Subject: Re: moving allocsys() into MI part of kernel
To: None <tech-kern@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-kern
Date: 05/08/1999 20:54:50
In article <199905081700.DAA07665@wombat.cs.rmit.edu.au> lukem@netbsd.org writes:
>Hi all...
>
>Whilst looking at which ports supported the `BUFCACHE' option (with
>intent to convert the remaining ports), I noticed that most ports
>had a MD allocsys() function, which (amongst other things) calculates
>and then allocates the memory to be used by the buffer cache.
>
[...]

Very nice, a few comments:

1. Don't you need to retain the original copyright since most of the
   code was lifted?
2a. You added a bug in the sparc case: s/bufpages/nbuf
2b. You can remove that ifdef by appropriately defining VM_MAX_KERNEL_BUF
    in the sparc port something like:
	#define VM_MAX_KERNEL_BUF (CPU_ISSUN4C ? n1 : n2)
3. The sparc64 and the alpha crap you can do via a second define in
   machine/vmparam.h, or move them back to md code.
4. Format_memory should get passed a buffer and a buffer size instead
   of allocating a static buffer.
	
christos

>+ 	/*
>+ 	 * XXX stopgap measure to prevent wasting too much KVM on
>+ 	 * the sparsely filled buffer cache.
>+ 	 */
>+ 	if (nbuf * MAXBSIZE > VM_MAX_KERNEL_BUF)
>+ 		nbuf = VM_MAX_KERNEL_BUF / MAXBSIZE;
>+ #if defined (__sparc__)		/* XXX */
>+ 	if (CPU_ISSUN4C && bufpages > (128 * (65536/MAXBSIZE)))
>+ 		bufpages = (128 * (65536/MAXBSIZE));
>+ #endif
>+ 
>+ 	/*
>+ 	 * We allocate 1/2 as many swap buffer headers as file I/O buffers.
>+ 	 */
>+ 	if (nswbuf == 0) {
>+ 		nswbuf = (nbuf / 2) &~ 1;	/* force even */
>+ 		if (nswbuf > 256)
>+ 			nswbuf = 256;		/* sanity */
>+ 	}
>+ 	valloc(buf, struct buf, nbuf);
>+ 
>+ #if defined(__alpha__)			/* XXX */
>+ 	/*
>+ 	 * There appears to be a correlation between the number
>+ 	 * of processor slots defined in the HWRPB and the whami
>+ 	 * value that can be returned.
>+ 	 */
>+ 	valloc(mchkinfo_all_cpus, struct mchkinfo, hwrpb->rpb_pcs_cnt);
>+ #endif
>+ 
>+ #if defined(__sparc64__)		/* XXX */
>+ 	/*
>+ 	 * Allocate DVMA slots for 1/4 of the number of I/O buffers
>+ 	 * and one for each process too (PHYSIO).
>+ 	 */
>+ 	valloc(dvmamap, struct map, ndvmamap = maxproc + ((nbuf / 4) &~ 1));
>+ #endif
>+ 
>+ 	return (v);
>+ }
>+ 
>+ const char *
>+ format_memory(count)
>+ 	int64_t	count;
>+ {
>+ 		/*
>+ 		 * large enough buffer for:
>+ 		 *	"18014398509481984 KB (18446744073709551616 bytes)"
>+ 		 * i.e.,
>+ 		 *	2^54 KB (2^64 bytes)
>+ 		 */
>+ 	static char pbuf[80];	
>+ 
>+ 	snprintf(pbuf, sizeof(pbuf) - 1, "%qd KB (%qd bytes)",
>+ 	    (long long)(count / 1024), (long long) count);
>+ 	return (pbuf);
>+ }
>