Skip to content

Commit 9d99aaa

Browse files
Andi KleenLinus Torvalds
authored andcommitted
[PATCH] x86_64: Support memory hotadd without sparsemem
Memory hotadd doesn't need SPARSEMEM, but can be handled by just preallocating mem_maps. This only needs some untangling of ifdefs to enable the necessary code even without SPARSEMEM. Originally from Keith Mannthey, hacked by AK. Signed-off-by: Andi Kleen <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 805e8c0 commit 9d99aaa

File tree

6 files changed

+47
-12
lines changed

6 files changed

+47
-12
lines changed

arch/i386/mm/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,7 @@ void __init mem_init(void)
651651
* Specifically, in the case of x86, we will always add
652652
* memory to the highmem for now.
653653
*/
654+
#ifdef CONFIG_HOTPLUG_MEMORY
654655
#ifndef CONFIG_NEED_MULTIPLE_NODES
655656
int add_memory(u64 start, u64 size)
656657
{
@@ -667,6 +668,7 @@ int remove_memory(u64 start, u64 size)
667668
return -EINVAL;
668669
}
669670
#endif
671+
#endif
670672

671673
kmem_cache_t *pgd_cache;
672674
kmem_cache_t *pmd_cache;

arch/x86_64/kernel/e820.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static inline int bad_addr(unsigned long *addrp, unsigned long size)
8080
return 0;
8181
}
8282

83-
int __init e820_mapped(unsigned long start, unsigned long end, unsigned type)
83+
int __meminit e820_mapped(unsigned long start, unsigned long end, unsigned type)
8484
{
8585
int i;
8686
for (i = 0; i < e820.nr_map; i++) {

arch/x86_64/mm/init.c

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,8 @@ void __init clear_kernel_mapping(unsigned long address, unsigned long size)
507507

508508
/*
509509
* Memory hotplug specific functions
510-
* These are only for non-NUMA machines right now.
511510
*/
512-
#ifdef CONFIG_MEMORY_HOTPLUG
511+
#if defined(CONFIG_ACPI_HOTPLUG_MEMORY) || defined(CONFIG_ACPI_HOTPLUG_MEMORY_MODULE)
513512

514513
void online_page(struct page *page)
515514
{
@@ -520,6 +519,39 @@ void online_page(struct page *page)
520519
num_physpages++;
521520
}
522521

522+
#ifndef CONFIG_MEMORY_HOTPLUG
523+
/*
524+
* Memory Hotadd without sparsemem. The mem_maps have been allocated in advance,
525+
* just online the pages.
526+
*/
527+
int __add_pages(struct zone *z, unsigned long start_pfn, unsigned long nr_pages)
528+
{
529+
int err = -EIO;
530+
unsigned long pfn;
531+
unsigned long total = 0, mem = 0;
532+
for (pfn = start_pfn; pfn < start_pfn + nr_pages; pfn++) {
533+
unsigned long addr = pfn << PAGE_SHIFT;
534+
if (pfn_valid(pfn) && e820_mapped(addr, addr+1, E820_RAM)) {
535+
online_page(pfn_to_page(pfn));
536+
err = 0;
537+
mem++;
538+
}
539+
total++;
540+
}
541+
if (!err) {
542+
z->spanned_pages += total;
543+
z->present_pages += mem;
544+
z->zone_pgdat->node_spanned_pages += total;
545+
z->zone_pgdat->node_present_pages += mem;
546+
}
547+
return err;
548+
}
549+
#endif
550+
551+
/*
552+
* Memory is added always to NORMAL zone. This means you will never get
553+
* additional DMA/DMA32 memory.
554+
*/
523555
int add_memory(u64 start, u64 size)
524556
{
525557
struct pglist_data *pgdat = NODE_DATA(0);

drivers/acpi/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ config ACPI_CONTAINER
329329
config ACPI_HOTPLUG_MEMORY
330330
tristate "Memory Hotplug"
331331
depends on ACPI
332-
depends on MEMORY_HOTPLUG
332+
depends on MEMORY_HOTPLUG || X86_64
333333
default n
334334
help
335335
This driver adds supports for ACPI Memory Hotplug. This driver

include/linux/init.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ void __init parse_early_param(void);
245245
#define __cpuexitdata __exitdata
246246
#endif
247247

248-
#ifdef CONFIG_MEMORY_HOTPLUG
248+
#if defined(CONFIG_MEMORY_HOTPLUG) || defined(CONFIG_ACPI_HOTPLUG_MEMORY) \
249+
|| defined(CONFIG_ACPI_HOTPLUG_MEMORY_MODULE)
249250
#define __meminit
250251
#define __meminitdata
251252
#define __memexit

include/linux/memory_hotplug.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ extern int add_one_highpage(struct page *page, int pfn, int bad_ppro);
5858
/* need some defines for these for archs that don't support it */
5959
extern void online_page(struct page *page);
6060
/* VM interface that may be used by firmware interface */
61-
extern int add_memory(u64 start, u64 size);
62-
extern int remove_memory(u64 start, u64 size);
6361
extern int online_pages(unsigned long, unsigned long);
6462

6563
/* reasonably generic interface to expand the physical pages in a zone */
@@ -92,11 +90,6 @@ static inline int mhp_notimplemented(const char *func)
9290
return -ENOSYS;
9391
}
9492

95-
static inline int __add_pages(struct zone *zone, unsigned long start_pfn,
96-
unsigned long nr_pages)
97-
{
98-
return mhp_notimplemented(__FUNCTION__);
99-
}
10093
#endif /* ! CONFIG_MEMORY_HOTPLUG */
10194
static inline int __remove_pages(struct zone *zone, unsigned long start_pfn,
10295
unsigned long nr_pages)
@@ -105,4 +98,11 @@ static inline int __remove_pages(struct zone *zone, unsigned long start_pfn,
10598
dump_stack();
10699
return -ENOSYS;
107100
}
101+
102+
#if defined(CONFIG_MEMORY_HOTPLUG) || defined(CONFIG_ACPI_HOTPLUG_MEMORY) \
103+
|| defined(CONFIG_ACPI_HOTPLUG_MEMORY_MODULE)
104+
extern int add_memory(u64 start, u64 size);
105+
extern int remove_memory(u64 start, u64 size);
106+
#endif
107+
108108
#endif /* __LINUX_MEMORY_HOTPLUG_H */

0 commit comments

Comments
 (0)