Restoring in-memory/swapped page state on resume from hibernation
Restoring in-memory/swapped page state on resume from hibernation
I'm a big fan of Linux's hibernation support, which works extremely well on all the (admittedly slightly older) hardware I've tried it on. I highly prefer it to full shutdown and power up.
There's one thing about hibernation that's bugged me for a while, though: a hibernated system is always sluggish and unresponsive immediately after having been resumed. It's not snappy immediately after power on. This is exacerbated by old hardware, but happens on newer systems to a slightly notable extent too.
This seems to be because the kernel only swaps the pages critically necessary for [kernel-level] operation back into working memory, restores the kernel's base working state, and lets userspace just churn for a while as various processes swap the pages they need back into RAM under their own steam.
This does not work very well in practice, as the system initially functions as though some large process had forced everything to fully swap to disk. Whatever was on the screen will swap back in pretty quickly, but switch to another process and you'll be waiting a couple seconds as it swaps back into memory too. On older hardware - my case in point is a Core 2 ThinkPad T60 - "a couple seconds" can even wind up being a couple minutes.
I recently realized that this problem has a surprisingly simple solution, after thinking about it for a bit: take note of the tags that label what pages are on disk and in RAM, then restore this exact state on resume. Sure, the resume process might take ~10 seconds more, but I don't care - I'd have a snappy system.
I was wondering if there are any obscure kernel compile options that enable such functionality, or some configuration I can set up that would approximate this behavior?
NOTE: I do not consider swapoff -a; swapon -a a viable solution; the moment the suspended userspace is reanimated, all loaded processes are attempting to execute code and fighting to swap themselves back into RAM, causing massive disk I/O. Attempting to destroy the swap area would only add to the hurricane, and would actually take longer to complete than if the kernel resumed all of RAM before reanimating userspace.
K2-Think
The sluggishness experienced immediately after resuming from hibernation in Linux is primarily due to the kernel's default behavior of excluding clean file-backed pages (e.g., cached program code and shared libraries) from the hibernation image. These pages are evicted from RAM during hibernation preparation to minimize the image size, leading to post-resume disk I/O as they are reloaded into memo...
GPT-5
Short answer: what you’re seeing after resume isn’t “swapping everything back in,” it’s mostly the page cache (clean file-backed pages: program text, shared libraries, file data, dentries/inodes) having been dropped before hibernation to make the image smaller. On resume those pages have to be faulted back from the filesystem, which looks like heavy I/O and feels sluggish. Anonymous (non-file-back...
Claude 3.7 Sonnet
Restoring Memory State After Hibernation in Linux
The sluggishness you're experiencing after resuming from hibernation is indeed due to how Linux handles memory during the hibernate/resume process. Let me explain what's happening and what options you have.
Why Resume Is Sluggish
When Linux hibernates, it saves the entire system state to disk. However, during resume:
- The kernel only loa...
Claude Opus 4
This is an excellent question about optimizing Linux hibernation resume performance. You've correctly identified the core issue: the kernel only restores the minimum necessary pages during resume, leaving userspace processes to fault in their pages on-demand, which causes the sluggishness you're experiencing.
Current Kernel Behavior
The Linux kernel's hibernation implementation (suspend-to-di...
DeepSeek R1
o4 mini
The short answer is: there is no magic “turn-this-on in your kernel .config” switch in mainline Linux today that will re-page in user-land memory eagerly on resume. The upstream hibernation (swsusp) code deliberately uses a “paged resume” model—only the absolutely essential pages for the kernel itself are brought back at wake-up, and the rest of user space faults in on demand. That is exactly wh...
Gemini 2.5 Pro
Excellent question. You've perfectly articulated a subtle but significant annoyance with the hibernation resume process. Your diagnosis of the cause is also spot-on: the kernel restores the memory image and thaws processes, but it's up to individual processes to fault their required pages back into RAM from the swap device, leading to a "page fault storm" and massive disk I/O contention.
Your pro...
o3 Pro
Short answer
The current in–kernel hibernation code (swsusp / suspend-to-disk) does not contain, and has never contained, a facility that “remembers which pages were in RAM and puts them back there before userspace is thawed”. If a page had been pushed out to swap before you hibernate, it will still be in swap after you resume and it will be faulted back on demand, one page-fault at a time....
o3
Short version
What you are asking for does not exists in the main-line Linux kernel, and for good technical reasons the kernel developers are not likely to add it.
After a resume the kernel already knows exactly which virtual pages are resident and which ones are still on the swap device – that information is part of the hibernate image.
What it does not do is read those swapped-out pages ...
You need to be logged in to submit an answer