Subject: kern/1903: adding better method than [kern-1875] 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: 01/06/1996 18:47:52
>Number:         1903
>Category:       kern
>Synopsis:       adding better method than [kern-1875] 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:   Sat Jan  6 03:05:01 1996
>Last-Modified:
>Originator:     Luke Mewburn
>Organization:
>Release:        1.1
>Environment:
System: NetBSD shelob 1.1A NetBSD 1.1A (SHELOB) #3: Wed Jan 3 14:46:55 EST 1996 root@shelob:/z/src/sys/arch/i386/compile/SHELOB i386

>Description:
	[ note that this replaces kern-1875 which I previously submitted.
	  It puts the value of the BUFCACHE define into a global
	  variable BUFCACHE before using it, as suggested by
	  Chris Demetriou. This allows editing the value in with
	  a debugger. ]

	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

>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 i386, but it is trivial to
	apply to /sys/arch/*/*/machdep.c.

*** /usr/osrc/sys/arch/i386/i386/machdep.c	Mon Oct 16 12:43:28 1995
--- i386/machdep.c	Wed Jan  3 18:46:22 1996
***************
*** 115,120 ****
--- 115,128 ----
  #else
  int	bufpages = 0;
  #endif
+ #if !defined(BUFCACHE)
+ #define	BUFCACHE	10
+ #endif
+ #if (BUFCACHE < 1) || (BUFCACHE > 95)
+ #undef	BUFCACHE
+ #define	BUFCACHE	10
+ #endif
+ int	bufcache = BUFCACHE;
  
  int	physmem;
  int	dumpmem_low;
***************
*** 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)
--- 321,332 ----
  #endif
  
  	/*
! 	 * Set size of buffer cache to physmem/buffercache * 100
! 	 * (i.e., bufcache % of physmem). We allocate 1/2 as many
! 	 * swap buffer headers as file I/O buffers.
  	 */
  	if (bufpages == 0)
! 		bufpages= physmem / (CLSIZE * 100) * bufcache;
  	if (nbuf == 0) {
  		nbuf = bufpages;
  		if (nbuf < 16)
>Audit-Trail:
>Unformatted: