Skip to content

Commit f46edbd

Browse files
djbwtorvalds
authored andcommitted
mm/sparsemem: add helpers track active portions of a section at boot
Prepare for hot{plug,remove} of sub-ranges of a section by tracking a sub-section active bitmask, each bit representing a PMD_SIZE span of the architecture's memory hotplug section size. The implications of a partially populated section is that pfn_valid() needs to go beyond a valid_section() check and either determine that the section is an "early section", or read the sub-section active ranges from the bitmask. The expectation is that the bitmask (subsection_map) fits in the same cacheline as the valid_section() / early_section() data, so the incremental performance overhead to pfn_valid() should be negligible. The rationale for using early_section() to short-ciruit the subsection_map check is that there are legacy code paths that use pfn_valid() at section granularity before validating the pfn against pgdat data. So, the early_section() check allows those traditional assumptions to persist while also permitting subsection_map to tell the truth for purposes of populating the unused portions of early sections with PMEM and other ZONE_DEVICE mappings. Link: http://lkml.kernel.org/r/156092350874.979959.18185938451405518285.stgit@dwillia2-desk3.amr.corp.intel.com Signed-off-by: Dan Williams <[email protected]> Reported-by: Qian Cai <[email protected]> Tested-by: Jane Chu <[email protected]> Tested-by: Aneesh Kumar K.V <[email protected]> [ppc64] Reviewed-by: Oscar Salvador <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Vlastimil Babka <[email protected]> Cc: Logan Gunthorpe <[email protected]> Cc: Pavel Tatashin <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Jeff Moyer <[email protected]> Cc: Jérôme Glisse <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Mike Rapoport <[email protected]> Cc: Toshi Kani <[email protected]> Cc: Wei Yang <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: Christoph Hellwig <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 326e1b8 commit f46edbd

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

include/linux/mmzone.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,8 @@ struct mem_section_usage {
11781178
unsigned long pageblock_flags[0];
11791179
};
11801180

1181+
void subsection_map_init(unsigned long pfn, unsigned long nr_pages);
1182+
11811183
struct page;
11821184
struct page_ext;
11831185
struct mem_section {
@@ -1321,12 +1323,40 @@ static inline struct mem_section *__pfn_to_section(unsigned long pfn)
13211323

13221324
extern unsigned long __highest_present_section_nr;
13231325

1326+
static inline int subsection_map_index(unsigned long pfn)
1327+
{
1328+
return (pfn & ~(PAGE_SECTION_MASK)) / PAGES_PER_SUBSECTION;
1329+
}
1330+
1331+
#ifdef CONFIG_SPARSEMEM_VMEMMAP
1332+
static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
1333+
{
1334+
int idx = subsection_map_index(pfn);
1335+
1336+
return test_bit(idx, ms->usage->subsection_map);
1337+
}
1338+
#else
1339+
static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn)
1340+
{
1341+
return 1;
1342+
}
1343+
#endif
1344+
13241345
#ifndef CONFIG_HAVE_ARCH_PFN_VALID
13251346
static inline int pfn_valid(unsigned long pfn)
13261347
{
1348+
struct mem_section *ms;
1349+
13271350
if (pfn_to_section_nr(pfn) >= NR_MEM_SECTIONS)
13281351
return 0;
1329-
return valid_section(__nr_to_section(pfn_to_section_nr(pfn)));
1352+
ms = __nr_to_section(pfn_to_section_nr(pfn));
1353+
if (!valid_section(ms))
1354+
return 0;
1355+
/*
1356+
* Traditionally early sections always returned pfn_valid() for
1357+
* the entire section-sized span.
1358+
*/
1359+
return early_section(ms) || pfn_section_valid(ms, pfn);
13301360
}
13311361
#endif
13321362

@@ -1358,6 +1388,7 @@ void sparse_init(void);
13581388
#define sparse_init() do {} while (0)
13591389
#define sparse_index_init(_sec, _nid) do {} while (0)
13601390
#define pfn_present pfn_valid
1391+
#define subsection_map_init(_pfn, _nr_pages) do {} while (0)
13611392
#endif /* CONFIG_SPARSEMEM */
13621393

13631394
/*

mm/page_alloc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7351,12 +7351,18 @@ void __init free_area_init_nodes(unsigned long *max_zone_pfn)
73517351
(u64)zone_movable_pfn[i] << PAGE_SHIFT);
73527352
}
73537353

7354-
/* Print out the early node map */
7354+
/*
7355+
* Print out the early node map, and initialize the
7356+
* subsection-map relative to active online memory ranges to
7357+
* enable future "sub-section" extensions of the memory map.
7358+
*/
73557359
pr_info("Early memory node ranges\n");
7356-
for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid)
7360+
for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) {
73577361
pr_info(" node %3d: [mem %#018Lx-%#018Lx]\n", nid,
73587362
(u64)start_pfn << PAGE_SHIFT,
73597363
((u64)end_pfn << PAGE_SHIFT) - 1);
7364+
subsection_map_init(start_pfn, end_pfn - start_pfn);
7365+
}
73607366

73617367
/* Initialise every node */
73627368
mminit_verify_pageflags_layout();

mm/sparse.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,41 @@ static inline unsigned long first_present_section_nr(void)
210210
return next_present_section_nr(-1);
211211
}
212212

213+
void subsection_mask_set(unsigned long *map, unsigned long pfn,
214+
unsigned long nr_pages)
215+
{
216+
int idx = subsection_map_index(pfn);
217+
int end = subsection_map_index(pfn + nr_pages - 1);
218+
219+
bitmap_set(map, idx, end - idx + 1);
220+
}
221+
222+
void __init subsection_map_init(unsigned long pfn, unsigned long nr_pages)
223+
{
224+
int end_sec = pfn_to_section_nr(pfn + nr_pages - 1);
225+
int i, start_sec = pfn_to_section_nr(pfn);
226+
227+
if (!nr_pages)
228+
return;
229+
230+
for (i = start_sec; i <= end_sec; i++) {
231+
struct mem_section *ms;
232+
unsigned long pfns;
233+
234+
pfns = min(nr_pages, PAGES_PER_SECTION
235+
- (pfn & ~PAGE_SECTION_MASK));
236+
ms = __nr_to_section(i);
237+
subsection_mask_set(ms->usage->subsection_map, pfn, pfns);
238+
239+
pr_debug("%s: sec: %d pfns: %ld set(%d, %d)\n", __func__, i,
240+
pfns, subsection_map_index(pfn),
241+
subsection_map_index(pfn + pfns - 1));
242+
243+
pfn += pfns;
244+
nr_pages -= pfns;
245+
}
246+
}
247+
213248
/* Record a memory area against a node. */
214249
void __init memory_present(int nid, unsigned long start, unsigned long end)
215250
{

0 commit comments

Comments
 (0)