Messages in this thread Patch in this message | | | Date | Mon, 22 Dec 1997 11:04:58 -0500 | From | Bill Hawes <> | Subject | patch for 2.1.75 buffer.c -- please test |
| |
I've put together a small patch for buffer.c that should help improve performance for some memory-intensive applications. It provides a new tuning parameter to help prevent over committing memory to buffers.
The new parameter is expressed as a percentage of total memory to be allowed for buffers without first checking the buffer list for reusable buffers. Once this limit has been reached, subsequent buffer allocations must check the lists before allocating additional buffers. Note that this DOES NOT limit the memory available for buffers -- it just slows down the growth after the limit is reached. Thus the patch will not introduce any low-memory failures or other problems, but may help avoid such problems by limiting excessive buffer memory.
I've set the default parameter at 40%, but this value should be reduced substantially for machines with a large amount of memory. Hopefully people with news server or web server applications can play with this and suggest optimal parameter values for various levels of memory.
Regards, Bill--- fs/buffer.c.old Mon Dec 22 10:45:44 1997 +++ fs/buffer.c Mon Dec 22 10:54:41 1997 @@ -43,6 +43,8 @@ #include <asm/io.h> #include <asm/bitops.h> +extern unsigned long num_physpages; + #define NR_SIZES 5 static char buffersize_index[17] = {-1, 0, 1, -1, 2, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1, 4}; @@ -98,7 +100,7 @@ each time we call refill */ int nref_dirt; /* Dirty buffer threshold for activating bdflush when trying to refill buffers. */ - int dummy1; /* unused */ + int mem_fract; /* maximum fraction of memory for buffers */ int age_buffer; /* Time for normal buffer to age before we flush it */ int age_super; /* Time for superblock to age before we @@ -107,11 +109,11 @@ int dummy3; /* unused */ } b_un; unsigned int data[N_PARAM]; -} bdf_prm = {{40, 500, 64, 256, 15, 30*HZ, 5*HZ, 1884, 2}}; +} bdf_prm = {{40, 500, 64, 256, 40, 30*HZ, 5*HZ, 1884, 2}}; /* These are the min and max parameter values that we will allow to be assigned */ int bdflush_min[N_PARAM] = { 0, 10, 5, 25, 0, 100, 100, 1, 1}; -int bdflush_max[N_PARAM] = {100,5000, 2000, 2000,100, 60000, 60000, 2047, 5}; +int bdflush_max[N_PARAM] = {100,5000, 2000, 2000, 90, 60000, 60000, 2047, 5}; void wakeup_bdflush(int); @@ -725,6 +727,7 @@ struct buffer_head * bh, * next; struct buffer_head * candidate[BUF_DIRTY]; int buffers[BUF_DIRTY]; + unsigned long max_pages = num_physpages * bdf_prm.b_un.mem_fract / 100; int i; int needed, obtained=0; @@ -733,11 +736,13 @@ /* We are going to try to locate this much memory. */ needed = bdf_prm.b_un.nrefill * size; - while ((nr_free_pages > min_free_pages*2) && - grow_buffers(GFP_BUFFER, size)) { - obtained += PAGE_SIZE; - if (obtained >= needed) - return; + if ((buffermem >> PAGE_SHIFT) < max_pages) { + while ((nr_free_pages > min_free_pages*2) && + grow_buffers(GFP_BUFFER, size)) { + obtained += PAGE_SIZE; + if (obtained >= needed) + return; + } } /* | |