FreeBSD/sys/kern/vfs_bio.c
/*
 * buf_alloc:
 *
 *	Allocate an empty buffer header.
 */
Allocate an empty buffer header.
Allocate an empty buffer header .
static struct buf *
buf_alloc(void)
{
	struct buf *bp;
	bp = uma_zalloc(buf_zone, M_NOWAIT);
	if (bp == NULL) {
		bufspace_daemonwakeup();
		atomic_add_int(&numbufallocfails, 1);
		return (NULL);
	}
	if (atomic_fetchadd_int(&numfreebuffers, -1) == lofreebuffers)
		bufspace_daemonwakeup();
	if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT, NULL) != 0)
		panic("getnewbuf_empty: Locked buf %p on free queue.", bp);
	KASSERT(bp->b_vp == NULL,
	    ("bp: %p still has vnode %p.", bp, bp->b_vp));
	KASSERT((bp->b_flags & (B_DELWRI | B_NOREUSE)) == 0,
	    ("invalid buffer %p flags %#x", bp, bp->b_flags));
	KASSERT((bp->b_xflags & (BX_VNCLEAN|BX_VNDIRTY)) == 0,
	    ("bp: %p still on a buffer list. xflags %X", bp, bp->b_xflags));
	KASSERT(bp->b_npages == 0,
	    ("bp: %p still has %d vm pages\n", bp, bp->b_npages));
	KASSERT(bp->b_kvasize == 0, ("bp: %p still has kva\n", bp));
	KASSERT(bp->b_bufsize == 0, ("bp: %p still has bufspace\n", bp));
	bp->b_flags = 0;
	bp->b_ioflags = 0;
	bp->b_xflags = 0;
	bp->b_vflags = 0;
	bp->b_vp = NULL;
	bp->b_blkno = bp->b_lblkno = 0;
	bp->b_offset = NOOFFSET;
	bp->b_iodone = 0;
	bp->b_error = 0;
	bp->b_resid = 0;
	bp->b_bcount = 0;
	bp->b_npages = 0;
	bp->b_dirtyoff = bp->b_dirtyend = 0;
	bp->b_bufobj = NULL;
	bp->b_pin_count = 0;
	bp->b_data = bp->b_kvabase = unmapped_buf;
	bp->b_fsprivate1 = NULL;
	bp->b_fsprivate2 = NULL;
	bp->b_fsprivate3 = NULL;
	LIST_INIT(&bp->b_dep);
	return (bp);
}
static struct buf * buf_alloc ( void ) { struct buf * bp ; bp = uma_zalloc ( buf_zone , M_NOWAIT ) ; if ( bp == NULL ) { bufspace_daemonwakeup ( ) ; atomic_add_int ( & numbufallocfails , 1 ) ; return ( NULL ) ; } if ( atomic_fetchadd_int ( & numfreebuffers , -1 ) == lofreebuffers ) bufspace_daemonwakeup ( ) ; if ( BUF_LOCK ( bp , LK_EXCLUSIVE | LK_NOWAIT , NULL ) != 0 ) panic ( " " , bp ) ; KASSERT ( bp -> b_vp == NULL , ( " " , bp , bp -> b_vp ) ) ; KASSERT ( ( bp -> b_flags & ( B_DELWRI | B_NOREUSE ) ) == 0 , ( " " , bp , bp -> b_flags ) ) ; KASSERT ( ( bp -> b_xflags & ( BX_VNCLEAN | BX_VNDIRTY ) ) == 0 , ( " " , bp , bp -> b_xflags ) ) ; KASSERT ( bp -> b_npages == 0 , ( " \n " , bp , bp -> b_npages ) ) ; KASSERT ( bp -> b_kvasize == 0 , ( " \n " , bp ) ) ; KASSERT ( bp -> b_bufsize == 0 , ( " \n " , bp ) ) ; bp -> b_flags = 0 ; bp -> b_ioflags = 0 ; bp -> b_xflags = 0 ; bp -> b_vflags = 0 ; bp -> b_vp = NULL ; bp -> b_blkno = bp -> b_lblkno = 0 ; bp -> b_offset = NOOFFSET ; bp -> b_iodone = 0 ; bp -> b_error = 0 ; bp -> b_resid = 0 ; bp -> b_bcount = 0 ; bp -> b_npages = 0 ; bp -> b_dirtyoff = bp -> b_dirtyend = 0 ; bp -> b_bufobj = NULL ; bp -> b_pin_count = 0 ; bp -> b_data = bp -> b_kvabase = unmapped_buf ; bp -> b_fsprivate1 = NULL ; bp -> b_fsprivate2 = NULL ; bp -> b_fsprivate3 = NULL ; LIST_INIT ( & bp -> b_dep ) ; return ( bp ) ; }
buf_alloc:
      Allocate an empty buffer header.
buf_alloc : Allocate an empty buffer header .
/*
	 * Wake-up the bufspace daemon on transition.
	 */