Currently, when mkimg(1) is used to create an image that's large
relative to system memory, it pulls its input files (e.g. filesystem
images) into the active queue in image_copyout_file(). This triggers
some aggressive behaviour from the pagedaemon, since it results in a
state where the inactive queue is depleted and almost all of system
memory is in the active queue. In particular, this forces the pagedaemon
to swap out lots of anonymous memory in an attempt to address the
shortfall.
Use madvise(2) in image_file_unmap() to hint to the VM that pages
backing input files should be reclaimed before other pages. This
basically means that they'll be reclaimed in FIFO order from the
inactive queue when the system is under memory pressure, avoiding
a global impact on the system.