summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authormarkj <markj@FreeBSD.org>2016-06-01 02:30:06 +0000
committermarkj <markj@FreeBSD.org>2016-06-01 02:30:06 +0000
commitbe9a20239f1e1d061ba3cb8c213dba515038484f (patch)
tree8243804fb1276e4c472709c21dbaf782a12a0ef4 /usr.bin
parente4b5ee08b537ee3e1a899cbc2b82af88a52d9925 (diff)
downloadFreeBSD-src-be9a20239f1e1d061ba3cb8c213dba515038484f.zip
FreeBSD-src-be9a20239f1e1d061ba3cb8c213dba515038484f.tar.gz
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
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mkimg/image.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/usr.bin/mkimg/image.c b/usr.bin/mkimg/image.c
index a3bec63..2527f28 100644
--- a/usr.bin/mkimg/image.c
+++ b/usr.bin/mkimg/image.c
@@ -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);
}
OpenPOWER on IntegriCloud