Skip to contentSkip to conversation

sparsemem interaction with memory add bug fixes

PATCH In review Mike Kravetz 5 participants 6 messages Apr 12, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparsemem interaction with memory add bug fixes

This patch fixes two bugs with the way sparsemem interacts with memory add. They are:
- memory leak if memmap for section already exists
- calling alloc_bootmem_node() after boot
These bugs were discovered and a first cut at the fixes were provided by Arnd Bergmann <[email protected]> and Joel Schopp <[email protected]>.

mm/sparse.c +5 -2
diff -Naupr linux-2.6.17-rc1-mm2/mm/sparse.c linux-2.6.17-rc1-mm2.work/mm/sparse.c
@@ -32,7 +32,10 @@ static struct mem_section *sparse_index_
 	unsigned long array_size = SECTIONS_PER_ROOT *
 				   sizeof(struct mem_section);
 
-	section = alloc_bootmem_node(NODE_DATA(nid), array_size);
+	if (system_state == SYSTEM_RUNNING)
+		section = kmalloc_node(array_size, GFP_KERNEL, nid);
+	else
+		section = alloc_bootmem_node(NODE_DATA(nid), array_size);
 
 	if (section)
 		memset(section, 0, array_size);
@@ -281,9 +284,9 @@ int sparse_add_one_section(struct zone *
 
 	ret = sparse_init_one_section(ms, section_nr, memmap);
 
+out:
 	if (ret <= 0)
 		__kfree_section_memmap(memmap, nr_pages);
-out:
 	pgdat_resize_unlock(pgdat, &flags);
 	return ret;
 }
#1 lore raw
Quoted 9 lines · Mike Kravetz

This patch fixes two bugs with the way sparsemem interacts with memory add. They are:
- memory leak if memmap for section already exists
- calling alloc_bootmem_node() after boot
These bugs were discovered and a first cut at the fixes were provided by Arnd Bergmann <[email protected]> and Joel Schopp <[email protected]>.

These fix memory adding spu addresses on cell, among other things.

#2 lore raw
In reply to Mike Kravetz
Quoted 25 lines · Mike Kravetz

This patch fixes two bugs with the way sparsemem interacts with memory add. They are:
- memory leak if memmap for section already exists
- calling alloc_bootmem_node() after boot
These bugs were discovered and a first cut at the fixes were provided by Arnd Bergmann <[email protected]> and Joel Schopp <[email protected]>.

diff -Naupr linux-2.6.17-rc1-mm2/mm/sparse.c linux-2.6.17-rc1-mm2.work/mm/sparse.c

mm/sparse.c +4 -1
@@ -32,7 +32,10 @@ static struct mem_section *sparse_index_
 	unsigned long array_size = SECTIONS_PER_ROOT *
 				   sizeof(struct mem_section);
 
-	section = alloc_bootmem_node(NODE_DATA(nid), array_size);
+	if (system_state == SYSTEM_RUNNING)
+		section = kmalloc_node(array_size, GFP_KERNEL, nid);
+	else
+		section = alloc_bootmem_node(NODE_DATA(nid), array_size);
 
 	if (section)
 		memset(section, 0, array_size);

mm/sparse.c int sparse_add_one_section(struct zone * · line 292

Quoted 10 lines
mm/sparse.c +1 -1
@@ -281,9 +284,9 @@ int sparse_add_one_section(struct zone *
 
 	ret = sparse_init_one_section(ms, section_nr, memmap);
 
+out:
 	if (ret <= 0)
 		__kfree_section_memmap(memmap, nr_pages);
-out:
 	pgdat_resize_unlock(pgdat, &flags);
 	return ret;
 }

First change looks sane. For the second it makes it obvious that we are freeing the alloc'd section within the pgdat resize lock. Doesn't seem to make any sense to do that to me? Perhaps it should be more like the attached.

-apw

 sparse.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
mm/sparse.c +2 -2
diff -upN reference/mm/sparse.c current/mm/sparse.c
@@ -281,9 +281,9 @@ int sparse_add_one_section(struct zone *
 
 	ret = sparse_init_one_section(ms, section_nr, memmap);
 
-	if (ret <= 0)
-		__kfree_section_memmap(memmap, nr_pages);
 out:
 	pgdat_resize_unlock(pgdat, &flags);
+	if (ret <= 0)
+		__kfree_section_memmap(memmap, nr_pages);
 	return ret;
 }
#3 lore raw
Quoted 55 lines · Andy Whitcroft
Quoted 25 lines · Mike Kravetz

This patch fixes two bugs with the way sparsemem interacts with memory add. They are:
- memory leak if memmap for section already exists
- calling alloc_bootmem_node() after boot
These bugs were discovered and a first cut at the fixes were provided by Arnd Bergmann <[email protected]> and Joel Schopp <[email protected]>.

diff -Naupr linux-2.6.17-rc1-mm2/mm/sparse.c linux-2.6.17-rc1-mm2.work/mm/sparse.c

mm/sparse.c +4 -1
@@ -32,7 +32,10 @@ static struct mem_section *sparse_index_
 	unsigned long array_size = SECTIONS_PER_ROOT *
 				   sizeof(struct mem_section);
 
-	section = alloc_bootmem_node(NODE_DATA(nid), array_size);
+	if (system_state == SYSTEM_RUNNING)
+		section = kmalloc_node(array_size, GFP_KERNEL, nid);
+	else
+		section = alloc_bootmem_node(NODE_DATA(nid), array_size);
 
 	if (section)
 		memset(section, 0, array_size);

mm/sparse.c int sparse_add_one_section(struct zone * · line 292

Quoted 10 lines
mm/sparse.c +1 -1
@@ -281,9 +284,9 @@ int sparse_add_one_section(struct zone *
 
 	ret = sparse_init_one_section(ms, section_nr, memmap);
 
+out:
 	if (ret <= 0)
 		__kfree_section_memmap(memmap, nr_pages);
-out:
 	pgdat_resize_unlock(pgdat, &flags);
 	return ret;
 }

First change looks sane. For the second it makes it obvious that we are freeing the alloc'd section within the pgdat resize lock. Doesn't seem to make any sense to do that to me? Perhaps it should be more like the attached.

-apw

------------------------------------------------------------------------

 sparse.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff -upN reference/mm/sparse.c current/mm/sparse.c

mm/sparse.c +0 -0
@@ -281,9 +281,9 @@ int sparse_add_one_section(struct zone *
 

mm/sparse.c int sparse_add_one_section(struct zone * · line 289

Quoted 10 lines
mm/sparse.c +2 -2
 	ret = sparse_init_one_section(ms, section_nr, memmap);
 
-	if (ret <= 0)
-		__kfree_section_memmap(memmap, nr_pages);
 out:
 	pgdat_resize_unlock(pgdat, &flags);
+	if (ret <= 0)
+		__kfree_section_memmap(memmap, nr_pages);
 	return ret;
 }

Whatever, I don't really care. It doesn't matter functionally if we free under the pgdat_resize lock or not. This looks fine, as does the original patch. If resizing pgdats was a hot path we might prefer this way outside the lock.

-Joel

#4 lore raw
In reply to Mike Kravetz
Quoted 6 lines · Mike Kravetz

This patch fixes two bugs with the way sparsemem interacts with memory add. They are:
- memory leak if memmap for section already exists
- calling alloc_bootmem_node() after boot
These bugs were discovered and a first cut at the fixes were provided by Arnd Bergmann <[email protected]> and Joel Schopp <[email protected]>.

At first glance, these seem fine to me.

Just out of curiosity. Can these issues be revealed with current code, or do they only show up with the cell changes?

-- Dave

#5 lore raw
Quoted 2 lines · Dave Hansen

Just out of curiosity. Can these issues be revealed with current code, or do they only show up with the cell changes?

Yes, you could hit either of these doing memory adds with the current code. The follow up issue of adding sub-section amounts of memory is cell specific.

Signature · 1 line
Mike