svn commit: r248510 - in head/sys: kern sys

Konstantin Belousov kib at FreeBSD.org
Tue Mar 19 14:27:15 UTC 2013


Author: kib
Date: Tue Mar 19 14:27:14 2013
New Revision: 248510
URL: http://svnweb.freebsd.org/changeset/base/248510

Log:
  Add a helper function vfs_bio_bzero_buf() to zero the portion of the
  buffer, transparently handling mapped or unmapped buffers.  Its intent
  is to replace the use of bzero(bp->b_data) in cases where the buffer
  might be unmapped, to avoid unneeded upgrades.
  
  Sponsored by:	The FreeBSD Foundation
  Tested by:	pho

Modified:
  head/sys/kern/vfs_bio.c
  head/sys/sys/buf.h

Modified: head/sys/kern/vfs_bio.c
==============================================================================
--- head/sys/kern/vfs_bio.c	Tue Mar 19 14:15:41 2013	(r248509)
+++ head/sys/kern/vfs_bio.c	Tue Mar 19 14:27:14 2013	(r248510)
@@ -4176,6 +4176,32 @@ unlock:
 	bp->b_resid = 0;
 }
 
+void
+vfs_bio_bzero_buf(struct buf *bp, int base, int size)
+{
+	vm_page_t m;
+	int i, n;
+
+	if ((bp->b_flags & B_UNMAPPED) == 0) {
+		BUF_CHECK_MAPPED(bp);
+		bzero(bp->b_data + base, size);
+	} else {
+		BUF_CHECK_UNMAPPED(bp);
+		n = PAGE_SIZE - (base & PAGE_MASK);
+		VM_OBJECT_WLOCK(bp->b_bufobj->bo_object);
+		for (i = base / PAGE_SIZE; size > 0 && i < bp->b_npages; ++i) {
+			m = bp->b_pages[i];
+			if (n > size)
+				n = size;
+			pmap_zero_page_area(m, base & PAGE_MASK, n);
+			base += n;
+			size -= n;
+			n = PAGE_SIZE;
+		}
+		VM_OBJECT_WUNLOCK(bp->b_bufobj->bo_object);
+	}
+}
+
 /*
  * vm_hold_load_pages and vm_hold_free_pages get pages into
  * a buffers address space.  The pages are anonymous and are

Modified: head/sys/sys/buf.h
==============================================================================
--- head/sys/sys/buf.h	Tue Mar 19 14:15:41 2013	(r248509)
+++ head/sys/sys/buf.h	Tue Mar 19 14:27:14 2013	(r248510)
@@ -519,6 +519,7 @@ int	cluster_read(struct vnode *, u_quad_
 	    struct ucred *, long, int, int, struct buf **);
 int	cluster_wbuild(struct vnode *, long, daddr_t, int, int);
 void	cluster_write(struct vnode *, struct buf *, u_quad_t, int, int);
+void	vfs_bio_bzero_buf(struct buf *bp, int base, int size);
 void	vfs_bio_set_valid(struct buf *, int base, int size);
 void	vfs_bio_clrbuf(struct buf *);
 void	vfs_busy_pages(struct buf *, int clear_modify);


More information about the svn-src-all mailing list