From 196f5066228d908cbac060396a1aba557efe1ef3 Mon Sep 17 00:00:00 2001 From: Pedro Martelletto Date: Sat, 26 May 2007 20:26:52 +0000 Subject: Dynamic buffer cache. Initial diff from mickey@, okay art@ beck@ toby@ deraadt@ dlg@. --- sys/arch/aviion/aviion/machdep.c | 88 +++++----------------------------------- 1 file changed, 10 insertions(+), 78 deletions(-) (limited to 'sys/arch/aviion') diff --git a/sys/arch/aviion/aviion/machdep.c b/sys/arch/aviion/aviion/machdep.c index fe4951338b7..eb4b2527e0a 100644 --- a/sys/arch/aviion/aviion/machdep.c +++ b/sys/arch/aviion/aviion/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.6 2007/05/12 20:03:22 miod Exp $ */ +/* $OpenBSD: machdep.c,v 1.7 2007/05/26 20:26:50 pedro Exp $ */ /* * Copyright (c) 1998, 1999, 2000, 2001 Steve Murphree, Jr. * Copyright (c) 1996 Nivas Madhur @@ -116,12 +116,6 @@ __cpu_simple_lock_t cpu_mutex = __SIMPLELOCK_UNLOCKED; /* * Declare these as initialized data so we can patch them. */ -#ifdef NBUF -int nbuf = NBUF; -#else -int nbuf = 0; -#endif - #ifndef BUFCACHEPERCENT #define BUFCACHEPERCENT 5 #endif @@ -269,49 +263,17 @@ cpu_startup() platform->startup(); /* - * Now allocate buffers proper. They are different than the above - * in that they usually occupy more virtual memory than physical. + * Determine how many buffers to allocate. + * We allocate bufcachepercent% of memory for buffer space. */ - size = MAXBSIZE * nbuf; - if (uvm_map(kernel_map, (vaddr_t *) &buffers, round_page(size), - NULL, UVM_UNKNOWN_OFFSET, 0, UVM_MAPFLAG(UVM_PROT_NONE, - UVM_PROT_NONE, UVM_INH_NONE, UVM_ADV_NORMAL, 0))) - panic("cpu_startup: cannot allocate VM for buffers"); - minaddr = (vaddr_t)buffers; - - if ((bufpages / nbuf) >= btoc(MAXBSIZE)) { - /* don't want to alloc more physical mem than needed */ - bufpages = btoc(MAXBSIZE) * nbuf; - } - base = bufpages / nbuf; - residual = bufpages % nbuf; - - for (i = 0; i < nbuf; i++) { - vsize_t curbufsize; - vaddr_t curbuf; - struct vm_page *pg; + if (bufpages == 0) + bufpages = physmem * bufcachepercent / 100; - /* - * Each buffer has MAXBSIZE bytes of VM space allocated. Of - * that MAXBSIZE space, we allocate and map (base+1) pages - * for the first "residual" buffers, and then we allocate - * "base" pages for the rest. - */ - curbuf = (vaddr_t)buffers + (i * MAXBSIZE); - curbufsize = PAGE_SIZE * ((i < residual) ? (base + 1) : base); - - while (curbufsize) { - pg = uvm_pagealloc(NULL, 0, NULL, 0); - if (pg == NULL) - panic("cpu_startup: not enough memory for " - "buffer cache"); - pmap_kenter_pa(curbuf, VM_PAGE_TO_PHYS(pg), - VM_PROT_READ | VM_PROT_WRITE); - curbuf += PAGE_SIZE; - curbufsize -= PAGE_SIZE; - } - } - pmap_update(pmap_kernel()); + /* Restrict to at most 25% filled kvm */ + if (bufpages > + (VM_MAX_KERNEL_ADDRESS-VM_MIN_KERNEL_ADDRESS) / PAGE_SIZE / 4) + bufpages = (VM_MAX_KERNEL_ADDRESS-VM_MIN_KERNEL_ADDRESS) / + PAGE_SIZE / 4; /* * Allocate a submap for exec arguments. This map effectively @@ -327,8 +289,6 @@ cpu_startup() VM_PHYS_SIZE, 0, FALSE, NULL); printf("avail mem = %ld (%d pages)\n", ptoa(uvmexp.free), uvmexp.free); - printf("using %d buffers containing %d bytes of memory\n", nbuf, - bufpages * PAGE_SIZE); /* * Set up buffers, so they can be used to read disk labels. @@ -377,34 +337,6 @@ allocsys(v) valloc(msqids, struct msqid_ds, msginfo.msgmni); #endif - /* - * Determine how many buffers to allocate. We use 10% of the - * first 2MB of memory, and 5% of the rest, with a minimum of 16 - * buffers. We allocate 1/2 as many swap buffer headers as file - * i/o buffers. - */ - if (bufpages == 0) { - bufpages = (btoc(2 * 1024 * 1024) + physmem) * - bufcachepercent / 100; - } - if (nbuf == 0) { - nbuf = bufpages; - if (nbuf < 16) - nbuf = 16; - } - - /* Restrict to at most 70% filled kvm */ - if (nbuf > - (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / MAXBSIZE * 7 / 10) - nbuf = (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) / - MAXBSIZE * 7 / 10; - - /* More buffer pages than fits into the buffers is senseless. */ - if (bufpages > nbuf * MAXBSIZE / PAGE_SIZE) - bufpages = nbuf * MAXBSIZE / PAGE_SIZE; - - valloc(buf, struct buf, nbuf); - return v; } -- cgit v1.2.3