Subject: kern/1875: adding simple method of setting bufcache size
To: None <gnats-bugs@gnats.netbsd.org>
From: Luke Mewburn <lukem@supp.cpr.itg.telecom.com.au>
List: netbsd-bugs
Date: 12/31/1995 15:52:30
>Number:         1875
>Category:       kern
>Synopsis:       add a simple method of setting bufcache size
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   lm
>Arrival-Date:   Sun Dec 31 00:05:03 1995
>Last-Modified:
>Originator:     Luke Mewburn
>Organization:
Werj
>Release:        NetBSD.1-1
>Environment:
NetBSD karybdis 1.1 NetBSD 1.1
>Description:
	currently there isn't a method to easily set the % of memory
	to use as buffer cache - depending upon the architecture it
	ranges from 200k + 5% of physmem to a flat 10% of physmem.
	Systems such as ULTRIX have a "bufcache" config entry, which
	is useful on fileservers to set between 30 and 50% (if you
	have 128MB of RAM :)
	Anyway, until a unified buffer cache schem is incorporated,
	the following patch (just for i386, but it's so simple it can
	easily be put in for each port) adds another option - BUFCACHE
	- which can be defined as a % of physmem to use for bufcache.
	If BUFCACHE isn't defined, it defaults to 10% (which is more
	reasonable than 5% IMHO)
>How-To-Repeat:
	Try and work out how to set NPBG and BUFPAGES to tune the buffer
	cache size.
>Fix:
	Apply this simple patch. Use something like
		options BUFCACHE=xxx
	to set the buffer cache to xxx% of physmem.

	I do the caculation in the order:
		bufpages= physmem / (CLSIZE * 100) * BUFCACHE;
	to prevent int overflow on 32bit architectures with large
	chunks of ram (>32MB) when BUFCACHE is set to some number like
	70% (which is feasable - our ULTRIX NFS servers run at 80%
	buffer cache.)

	PS: as I said above, this is for i368, but it is trivial to
	apply to /sys/arch/*/*/machdep.c.


*** i386/machdep.c.orig	Mon Oct 16 12:43:28 1995
--- i386/machdep.c	Sun Dec 31 15:41:03 1995
***************
*** 313,329 ****
  #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)
! 		if (physmem < btoc(2 * 1024 * 1024))
! 			bufpages = physmem / (10 * CLSIZE);
! 		else
! 			bufpages = (btoc(2 * 1024 * 1024) + physmem) /
! 			    (20 * CLSIZE);
  	if (nbuf == 0) {
  		nbuf = bufpages;
  		if (nbuf < 16)
--- 313,332 ----
  #endif
  
  	/*
! 	 * If BUFCACHE is defined to a reasonable figure
! 	 * (1 <= BUFCACHE <= 95) then use that as a % of
! 	 * physical memory to use for buffer cache.
! 	 * Otherwise, use 10%
  	 */
+ #if !defined(BUFCACHE)
+ #define	BUFCACHE	10
+ #endif
+ #if (BUFCACHE < 1) || (BUFCACHE > 95)
+ #undef	BUFCACHE
+ #define	BUFCACHE	10
+ #endif
  	if (bufpages == 0)
! 		bufpages= physmem / (CLSIZE * 100) * BUFCACHE;
  	if (nbuf == 0) {
  		nbuf = bufpages;
  		if (nbuf < 16)
>Audit-Trail:
>Unformatted: