Normally suspend2 writes all non-free pages (including clean cache pages and cached swap pages). This is a bit annoying for me, since 90% of the time I use less than 40% of my laptop's memory, but I have to wait for the other 60% of the RAM to be read and written at suspend and resume time.
ImageSizeLimit is an upper bound on the image size. If the image would be larger than this, then there is a pre-suspend forcing of pages--dirty or not--to disk. If the value is not dynamically chosen, it is inefficient--too high, and unnecessary pages are written in the suspend image; too low, and suspend and resume time is significantly increased since a bunch of stuff has to be swapped out before suspend and back in after resume, and page for page the swapper is much slower than Suspend2's image writer. Dynamically choosing the value is apparently non-trivial...at least I tried to do it for a while, then gave up.
My application forces all the clean pages (600MB as I write this) to go away, without losing active program text pages or forcing dirty pages to swap. It stops as soon as there are more than 100 pages written to swap since the program started running, so it does not significantly extend the suspend time (a few hundred pages are swapped before the application notices and exits, which does take a second or so).
This approach doesn't need prior configuration--it automatically discovers just how much RAM can be cheaply freed by allocating as much as the system can spare without swapping, then it exits and leaves thousands of free pages.
Without all the extra pages, the suspend image is much smaller, so suspend and resume are faster. Since only a few dirty or active pages were actually swapped, it doesn't noticeably slow down the machine after resume (there is more overhead when xscreensaver wakes up after noticing the wall clock time jumping well past the inactivity threshold, than there is from post-resume swapping ;-).
Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds