Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

PM: hibernate: shrink shmem pages after dev_pm_ops.prepare()

When hibernate with data center dGPUs, huge number of VRAM data will be
moved to shmem during dev_pm_ops.prepare(). These shmem pages take a lot
of system memory so that there's no enough free memory for creating the
hibernation image. This will cause hibernation fail and abort.

After dev_pm_ops.prepare(), call shrink_all_memory() to force move shmem
pages to swap disk and reclaim the pages, so that there's enough system
memory for hibernation image and less pages needed to copy to the image.

This patch can only flush and free about half shmem pages. It will be
better to flush and free more pages, even all of shmem pages, so that
there're less pages to be copied to the hibernation image and the overall
hibernation time can be reduced.

Signed-off-by: Samuel Zhang <guoqing.zhang@amd.com>
Acked-by: Rafael J. Wysocki <rafael@kernel.org>
Link: https://lore.kernel.org/r/20250710062313.3226149-4-guoqing.zhang@amd.com
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>

authored by

Samuel Zhang and committed by
Mario Limonciello
2640e819 924dda02

+26
+26
kernel/power/hibernate.c
··· 381 381 return error; 382 382 } 383 383 384 + static void shrink_shmem_memory(void) 385 + { 386 + struct sysinfo info; 387 + unsigned long nr_shmem_pages, nr_freed_pages; 388 + 389 + si_meminfo(&info); 390 + nr_shmem_pages = info.sharedram; /* current page count used for shmem */ 391 + /* 392 + * The intent is to reclaim all shmem pages. Though shrink_all_memory() can 393 + * only reclaim about half of them, it's enough for creating the hibernation 394 + * image. 395 + */ 396 + nr_freed_pages = shrink_all_memory(nr_shmem_pages); 397 + pr_debug("requested to reclaim %lu shmem pages, actually freed %lu pages\n", 398 + nr_shmem_pages, nr_freed_pages); 399 + } 400 + 384 401 /** 385 402 * hibernation_snapshot - Quiesce devices and create a hibernation image. 386 403 * @platform_mode: If set, use platform driver to prepare for the transition. ··· 438 421 dpm_complete(PMSG_RECOVER); 439 422 goto Thaw; 440 423 } 424 + 425 + /* 426 + * Device drivers may move lots of data to shmem in dpm_prepare(). The shmem 427 + * pages will use lots of system memory, causing hibernation image creation 428 + * fail due to insufficient free memory. 429 + * This call is to force flush the shmem pages to swap disk and reclaim 430 + * the system memory so that image creation can succeed. 431 + */ 432 + shrink_shmem_memory(); 441 433 442 434 console_suspend_all(); 443 435 pm_restrict_gfp_mask();