[PATCH 2 of 4] hotplug-memory: adding non-section-aligned memory is bad

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jeremy Fitzhardinge
Date: Thursday, March 27, 2008 - 5:28 pm

Adding non-section-aligned memory will cause bad results, because page
structures are only built on section-aligned boundaries.  Also, memory
whose size isn't a multiple of the section size is silently ignored.

This patch adds a couple of WARN_ONs to help confused programmers work
out what's going wrong when they hotplug memory without being aware of
these constraints.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
Cc: Christoph Lameter <clameter@sgi.com>
Cc: Dave Hansen <dave@linux.vnet.ibm.com>

diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
--- a/include/linux/mmzone.h
+++ b/include/linux/mmzone.h
@@ -784,6 +784,9 @@
 #define PAGES_PER_SECTION       (1UL << PFN_SECTION_SHIFT)
 #define PAGE_SECTION_MASK	(~(PAGES_PER_SECTION-1))
 
+#define SECTION_SIZE		(1UL << SECTION_SIZE_BITS)
+#define SECTION_SIZE_MASK	(SECTION_SIZE - 1)
+
 #define SECTION_BLOCKFLAGS_BITS \
 	((1UL << (PFN_SECTION_SHIFT - pageblock_order)) * NR_PAGEBLOCK_BITS)
 
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -300,6 +300,11 @@
 	int ret;
 	u64 start = res->start;
 	u64 size = res->end - res->start + 1;
+
+	/* Adding non-section-aligned memory will give unexpected
+	   and unintuitive results. */
+	WARN_ON((start & SECTION_SIZE_MASK) != 0);
+	WARN_ON((size & SECTION_SIZE_MASK) != 0);
 
 	if (!node_online(nid)) {
 		pgdat = hotadd_new_pgdat(nid, start);


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0 of 4] [RFC] hotplug memory: minor updates, Jeremy Fitzhardinge, (Thu Mar 27, 5:28 pm)
[PATCH 1 of 4] hotplug-memory: add add_memory_resource, Jeremy Fitzhardinge, (Thu Mar 27, 5:28 pm)
[PATCH 2 of 4] hotplug-memory: adding non-section-aligned ..., Jeremy Fitzhardinge, (Thu Mar 27, 5:28 pm)
[PATCH 3 of 4] sparsemem: reduce i386 PAE section size, Jeremy Fitzhardinge, (Thu Mar 27, 5:28 pm)
[PATCH 4 of 4] paravirt_ops: don't steal memory resources ..., Jeremy Fitzhardinge, (Thu Mar 27, 5:28 pm)
Re: [PATCH 3 of 4] sparsemem: reduce i386 PAE section size, Christoph Lameter, (Thu Mar 27, 5:35 pm)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., KAMEZAWA Hiroyuki, (Thu Mar 27, 6:27 pm)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., KAMEZAWA Hiroyuki, (Thu Mar 27, 6:54 pm)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., Jeremy Fitzhardinge, (Thu Mar 27, 7:13 pm)
Re: [PATCH 3 of 4] sparsemem: reduce i386 PAE section size, Jeremy Fitzhardinge, (Thu Mar 27, 7:26 pm)
Re: [PATCH 3 of 4] sparsemem: reduce i386 PAE section size, Christoph Lameter, (Thu Mar 27, 7:27 pm)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., KAMEZAWA Hiroyuki, (Thu Mar 27, 7:33 pm)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., Jeremy Fitzhardinge, (Thu Mar 27, 7:51 pm)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., KAMEZAWA Hiroyuki, (Thu Mar 27, 8:17 pm)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., Jeremy Fitzhardinge, (Thu Mar 27, 9:07 pm)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., Jeremy Fitzhardinge, (Thu Mar 27, 9:20 pm)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., KAMEZAWA Hiroyuki, (Thu Mar 27, 9:39 pm)
Re: [PATCH 3 of 4] sparsemem: reduce i386 PAE section size, Jeremy Fitzhardinge, (Thu Mar 27, 11:18 pm)
Re: [PATCH 0 of 4] [RFC] hotplug memory: minor updates, Ingo Molnar, (Fri Mar 28, 2:12 am)
Re: [PATCH 0 of 4] [RFC] hotplug memory: minor updates, Jeremy Fitzhardinge, (Fri Mar 28, 9:07 am)
Re: [PATCH 3 of 4] sparsemem: reduce i386 PAE section size, Jeremy Fitzhardinge, (Fri Mar 28, 11:05 am)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., Jeremy Fitzhardinge, (Fri Mar 28, 11:19 am)
Re: [PATCH 2 of 4] hotplug-memory: adding non-section-alig ..., Jeremy Fitzhardinge, (Fri Mar 28, 2:30 pm)
Re: [PATCH 0 of 4] [RFC] hotplug memory: minor updates, Ingo Molnar, (Fri Mar 28, 3:04 pm)