Skip to content

Commit

Permalink
PM/hibernate: touch NMI watchdog when creating snapshot
Browse files Browse the repository at this point in the history
There is a problem that when counting the pages for creating the
hibernation snapshot will take significant amount of time, especially on
system with large memory.  Since the counting job is performed with irq
disabled, this might lead to NMI lockup.  The following warning were
found on a system with 1.5TB DRAM:

  Freezing user space processes ... (elapsed 0.002 seconds) done.
  OOM killer disabled.
  PM: Preallocating image memory...
  NMI watchdog: Watchdog detected hard LOCKUP on cpu 27
  CPU: 27 PID: 3128 Comm: systemd-sleep Not tainted 4.13.0-0.rc2.git0.1.fc27.x86_64 hardkernel#1
  task: ffff9f01971ac000 task.stack: ffffb1a3f325c000
  RIP: 0010:memory_bm_find_bit+0xf4/0x100
  Call Trace:
   swsusp_set_page_free+0x2b/0x30
   mark_free_pages+0x147/0x1c0
   count_data_pages+0x41/0xa0
   hibernate_preallocate_memory+0x80/0x450
   hibernation_snapshot+0x58/0x410
   hibernate+0x17c/0x310
   state_store+0xdf/0xf0
   kobj_attr_store+0xf/0x20
   sysfs_kf_write+0x37/0x40
   kernfs_fop_write+0x11c/0x1a0
   __vfs_write+0x37/0x170
   vfs_write+0xb1/0x1a0
   SyS_write+0x55/0xc0
   entry_SYSCALL_64_fastpath+0x1a/0xa5
  ...
  done (allocated 6590003 pages)
  PM: Allocated 26360012 kbytes in 19.89 seconds (1325.28 MB/s)

It has taken nearly 20 seconds(2.10GHz CPU) thus the NMI lockup was
triggered.  In case the timeout of the NMI watch dog has been set to 1
second, a safe interval should be 6590003/20 = 320k pages in theory.
However there might also be some platforms running at a lower frequency,
so feed the watchdog every 100k pages.

[[email protected]: simplification]
  Link: http://lkml.kernel.org/r/[email protected]
[[email protected]: use interval of 128k instead of 100k to avoid modulus]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Chen Yu <[email protected]>
Reported-by: Jan Filipcewicz <[email protected]>
Suggested-by: Michal Hocko <[email protected]>
Reviewed-by: Michal Hocko <[email protected]>
Acked-by: Rafael J. Wysocki <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Len Brown <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
yu-chen-surf authored and torvalds committed Aug 25, 2017
1 parent 90a6cd5 commit 556b969
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include <linux/kthread.h>
#include <linux/memcontrol.h>
#include <linux/ftrace.h>
#include <linux/nmi.h>

#include <asm/sections.h>
#include <asm/tlbflush.h>
Expand Down Expand Up @@ -2535,9 +2536,14 @@ void drain_all_pages(struct zone *zone)

#ifdef CONFIG_HIBERNATION

/*
* Touch the watchdog for every WD_PAGE_COUNT pages.
*/
#define WD_PAGE_COUNT (128*1024)

void mark_free_pages(struct zone *zone)
{
unsigned long pfn, max_zone_pfn;
unsigned long pfn, max_zone_pfn, page_count = WD_PAGE_COUNT;
unsigned long flags;
unsigned int order, t;
struct page *page;
Expand All @@ -2552,6 +2558,11 @@ void mark_free_pages(struct zone *zone)
if (pfn_valid(pfn)) {
page = pfn_to_page(pfn);

if (!--page_count) {
touch_nmi_watchdog();
page_count = WD_PAGE_COUNT;
}

if (page_zone(page) != zone)
continue;

Expand All @@ -2565,8 +2576,13 @@ void mark_free_pages(struct zone *zone)
unsigned long i;

pfn = page_to_pfn(page);
for (i = 0; i < (1UL << order); i++)
for (i = 0; i < (1UL << order); i++) {
if (!--page_count) {
touch_nmi_watchdog();
page_count = WD_PAGE_COUNT;
}
swsusp_set_page_free(pfn_to_page(pfn + i));
}
}
}
spin_unlock_irqrestore(&zone->lock, flags);
Expand Down

0 comments on commit 556b969

Please sign in to comment.