FreeBSD/sys/kern/vfs_bio.c
/*
 * Delayed write. (Buffer is marked dirty).  Do not bother writing
 * anything if the buffer is marked invalid.
 *
 * Note that since the buffer must be completely valid, we can safely
 * set B_CACHE.  In fact, we have to set B_CACHE here rather then in
 * biodone() in order to prevent getblk from writing the buffer
 * out synchronously.
 */
Delayed write. (Buffer is marked dirty).  Do not bother writing
anything if the buffer is marked invalid.

Note that since the buffer must be completely valid, we can safely
set B_CACHE.  In fact, we have to set B_CACHE here rather then in
biodone() in order to prevent getblk from writing the buffer
out synchronously.
Delayed write . ( Buffer is marked dirty ) . Do not bother writing anything if the buffer is marked invalid . Note that since the buffer must be completely valid we can safely set B_CACHE . In fact we have to set B_CACHE here rather then in biodone () in order to prevent getblk from writing the buffer out synchronously .
void
bdwrite(struct buf *bp)
{
	struct thread *td = curthread;
	struct vnode *vp;
	struct bufobj *bo;
	CTR3(KTR_BUF, "bdwrite(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags);
	KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp));
	KASSERT((bp->b_flags & B_BARRIER) == 0,
	    ("Barrier request in delayed write %p", bp));
	BUF_ASSERT_HELD(bp);
	if (bp->b_flags & B_INVAL) {
		brelse(bp);
		return;
	}
	vp = bp->b_vp;
	bo = bp->b_bufobj;
	if ((td->td_pflags & (TDP_COWINPROGRESS|TDP_INBDFLUSH)) == 0) {
		td->td_pflags |= TDP_INBDFLUSH;
		BO_BDFLUSH(bo, bp);
		td->td_pflags &= ~TDP_INBDFLUSH;
	} else
		recursiveflushes++;
	bdirty(bp);
	bp->b_flags |= B_CACHE;
	if (vp->v_type != VCHR && bp->b_lblkno == bp->b_blkno) {
		VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno, NULL, NULL);
	}
	vfs_clean_pages_dirty_buf(bp);
	bqrelse(bp);
}
void bdwrite ( struct buf * bp ) { struct thread * td = curthread ; struct vnode * vp ; struct bufobj * bo ; CTR3 ( KTR_BUF , " " , bp , bp -> b_vp , bp -> b_flags ) ; KASSERT ( bp -> b_bufobj != NULL , ( " " , bp ) ) ; KASSERT ( ( bp -> b_flags & B_BARRIER ) == 0 , ( " " , bp ) ) ; BUF_ASSERT_HELD ( bp ) ; if ( bp -> b_flags & B_INVAL ) { brelse ( bp ) ; return ; } vp = bp -> b_vp ; bo = bp -> b_bufobj ; if ( ( td -> td_pflags & ( TDP_COWINPROGRESS | TDP_INBDFLUSH ) ) == 0 ) { td -> td_pflags |= TDP_INBDFLUSH ; BO_BDFLUSH ( bo , bp ) ; td -> td_pflags &= ~ TDP_INBDFLUSH ; } else recursiveflushes ++ ; bdirty ( bp ) ; bp -> b_flags |= B_CACHE ; if ( vp -> v_type != VCHR && bp -> b_lblkno == bp -> b_blkno ) { VOP_BMAP ( vp , bp -> b_lblkno , NULL , & bp -> b_blkno , NULL , NULL ) ; } vfs_clean_pages_dirty_buf ( bp ) ; bqrelse ( bp ) ; }
Delayed write.
Delayed write .
/*
	 * If we have too many dirty buffers, don't create any more.
	 * If we are wildly over our limit, then force a complete
	 * cleanup. Otherwise, just keep the situation from getting
	 * out of control. Note that we have to avoid a recursive
	 * disaster and not try to clean up after our own cleanup!
	 */ /*
	 * Set B_CACHE, indicating that the buffer is fully valid.  This is
	 * true even of NFS now.
	 */ /*
	 * This bmap keeps the system from needing to do the bmap later,
	 * perhaps when the system is attempting to do a sync.  Since it
	 * is likely that the indirect block -- or whatever other datastructure
	 * that the filesystem needs is still in memory now, it is a good
	 * thing to do this.  Note also, that if the pageout daemon is
	 * requesting a sync -- there might not be enough memory to do
	 * the bmap then...  So, this is important to do.
	 */ /*
	 * Set the *dirty* buffer range based upon the VM system dirty
	 * pages.
	 *
	 * Mark the buffer pages as clean.  We need to do this here to
	 * satisfy the vnode_pager and the pageout daemon, so that it
	 * thinks that the pages have been "cleaned".  Note that since
	 * the pages are in a delayed write buffer -- the VFS layer
	 * "will" see that the pages get written out on the next sync,
	 * or perhaps the cluster will be completed.
	 */ /*
	 * note: we cannot initiate I/O from a bdwrite even if we wanted to,
	 * due to the softdep code.
	 */