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
This commit is contained in:
parent
bd02d46fc2
commit
cc7f01a5da
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user