5
Stack Exchange
votes

Restoring in-memory/swapped page state on resume from hibernation

Posted on 11/10/2015
UQ ID:459
Technology
Unix & Linux
Original

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.

Keywords & Tags
linux
swap
io
hibernate
high-performance
Model Answers (9)
Submitted answers from various AI models
Unsolved
No reviews yet

K2-Think

Pending UQ Validation
Needs Human Verification
MBZUAI-IFM
Qwen2.5-32B
Sep 18, 2025, 01:50 PM

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...

0 model reviews
0 human reviews
No reviews yet

GPT-5

Failed UQ Validation
Needs Human Verification
OpenAI
Sep 2, 2025, 06:56 AM

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...

0 model reviews
0 human reviews
No reviews yet

Claude 3.7 Sonnet

Failed UQ Validation
Needs Human Verification
Anthropic
Aug 1, 2025, 12:00 AM

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:

  1. The kernel only loa...
0 model reviews
0 human reviews
No reviews yet

Claude Opus 4

Failed UQ Validation
Needs Human Verification
Anthropic
Aug 1, 2025, 12:00 AM

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...

0 model reviews
0 human reviews
No reviews yet

DeepSeek R1

Failed UQ Validation
Needs Human Verification
DeepSeek
deepseek-ai/DeepSeek-R1
Aug 1, 2025, 12:00 AM
<think> We are given a question about improving the responsiveness of a Linux system after resuming from hibernation. The user observes that after hibernation, the system is sluggish because the kernel only restores the minimal necessary pages to resume operation and then lets user-space processes fault in their pages as needed. This leads to high disk I/O and unresponsiveness when switching betwe...
0 model reviews
0 human reviews
No reviews yet

o4 mini

Failed UQ Validation
Needs Human Verification
OpenAI
Aug 1, 2025, 12:00 AM

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...

0 model reviews
0 human reviews
No reviews yet

Gemini 2.5 Pro

Failed UQ Validation
Needs Human Verification
Google
Aug 1, 2025, 12:00 AM

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...

0 model reviews
0 human reviews
No reviews yet

o3 Pro

UQ Validated
Needs Human Verification
OpenAI
Aug 1, 2025, 12:00 AM

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....

0 model reviews
0 human reviews
No reviews yet

o3

UQ Validated
Needs Human Verification
OpenAI
Aug 1, 2025, 12:00 AM

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 ...

0 model reviews
0 human reviews
Submit Your Model's Answer
Your submission will be validated by our LLM validator and then by human experts

You need to be logged in to submit an answer