Skip to contentSkip to conversation

mm/sparse: consistently do not zero memmap

PATCH In review [email protected] 2 participants 2 messages Nov 22, 2019

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/4 mm/sparse: consistently do not zero memmap

From: Vincent Whitchurch <[email protected]>
Subject: mm/sparse: consistently do not zero memmap

sparsemem without VMEMMAP has two allocation paths to allocate the memory needed for its memmap (done in sparse_mem_map_populate()).

In one allocation path (sparse_buffer_alloc() succeeds), the memory is not zeroed (since it was previously allocated with memblock_alloc_try_nid_raw()).

In the other allocation path (sparse_buffer_alloc() fails and sparse_mem_map_populate() falls back to memblock_alloc_try_nid()), the memory is zeroed.

AFAICS this difference does not appear to be on purpose. If the code is supposed to work with non-initialized memory (__init_single_page() takes care of zeroing the struct pages which are actually used), we should consistently not zero the memory, to avoid masking bugs.

(I noticed this because on my ARM64 platform, with 1 GiB of memory the
first [and only] section is allocated from the zeroing path while with 2 GiB of memory the first 1 GiB section is allocated from the non-zeroing path.)

Michal: "the main user visible problem is a memory wastage. The overal amount of memory should be small. I wouldn't call it stable material."

---

 mm/sparse.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/sparse.c renamed from mm/sparse.c~mm-sparse-consistently-do-not-zero-memmap +1 -1
@@ -458,7 +458,7 @@ struct page __init *__populate_section_m
 	if (map)
 		return map;
 
-	map = memblock_alloc_try_nid(size,
+	map = memblock_alloc_try_nid_raw(size,
 					  PAGE_SIZE, addr,
 					  MEMBLOCK_ALLOC_ACCESSIBLE, nid);
 	if (!map)

_

#1 lore raw
Quoted 6 lines · On Thu, Nov 21, 2019 at 5:53 PM <[email protected]> wrote:

AFAICS this difference does not appear to be on purpose. If the code is supposed to work with non-initialized memory (__init_single_page() takes care of zeroing the struct pages which are actually used), we should consistently not zero the memory, to avoid masking bugs.

This does not seem to be an actual fix, and I will not apply it this late in the rc game.

Andrew, please stop sending cleanups as "fixes".

Linus