FreeBSD/sys/kern/vfs_bio.c
/*
 * This code constitutes the buffer memory from either anonymous system
 * memory (in the case of non-VMIO operations) or from an associated
 * VM object (in the case of VMIO operations).  This code is able to
 * resize a buffer up or down.
 *
 * Note that this code is tricky, and has many complications to resolve
 * deadlock or inconsistent data situations.  Tread lightly!!! 
 * There are B_CACHE and B_DELWRI interactions that must be dealt with by 
 * the caller.  Calling this code willy nilly can result in the loss of data.
 *
 * allocbuf() only adjusts B_CACHE for VMIO buffers.  getblk() deals with
 * B_CACHE for the non-VMIO case.
 */
This code constitutes the buffer memory from either anonymous system
memory (in the case of non-VMIO operations) or from an associated
VM object (in the case of VMIO operations).  This code is able to
resize a buffer up or down.

Note that this code is tricky, and has many complications to resolve
deadlock or inconsistent data situations.  Tread lightly
There are B_CACHE and B_DELWRI interactions that must be dealt with by
the caller.  Calling this code willy nilly can result in the loss of data.

allocbuf() only adjusts B_CACHE for VMIO buffers.  getblk() deals with
B_CACHE for the non-VMIO case.
This code constitutes the buffer memory from either anonymous system memory ( in the case of non - VMIO operations ) or from an associated VM object ( in the case of VMIO operations ) . This code is able to resize a buffer up or down . Note that this code is tricky and has many complications to resolve deadlock or inconsistent data situations . Tread lightly There are B_CACHE and B_DELWRI interactions that must be dealt with by the caller . Calling this code willy nilly can result in the loss of data . allocbuf () only adjusts B_CACHE for VMIO buffers . getblk () deals with B_CACHE for the non - VMIO case .
int
allocbuf(struct buf *bp, int size)
{
	int newbsize;
	BUF_ASSERT_HELD(bp);
	if (bp->b_bcount == size)
		return (1);
	if (bp->b_kvasize != 0 && bp->b_kvasize < size)
		panic("allocbuf: buffer too small");
	newbsize = roundup2(size, DEV_BSIZE);
	if ((bp->b_flags & B_VMIO) == 0) {
		if ((bp->b_flags & B_MALLOC) == 0)
			newbsize = round_page(newbsize);
		if (newbsize < bp->b_bufsize)
			vfs_nonvmio_truncate(bp, newbsize);
		else if (newbsize > bp->b_bufsize)
			vfs_nonvmio_extend(bp, newbsize);
	} else {
		int desiredpages;
		desiredpages = (size == 0) ? 0 :
		    num_pages((bp->b_offset & PAGE_MASK) + newbsize);
		if (bp->b_flags & B_MALLOC)
			panic("allocbuf: VMIO buffer can't be malloced");
		if (size == 0 || bp->b_bufsize == 0)
			bp->b_flags |= B_CACHE;
		if (newbsize < bp->b_bufsize)
			vfs_vmio_truncate(bp, desiredpages);
		else if (size > bp->b_bcount)
			vfs_vmio_extend(bp, desiredpages, size);
		bufspace_adjust(bp, newbsize);
	}
	bp->b_bcount = size;		
	return (1);
}
int allocbuf ( struct buf * bp , int size ) { int newbsize ; BUF_ASSERT_HELD ( bp ) ; if ( bp -> b_bcount == size ) return ( 1 ) ; if ( bp -> b_kvasize != 0 && bp -> b_kvasize < size ) panic ( " " ) ; newbsize = roundup2 ( size , DEV_BSIZE ) ; if ( ( bp -> b_flags & B_VMIO ) == 0 ) { if ( ( bp -> b_flags & B_MALLOC ) == 0 ) newbsize = round_page ( newbsize ) ; if ( newbsize < bp -> b_bufsize ) vfs_nonvmio_truncate ( bp , newbsize ) ; else if ( newbsize > bp -> b_bufsize ) vfs_nonvmio_extend ( bp , newbsize ) ; } else { int desiredpages ; desiredpages = ( size == 0 ) ? 0 : num_pages ( ( bp -> b_offset & PAGE_MASK ) + newbsize ) ; if ( bp -> b_flags & B_MALLOC ) panic ( " " ) ; if ( size == 0 || bp -> b_bufsize == 0 ) bp -> b_flags |= B_CACHE ; if ( newbsize < bp -> b_bufsize ) vfs_vmio_truncate ( bp , desiredpages ) ; else if ( size > bp -> b_bcount ) vfs_vmio_extend ( bp , desiredpages , size ) ; bufspace_adjust ( bp , newbsize ) ; } bp -> b_bcount = size ; return ( 1 ) ; }
This code constitutes the buffer memory from either anonymous system
 memory (in the case of non-VMIO operations) or from an associated
 VM object (in the case of VMIO operations).
This code constitutes the buffer memory from either anonymous system memory ( in the case of non - VMIO operations ) or from an associated VM object ( in the case of VMIO operations ) .
/*
		 * Just get anonymous memory from the kernel.  Don't
		 * mess with B_CACHE.
		 */ /*
		 * Set B_CACHE initially if buffer is 0 length or will become
		 * 0-length.
		 */ /* XXX This looks as if it should be newbsize > b_bufsize */ /* requested buffer size. */