FreeBSD/sys/kern/vfs_bio.c
/*
 * Extend the backing for a non-VMIO buffer.
 */
Extend the backing for a non-VMIO buffer.
Extend the backing for a non - VMIO buffer .
static void
vfs_nonvmio_extend(struct buf *bp, int newbsize)
{
	caddr_t origbuf;
	int origbufsize;
	if (bp->b_bufsize == 0 && newbsize <= PAGE_SIZE/2 &&
	    bufmallocspace < maxbufmallocspace) {
		bp->b_data = malloc(newbsize, M_BIOBUF, M_WAITOK);
		bp->b_flags |= B_MALLOC;
		bufmallocadjust(bp, newbsize);
		return;
	}
	origbuf = NULL;
	origbufsize = 0;
	if (bp->b_flags & B_MALLOC) {
		origbuf = bp->b_data;
		origbufsize = bp->b_bufsize;
		bp->b_data = bp->b_kvabase;
		bufmallocadjust(bp, 0);
		bp->b_flags &= ~B_MALLOC;
		newbsize = round_page(newbsize);
	}
	vm_hold_load_pages(bp, (vm_offset_t) bp->b_data + bp->b_bufsize,
	    (vm_offset_t) bp->b_data + newbsize);
	if (origbuf != NULL) {
		bcopy(origbuf, bp->b_data, origbufsize);
		free(origbuf, M_BIOBUF);
	}
	bufspace_adjust(bp, newbsize);
}
static void vfs_nonvmio_extend ( struct buf * bp , int newbsize ) { caddr_t origbuf ; int origbufsize ; if ( bp -> b_bufsize == 0 && newbsize <= PAGE_SIZE / 2 && bufmallocspace < maxbufmallocspace ) { bp -> b_data = malloc ( newbsize , M_BIOBUF , M_WAITOK ) ; bp -> b_flags |= B_MALLOC ; bufmallocadjust ( bp , newbsize ) ; return ; } origbuf = NULL ; origbufsize = 0 ; if ( bp -> b_flags & B_MALLOC ) { origbuf = bp -> b_data ; origbufsize = bp -> b_bufsize ; bp -> b_data = bp -> b_kvabase ; bufmallocadjust ( bp , 0 ) ; bp -> b_flags &= ~ B_MALLOC ; newbsize = round_page ( newbsize ) ; } vm_hold_load_pages ( bp , ( vm_offset_t ) bp -> b_data + bp -> b_bufsize , ( vm_offset_t ) bp -> b_data + newbsize ) ; if ( origbuf != NULL ) { bcopy ( origbuf , bp -> b_data , origbufsize ) ; free ( origbuf , M_BIOBUF ) ; } bufspace_adjust ( bp , newbsize ) ; }
Extend the backing for a non-VMIO buffer.
Extend the backing for a non - VMIO buffer .
/*
	 * We only use malloced memory on the first allocation.
	 * and revert to page-allocated memory when the buffer
	 * grows.
	 *
	 * There is a potential smp race here that could lead
	 * to bufmallocspace slightly passing the max.  It
	 * is probably extremely rare and not worth worrying
	 * over.
	 */ /*
	 * If the buffer is growing on its other-than-first
	 * allocation then we revert to the page-allocation
	 * scheme.
	 */