Skip to content

Commit 6ad696d

Browse files
Andi Kleentorvalds
authored andcommitted
mm: allow memory hotplug and hibernation in the same kernel
Allow memory hotplug and hibernation in the same kernel Memory hotplug and hibernation were exclusive in Kconfig. This is obviously a problem for distribution kernels who want to support both in the same image. After some discussions with Rafael and others the only problem is with parallel memory hotadd or removal while a hibernation operation is in process. It was also working for s390 before. This patch removes the Kconfig level exclusion, and simply makes the memory add / remove functions grab the pm_mutex to exclude against hibernation. Fixes a regression - old kernels didn't exclude memory hotadd and hibernation. Signed-off-by: Andi Kleen <ak@linux.intel.com> Cc: Gerald Schaefer <gerald.schaefer@de.ibm.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Yasunori Goto <y-goto@jp.fujitsu.com> Acked-by: Rafael J. Wysocki <rjw@sisk.pl> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9398180 commit 6ad696d

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

‎include/linux/suspend.h‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,32 @@ static inline int unregister_pm_notifier(struct notifier_block *nb)
301301
#define pm_notifier(fn, pri) do { (void)(fn); } while (0)
302302
#endif /* !CONFIG_PM_SLEEP */
303303

304+
extern struct mutex pm_mutex;
305+
304306
#ifndef CONFIG_HIBERNATION
305307
static inline void register_nosave_region(unsigned long b, unsigned long e)
306308
{
307309
}
308310
static inline void register_nosave_region_late(unsigned long b, unsigned long e)
309311
{
310312
}
311-
#endif
312313

313-
extern struct mutex pm_mutex;
314+
static inline void lock_system_sleep(void) {}
315+
static inline void unlock_system_sleep(void) {}
316+
317+
#else
318+
319+
/* Let some subsystems like memory hotadd exclude hibernation */
320+
321+
static inline void lock_system_sleep(void)
322+
{
323+
mutex_lock(&pm_mutex);
324+
}
325+
326+
static inline void unlock_system_sleep(void)
327+
{
328+
mutex_unlock(&pm_mutex);
329+
}
330+
#endif
314331

315332
#endif /* _LINUX_SUSPEND_H */

‎mm/Kconfig‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,9 @@ config SPARSEMEM_VMEMMAP
128128
config MEMORY_HOTPLUG
129129
bool "Allow for memory hot-add"
130130
depends on SPARSEMEM || X86_64_ACPI_NUMA
131-
depends on HOTPLUG && !(HIBERNATION && !S390) && ARCH_ENABLE_MEMORY_HOTPLUG
131+
depends on HOTPLUG && ARCH_ENABLE_MEMORY_HOTPLUG
132132
depends on (IA64 || X86 || PPC_BOOK3S_64 || SUPERH || S390)
133133

134-
comment "Memory hotplug is currently incompatible with Software Suspend"
135-
depends on SPARSEMEM && HOTPLUG && HIBERNATION && !S390
136-
137134
config MEMORY_HOTPLUG_SPARSE
138135
def_bool y
139136
depends on SPARSEMEM && MEMORY_HOTPLUG

‎mm/memory_hotplug.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/migrate.h>
2727
#include <linux/page-isolation.h>
2828
#include <linux/pfn.h>
29+
#include <linux/suspend.h>
2930

3031
#include <asm/tlbflush.h>
3132

@@ -485,14 +486,18 @@ int __ref add_memory(int nid, u64 start, u64 size)
485486
struct resource *res;
486487
int ret;
487488

489+
lock_system_sleep();
490+
488491
res = register_memory_resource(start, size);
492+
ret = -EEXIST;
489493
if (!res)
490-
return -EEXIST;
494+
goto out;
491495

492496
if (!node_online(nid)) {
493497
pgdat = hotadd_new_pgdat(nid, start);
498+
ret = -ENOMEM;
494499
if (!pgdat)
495-
return -ENOMEM;
500+
goto out;
496501
new_pgdat = 1;
497502
}
498503

@@ -515,14 +520,17 @@ int __ref add_memory(int nid, u64 start, u64 size)
515520
BUG_ON(ret);
516521
}
517522

518-
return ret;
523+
goto out;
524+
519525
error:
520526
/* rollback pgdat allocation and others */
521527
if (new_pgdat)
522528
rollback_node_hotadd(nid, pgdat);
523529
if (res)
524530
release_memory_resource(res);
525531

532+
out:
533+
unlock_system_sleep();
526534
return ret;
527535
}
528536
EXPORT_SYMBOL_GPL(add_memory);
@@ -759,14 +767,16 @@ int offline_pages(unsigned long start_pfn,
759767
if (!test_pages_in_a_zone(start_pfn, end_pfn))
760768
return -EINVAL;
761769

770+
lock_system_sleep();
771+
762772
zone = page_zone(pfn_to_page(start_pfn));
763773
node = zone_to_nid(zone);
764774
nr_pages = end_pfn - start_pfn;
765775

766776
/* set above range as isolated */
767777
ret = start_isolate_page_range(start_pfn, end_pfn);
768778
if (ret)
769-
return ret;
779+
goto out;
770780

771781
arg.start_pfn = start_pfn;
772782
arg.nr_pages = nr_pages;
@@ -844,6 +854,7 @@ int offline_pages(unsigned long start_pfn,
844854
writeback_set_ratelimit();
845855

846856
memory_notify(MEM_OFFLINE, &arg);
857+
unlock_system_sleep();
847858
return 0;
848859

849860
failed_removal:
@@ -853,6 +864,8 @@ int offline_pages(unsigned long start_pfn,
853864
/* pushback to free area */
854865
undo_isolate_page_range(start_pfn, end_pfn);
855866

867+
out:
868+
unlock_system_sleep();
856869
return ret;
857870
}
858871

0 commit comments

Comments
 (0)