svn commit: r281442 - head/sys/kern

Will Andrews will at FreeBSD.org
Sat Apr 11 18:51:42 UTC 2015


Author: will
Date: Sat Apr 11 18:51:41 2015
New Revision: 281442
URL: https://svnweb.freebsd.org/changeset/base/281442

Log:
  uiomove_object_page(): Avoid instantiating pages in sparse regions on reads.
  
  Check whether the page being requested is either resident or on swap.  If
  not, read from the zero_region instead of instantiating an unnecessary page.
  
  This avoids consuming memory for sparse files on tmpfs, when they are read
  by applications that do not use SEEK_HOLE/SEEK_DATA (which is most of them).
  
  Reviewed by:	kib
  MFC after:	1 week
  Sponsored by:	Spectra Logic

Modified:
  head/sys/kern/uipc_shm.c

Modified: head/sys/kern/uipc_shm.c
==============================================================================
--- head/sys/kern/uipc_shm.c	Sat Apr 11 18:45:22 2015	(r281441)
+++ head/sys/kern/uipc_shm.c	Sat Apr 11 18:51:41 2015	(r281442)
@@ -163,6 +163,17 @@ uiomove_object_page(vm_object_t obj, siz
 	VM_OBJECT_WLOCK(obj);
 
 	/*
+	 * Read I/O without either a corresponding resident page or swap
+	 * page: use zero_region.  This is intended to avoid instantiating
+	 * pages on read from a sparse region.
+	 */
+	if (uio->uio_rw == UIO_READ && vm_page_lookup(obj, idx) == NULL &&
+	    !vm_pager_has_page(obj, idx, NULL, NULL)) {
+		VM_OBJECT_WUNLOCK(obj);
+		return (uiomove(__DECONST(void *, zero_region), len, uio));
+	}
+
+	/*
 	 * Parallel reads of the page content from disk are prevented
 	 * by exclusive busy.
 	 *


More information about the svn-src-head mailing list