FreeBSD/sys/kern/vfs_bio.c
/*
 *	bufkva_alloc:
 *
 *	Allocate the buffer KVA and set b_kvasize and b_kvabase.
 */
Allocate the buffer KVA and set b_kvasize and b_kvabase.
Allocate the buffer KVA and set b_kvasize and b_kvabase .
static int
bufkva_alloc(struct buf *bp, int maxsize, int gbflags)
{
	vm_offset_t addr;
	int error;
	KASSERT((gbflags & GB_UNMAPPED) == 0 || (gbflags & GB_KVAALLOC) != 0,
	    ("Invalid gbflags 0x%x in %s", gbflags, __func__));
	bufkva_free(bp);
	addr = 0;
	error = vmem_alloc(buffer_arena, maxsize, M_BESTFIT | M_NOWAIT, &addr);
	if (error != 0) {
		return (error);
	}
	bp->b_kvabase = (caddr_t)addr;
	bp->b_kvasize = maxsize;
	atomic_add_long(&bufkvaspace, bp->b_kvasize);
	if ((gbflags & GB_UNMAPPED) != 0) {
		bp->b_data = unmapped_buf;
		BUF_CHECK_UNMAPPED(bp);
	} else {
		bp->b_data = bp->b_kvabase;
		BUF_CHECK_MAPPED(bp);
	}
	return (0);
}
static int bufkva_alloc ( struct buf * bp , int maxsize , int gbflags ) { vm_offset_t addr ; int error ; KASSERT ( ( gbflags & GB_UNMAPPED ) == 0 || ( gbflags & GB_KVAALLOC ) != 0 , ( " " , gbflags , __func__ ) ) ; bufkva_free ( bp ) ; addr = 0 ; error = vmem_alloc ( buffer_arena , maxsize , M_BESTFIT | M_NOWAIT , & addr ) ; if ( error != 0 ) { return ( error ) ; } bp -> b_kvabase = ( caddr_t ) addr ; bp -> b_kvasize = maxsize ; atomic_add_long ( & bufkvaspace , bp -> b_kvasize ) ; if ( ( gbflags & GB_UNMAPPED ) != 0 ) { bp -> b_data = unmapped_buf ; BUF_CHECK_UNMAPPED ( bp ) ; } else { bp -> b_data = bp -> b_kvabase ; BUF_CHECK_MAPPED ( bp ) ; } return ( 0 ) ; }
bufkva_alloc:
      Allocate the buffer KVA and set b_kvasize and b_kvabase.
bufkva_alloc : Allocate the buffer KVA and set b_kvasize and b_kvabase .
/*
		 * Buffer map is too fragmented.  Request the caller
		 * to defragment the map.
		 */