Skip to content

Commit c1b3703

Browse files
Pavel Tatashingregkh
authored andcommitted
mm/page_alloc.c: broken deferred calculation
commit d135e5750205a21a212a19dbb05aeb339e2cbea7 upstream. In reset_deferred_meminit() we determine number of pages that must not be deferred. We initialize pages for at least 2G of memory, but also pages for reserved memory in this node. The reserved memory is determined in this function: memblock_reserved_memory_within(), which operates over physical addresses, and returns size in bytes. However, reset_deferred_meminit() assumes that that this function operates with pfns, and returns page count. The result is that in the best case machine boots slower than expected due to initializing more pages than needed in single thread, and in the worst case panics because fewer than needed pages are initialized early. Link: http://lkml.kernel.org/r/20171021011707.15191-1-pasha.tatashin@oracle.com Fixes: 864b9a393dcb ("mm: consider memblock reservations for deferred memory initialization sizing") Signed-off-by: Pavel Tatashin <pasha.tatashin@oracle.com> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Mel Gorman <mgorman@techsingularity.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4ecf752 commit c1b3703

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

include/linux/mmzone.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,8 @@ typedef struct pglist_data {
688688
* is the first PFN that needs to be initialised.
689689
*/
690690
unsigned long first_deferred_pfn;
691-
unsigned long static_init_size;
691+
/* Number of non-deferred pages */
692+
unsigned long static_init_pgcnt;
692693
#endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */
693694
} pg_data_t;
694695

mm/page_alloc.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,28 +267,37 @@ EXPORT_SYMBOL(nr_online_nodes);
267267
int page_group_by_mobility_disabled __read_mostly;
268268

269269
#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
270+
271+
/*
272+
* Determine how many pages need to be initialized durig early boot
273+
* (non-deferred initialization).
274+
* The value of first_deferred_pfn will be set later, once non-deferred pages
275+
* are initialized, but for now set it ULONG_MAX.
276+
*/
270277
static inline void reset_deferred_meminit(pg_data_t *pgdat)
271278
{
272-
unsigned long max_initialise;
273-
unsigned long reserved_lowmem;
279+
phys_addr_t start_addr, end_addr;
280+
unsigned long max_pgcnt;
281+
unsigned long reserved;
274282

275283
/*
276284
* Initialise at least 2G of a node but also take into account that
277285
* two large system hashes that can take up 1GB for 0.25TB/node.
278286
*/
279-
max_initialise = max(2UL << (30 - PAGE_SHIFT),
280-
(pgdat->node_spanned_pages >> 8));
287+
max_pgcnt = max(2UL << (30 - PAGE_SHIFT),
288+
(pgdat->node_spanned_pages >> 8));
281289

282290
/*
283291
* Compensate the all the memblock reservations (e.g. crash kernel)
284292
* from the initial estimation to make sure we will initialize enough
285293
* memory to boot.
286294
*/
287-
reserved_lowmem = memblock_reserved_memory_within(pgdat->node_start_pfn,
288-
pgdat->node_start_pfn + max_initialise);
289-
max_initialise += reserved_lowmem;
295+
start_addr = PFN_PHYS(pgdat->node_start_pfn);
296+
end_addr = PFN_PHYS(pgdat->node_start_pfn + max_pgcnt);
297+
reserved = memblock_reserved_memory_within(start_addr, end_addr);
298+
max_pgcnt += PHYS_PFN(reserved);
290299

291-
pgdat->static_init_size = min(max_initialise, pgdat->node_spanned_pages);
300+
pgdat->static_init_pgcnt = min(max_pgcnt, pgdat->node_spanned_pages);
292301
pgdat->first_deferred_pfn = ULONG_MAX;
293302
}
294303

@@ -324,7 +333,7 @@ static inline bool update_defer_init(pg_data_t *pgdat,
324333
return true;
325334
/* Initialise at least 2G of the highest zone */
326335
(*nr_initialised)++;
327-
if ((*nr_initialised > pgdat->static_init_size) &&
336+
if ((*nr_initialised > pgdat->static_init_pgcnt) &&
328337
(pfn & (PAGES_PER_SECTION - 1)) == 0) {
329338
pgdat->first_deferred_pfn = pfn;
330339
return false;

0 commit comments

Comments
 (0)