FreeBSD/sys/kern/vfs_bio.c
/*
 * Allocate the KVA mapping for an existing buffer.
 * If an unmapped buffer is provided but a mapped buffer is requested, take
 * also care to properly setup mappings between pages and KVA.
 */
Allocate the KVA mapping for an existing buffer.
If an unmapped buffer is provided but a mapped buffer is requested, take
also care to properly setup mappings between pages and KVA.
Allocate the KVA mapping for an existing buffer . If an unmapped buffer is provided but a mapped buffer is requested take also care to properly setup mappings between pages and KVA .
static void
bp_unmapped_get_kva(struct buf *bp, daddr_t blkno, int size, int gbflags)
{
	int bsize, maxsize, need_mapping, need_kva;
	off_t offset;
	need_mapping = bp->b_data == unmapped_buf &&
	    (gbflags & GB_UNMAPPED) == 0;
	need_kva = bp->b_kvabase == unmapped_buf &&
	    bp->b_data == unmapped_buf &&
	    (gbflags & GB_KVAALLOC) != 0;
	if (!need_mapping && !need_kva)
		return;
	BUF_CHECK_UNMAPPED(bp);
	if (need_mapping && bp->b_kvabase != unmapped_buf) {
		goto has_addr;
	}
	bsize = vn_isdisk(bp->b_vp, NULL) ? DEV_BSIZE : bp->b_bufobj->bo_bsize;
	KASSERT(bsize != 0, ("bsize == 0, check bo->bo_bsize"));
	offset = blkno * bsize;
	maxsize = size + (offset & PAGE_MASK);
	maxsize = imax(maxsize, bsize);
	while (bufkva_alloc(bp, maxsize, gbflags) != 0) {
		if ((gbflags & GB_NOWAIT_BD) != 0) {
			panic("GB_NOWAIT_BD and GB_UNMAPPED %p", bp);
		}
		atomic_add_int(&mappingrestarts, 1);
		bufspace_wait(bp->b_vp, gbflags, 0, 0);
	}
has_addr:
	if (need_mapping) {
		bp->b_data = bp->b_kvabase;
		BUF_CHECK_MAPPED(bp);
		bpmap_qenter(bp);
	}
}
static void bp_unmapped_get_kva ( struct buf * bp , daddr_t blkno , int size , int gbflags ) { int bsize , maxsize , need_mapping , need_kva ; off_t offset ; need_mapping = bp -> b_data == unmapped_buf && ( gbflags & GB_UNMAPPED ) == 0 ; need_kva = bp -> b_kvabase == unmapped_buf && bp -> b_data == unmapped_buf && ( gbflags & GB_KVAALLOC ) != 0 ; if ( ! need_mapping && ! need_kva ) return ; BUF_CHECK_UNMAPPED ( bp ) ; if ( need_mapping && bp -> b_kvabase != unmapped_buf ) { goto has_addr ; } bsize = vn_isdisk ( bp -> b_vp , NULL ) ? DEV_BSIZE : bp -> b_bufobj -> bo_bsize ; KASSERT ( bsize != 0 , ( " " ) ) ; offset = blkno * bsize ; maxsize = size + ( offset & PAGE_MASK ) ; maxsize = imax ( maxsize , bsize ) ; while ( bufkva_alloc ( bp , maxsize , gbflags ) != 0 ) { if ( ( gbflags & GB_NOWAIT_BD ) != 0 ) { panic ( " " , bp ) ; } atomic_add_int ( & mappingrestarts , 1 ) ; bufspace_wait ( bp -> b_vp , gbflags , 0 , 0 ) ; } has_addr : if ( need_mapping ) { bp -> b_data = bp -> b_kvabase ; BUF_CHECK_MAPPED ( bp ) ; bpmap_qenter ( bp ) ; } }
Allocate the KVA mapping for an existing buffer.
Allocate the KVA mapping for an existing buffer .
/*
		 * Buffer is not mapped, but the KVA was already
		 * reserved at the time of the instantiation.  Use the
		 * allocated space.
		 */ /*
	 * Calculate the amount of the address space we would reserve
	 * if the buffer was mapped.
	 */ /*
			 * XXXKIB: defragmentation cannot
			 * succeed, not sure what else to do.
			 */ /* b_offset is handled by bpmap_qenter. */