Skip to content

Commit 078eb6a

Browse files
Pavel Tatashintorvalds
Pavel Tatashin
authored andcommitted
x86/mm/memory_hotplug: determine block size based on the end of boot memory
Memory sections are combined into "memory block" chunks. These chunks are the units upon which memory can be added and removed. On x86, the new memory may be added after the end of the boot memory, therefore, if block size does not align with end of boot memory, memory hot-plugging/hot-removing can be broken. Memory sections are combined into "memory block" chunks. These chunks are the units upon which memory can be added and removed. On x86 the new memory may be added after the end of the boot memory, therefore, if block size does not align with end of boot memory, memory hotplugging/hotremoving can be broken. Currently, whenever machine is booted with more than 64G the block size is unconditionally increased to 2G from the base 128M. This is done in order to reduce number of memory device files in sysfs: /sys/devices/system/memory/memoryXXX We must use the largest allowed block size that aligns to the next address to be able to hotplug the next block of memory. So, when memory is larger or equal to 64G, we check the end address and find the largest block size that is still power of two but smaller or equal to 2G. Before, the fix: Run qemu with: -m 64G,slots=2,maxmem=66G -object memory-backend-ram,id=mem1,size=2G (qemu) device_add pc-dimm,id=dimm1,memdev=mem1 Block size [0x80000000] unaligned hotplug range: start 0x1040000000, size 0x80000000 acpi PNP0C80:00: add_memory failed acpi PNP0C80:00: acpi_memory_enable_device() error acpi PNP0C80:00: Enumeration failure With the fix memory is added successfully as the block size is set to 1G, and therefore aligns with start address 0x1040000000. [[email protected]: v4] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Pavel Tatashin <[email protected]> Reviewed-by: Ingo Molnar <[email protected]> Cc: "H. Peter Anvin" <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Steven Sistare <[email protected]> Cc: Daniel Jordan <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Bharata B Rao <[email protected]> Cc: Dan Williams <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Baoquan He <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent ba32558 commit 078eb6a

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

arch/x86/mm/init_64.c

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,14 +1328,39 @@ int kern_addr_valid(unsigned long addr)
13281328
return pfn_valid(pte_pfn(*pte));
13291329
}
13301330

1331+
/*
1332+
* Block size is the minimum amount of memory which can be hotplugged or
1333+
* hotremoved. It must be power of two and must be equal or larger than
1334+
* MIN_MEMORY_BLOCK_SIZE.
1335+
*/
1336+
#define MAX_BLOCK_SIZE (2UL << 30)
1337+
1338+
/* Amount of ram needed to start using large blocks */
1339+
#define MEM_SIZE_FOR_LARGE_BLOCK (64UL << 30)
1340+
13311341
static unsigned long probe_memory_block_size(void)
13321342
{
1333-
unsigned long bz = MIN_MEMORY_BLOCK_SIZE;
1343+
unsigned long boot_mem_end = max_pfn << PAGE_SHIFT;
1344+
unsigned long bz;
13341345

1335-
/* if system is UV or has 64GB of RAM or more, use large blocks */
1336-
if (is_uv_system() || ((max_pfn << PAGE_SHIFT) >= (64UL << 30)))
1337-
bz = 2UL << 30; /* 2GB */
1346+
/* If this is UV system, always set 2G block size */
1347+
if (is_uv_system()) {
1348+
bz = MAX_BLOCK_SIZE;
1349+
goto done;
1350+
}
13381351

1352+
/* Use regular block if RAM is smaller than MEM_SIZE_FOR_LARGE_BLOCK */
1353+
if (boot_mem_end < MEM_SIZE_FOR_LARGE_BLOCK) {
1354+
bz = MIN_MEMORY_BLOCK_SIZE;
1355+
goto done;
1356+
}
1357+
1358+
/* Find the largest allowed block size that aligns to memory end */
1359+
for (bz = MAX_BLOCK_SIZE; bz > MIN_MEMORY_BLOCK_SIZE; bz >>= 1) {
1360+
if (IS_ALIGNED(boot_mem_end, bz))
1361+
break;
1362+
}
1363+
done:
13391364
pr_info("x86/mm: Memory block size: %ldMB\n", bz >> 20);
13401365

13411366
return bz;

0 commit comments

Comments
 (0)