A problem with kernel buffers (struct buf).

Chris Torek chris at umcp-cs.UUCP
Thu Aug 29 02:14:09 AEST 1985


>In the work on the 4.2BSD kernel that I have been doing recently, I
>have come across a problem that I do not understand. ...  I allocate
>a buffer with geteblk with a size of about 10k,

Say no more!  That is the problem.  You cannot allocate a buffer
larger than MAXBSIZE without incurring "mysterious problems", since
each buffer has a virtual memory space of MAXBSIZE bytes (note that
for this reason MAXBSIZE must be a multiple of CLBYTES).

Had you installed my mass driver---or had Berkeley put a firewall
in allocbuf in the first place---you would have found the problem
much earlier.  Don't be embarrassed, though; I did the same thing
the first time in the mass driver, thus the following fix.

For those of you who don't want to install the whole thing, here's
just the changes to sys/vax/ufs_machdep.c.  Your line numbers may
vary:

*** /tmp/,RCSt1004349	Wed Aug 28 12:10:44 1985
--- /tmp/,RCSt2004349	Wed Aug 28 12:10:45 1985
***************
*** 29,32
  
  	sizealloc = roundup(size, CLBYTES);
  	/*
  	 * Buffer size does not change

--- 28,34 -----
  
  	sizealloc = roundup(size, CLBYTES);
+ 	if (sizealloc > MAXBSIZE)
+ 		panic("allocbuf");
+ 
  	/*
  	 * Buffer size does not change
***************
*** 68,72
  		    &tp->b_un.b_addr[tp->b_bufsize], take);
  		tp->b_bufsize += take;
! 		bp->b_bufsize = bp->b_bufsize - take;
  		if (bp->b_bcount > bp->b_bufsize)
  			bp->b_bcount = bp->b_bufsize;

--- 70,74 -----
  		    &tp->b_un.b_addr[tp->b_bufsize], take);
  		tp->b_bufsize += take;
! 		bp->b_bufsize -= take;
  		if (bp->b_bcount > bp->b_bufsize)
  			bp->b_bcount = bp->b_bufsize;
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at maryland



More information about the Comp.unix.wizards mailing list