svn commit: r301090 - head/usr.bin/mkimg

Mark Johnston markj at FreeBSD.org
Wed Jun 1 02:30:08 UTC 2016


Author: markj
Date: Wed Jun  1 02:30:06 2016
New Revision: 301090
URL: https://svnweb.freebsd.org/changeset/base/301090

Log:
  mkimg: Indicate that input file pages are unlikely to be reused.
  
  mkimg(1) uses a swap file to back input file chunks. When the output file
  is being written out, blocks of the swap file are mapped and their contents
  copied. This causes the backing VM pages to enter the active queue, and when
  the output file is large relative to system memory (as is generally the
  case), can result in a shortfall of inactive memory. This causes the
  pagedaemon to aggressively scan the active queue and swap out process
  memory in an attempt to meet the shortfall. Because mkimg's input files
  are typically the intermediate result of some build process, there's no
  need to push them all through the active queue. Use madvise(2) to indicate
  that the backing pages may be reclaimed in preference to active pages. In
  the case of the swap file, these pages will be freed as soon as mkimg
  exits anyway.
  
  When using mkimg on a desktop-class system with large amounts of dirty
  process memory, this change substantially improves mkimg runtime and
  reduces swap usage.
  
  Reviewed by:	marcel
  MFC after:	2 weeks
  Differential Revision:	https://reviews.freebsd.org/D6654

Modified:
  head/usr.bin/mkimg/image.c

Modified: head/usr.bin/mkimg/image.c
==============================================================================
--- head/usr.bin/mkimg/image.c	Wed Jun  1 01:43:46 2016	(r301089)
+++ head/usr.bin/mkimg/image.c	Wed Jun  1 02:30:06 2016	(r301090)
@@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <assert.h>
+#include <err.h>
 #include <errno.h>
 #include <limits.h>
 #include <paths.h>
@@ -315,6 +316,8 @@ image_file_unmap(void *buffer, size_t sz
 
 	unit = (secsz > image_swap_pgsz) ? secsz : image_swap_pgsz;
 	sz = (sz + unit - 1) & ~(unit - 1);
+	if (madvise(buffer, sz, MADV_DONTNEED) != 0)
+		warn("madvise");
 	munmap(buffer, sz);
 	return (0);
 }


More information about the svn-src-head mailing list