Skip to content

Commit cb1fb15

Browse files
Michal Hockogregkh
authored andcommitted
mm: consider memblock reservations for deferred memory initialization sizing
commit 864b9a393dcb5aed09b8fd31b9bbda0fdda99374 upstream. We have seen an early OOM killer invocation on ppc64 systems with crashkernel=4096M: kthreadd invoked oom-killer: gfp_mask=0x16040c0(GFP_KERNEL|__GFP_COMP|__GFP_NOTRACK), nodemask=7, order=0, oom_score_adj=0 kthreadd cpuset=/ mems_allowed=7 CPU: 0 PID: 2 Comm: kthreadd Not tainted 4.4.68-1.gd7fe927-default #1 Call Trace: dump_stack+0xb0/0xf0 (unreliable) dump_header+0xb0/0x258 out_of_memory+0x5f0/0x640 __alloc_pages_nodemask+0xa8c/0xc80 kmem_getpages+0x84/0x1a0 fallback_alloc+0x2a4/0x320 kmem_cache_alloc_node+0xc0/0x2e0 copy_process.isra.25+0x260/0x1b30 _do_fork+0x94/0x470 kernel_thread+0x48/0x60 kthreadd+0x264/0x330 ret_from_kernel_thread+0x5c/0xa4 Mem-Info: active_anon:0 inactive_anon:0 isolated_anon:0 active_file:0 inactive_file:0 isolated_file:0 unevictable:0 dirty:0 writeback:0 unstable:0 slab_reclaimable:5 slab_unreclaimable:73 mapped:0 shmem:0 pagetables:0 bounce:0 free:0 free_pcp:0 free_cma:0 Node 7 DMA free:0kB min:0kB low:0kB high:0kB active_anon:0kB inactive_anon:0kB active_file:0kB inactive_file:0kB unevictable:0kB isolated(anon):0kB isolated(file):0kB present:52428800kB managed:110016kB mlocked:0kB dirty:0kB writeback:0kB mapped:0kB shmem:0kB slab_reclaimable:320kB slab_unreclaimable:4672kB kernel_stack:1152kB pagetables:0kB unstable:0kB bounce:0kB free_pcp:0kB local_pcp:0kB free_cma:0kB writeback_tmp:0kB pages_scanned:0 all_unreclaimable? yes lowmem_reserve[]: 0 0 0 0 Node 7 DMA: 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB 0*4096kB 0*8192kB 0*16384kB = 0kB 0 total pagecache pages 0 pages in swap cache Swap cache stats: add 0, delete 0, find 0/0 Free swap = 0kB Total swap = 0kB 819200 pages RAM 0 pages HighMem/MovableOnly 817481 pages reserved 0 pages cma reserved 0 pages hwpoisoned the reason is that the managed memory is too low (only 110MB) while the rest of the the 50GB is still waiting for the deferred intialization to be done. update_defer_init estimates the initial memoty to initialize to 2GB at least but it doesn't consider any memory allocated in that range. In this particular case we've had Reserving 4096MB of memory at 128MB for crashkernel (System RAM: 51200MB) so the low 2GB is mostly depleted. Fix this by considering memblock allocations in the initial static initialization estimation. Move the max_initialise to reset_deferred_meminit and implement a simple memblock_reserved_memory helper which iterates all reserved blocks and sums the size of all that start below the given address. The cumulative size is than added on top of the initial estimation. This is still not ideal because reset_deferred_meminit doesn't consider holes and so reservation might be above the initial estimation whihch we ignore but let's make the logic simpler until we really need to handle more complicated cases. Fixes: 3a80a7f ("mm: meminit: initialise a subset of struct pages if CONFIG_DEFERRED_STRUCT_PAGE_INIT is set") Link: http://lkml.kernel.org/r/20170531104010.GI27783@dhcp22.suse.cz Signed-off-by: Michal Hocko <mhocko@suse.com> Acked-by: Mel Gorman <mgorman@suse.de> Tested-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com> 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 52d8b8a commit cb1fb15

4 files changed

Lines changed: 55 additions & 3 deletions

File tree

include/linux/memblock.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,20 @@ static inline void early_memtest(phys_addr_t start, phys_addr_t end)
408408
}
409409
#endif
410410

411+
extern unsigned long memblock_reserved_memory_within(phys_addr_t start_addr,
412+
phys_addr_t end_addr);
411413
#else
412414
static inline phys_addr_t memblock_alloc(phys_addr_t size, phys_addr_t align)
413415
{
414416
return 0;
415417
}
416418

419+
static inline unsigned long memblock_reserved_memory_within(phys_addr_t start_addr,
420+
phys_addr_t end_addr)
421+
{
422+
return 0;
423+
}
424+
417425
#endif /* CONFIG_HAVE_MEMBLOCK */
418426

419427
#endif /* __KERNEL__ */

include/linux/mmzone.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ 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;
691692
#endif /* CONFIG_DEFERRED_STRUCT_PAGE_INIT */
692693
} pg_data_t;
693694

mm/memblock.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,30 @@ static void __init_memblock memblock_dump(struct memblock_type *type, char *name
16341634
}
16351635
}
16361636

1637+
extern unsigned long __init_memblock
1638+
memblock_reserved_memory_within(phys_addr_t start_addr, phys_addr_t end_addr)
1639+
{
1640+
struct memblock_type *type = &memblock.reserved;
1641+
unsigned long size = 0;
1642+
int idx;
1643+
1644+
for (idx = 0; idx < type->cnt; idx++) {
1645+
struct memblock_region *rgn = &type->regions[idx];
1646+
phys_addr_t start, end;
1647+
1648+
if (rgn->base + rgn->size < start_addr)
1649+
continue;
1650+
if (rgn->base > end_addr)
1651+
continue;
1652+
1653+
start = rgn->base;
1654+
end = start + rgn->size;
1655+
size += end - start;
1656+
}
1657+
1658+
return size;
1659+
}
1660+
16371661
void __init_memblock __memblock_dump_all(void)
16381662
{
16391663
pr_info("MEMBLOCK configuration:\n");

mm/page_alloc.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,26 @@ int page_group_by_mobility_disabled __read_mostly;
269269
#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
270270
static inline void reset_deferred_meminit(pg_data_t *pgdat)
271271
{
272+
unsigned long max_initialise;
273+
unsigned long reserved_lowmem;
274+
275+
/*
276+
* Initialise at least 2G of a node but also take into account that
277+
* two large system hashes that can take up 1GB for 0.25TB/node.
278+
*/
279+
max_initialise = max(2UL << (30 - PAGE_SHIFT),
280+
(pgdat->node_spanned_pages >> 8));
281+
282+
/*
283+
* Compensate the all the memblock reservations (e.g. crash kernel)
284+
* from the initial estimation to make sure we will initialize enough
285+
* memory to boot.
286+
*/
287+
reserved_lowmem = memblock_reserved_memory_within(pgdat->node_start_pfn,
288+
pgdat->node_start_pfn + max_initialise);
289+
max_initialise += reserved_lowmem;
290+
291+
pgdat->static_init_size = min(max_initialise, pgdat->node_spanned_pages);
272292
pgdat->first_deferred_pfn = ULONG_MAX;
273293
}
274294

@@ -302,10 +322,9 @@ static inline bool update_defer_init(pg_data_t *pgdat,
302322
/* Always populate low zones for address-contrained allocations */
303323
if (zone_end < pgdat_end_pfn(pgdat))
304324
return true;
305-
306325
/* Initialise at least 2G of the highest zone */
307326
(*nr_initialised)++;
308-
if (*nr_initialised > (2UL << (30 - PAGE_SHIFT)) &&
327+
if ((*nr_initialised > pgdat->static_init_size) &&
309328
(pfn & (PAGES_PER_SECTION - 1)) == 0) {
310329
pgdat->first_deferred_pfn = pfn;
311330
return false;
@@ -5343,7 +5362,6 @@ void __paginginit free_area_init_node(int nid, unsigned long *zones_size,
53435362
/* pg_data_t should be reset to zero when it's allocated */
53445363
WARN_ON(pgdat->nr_zones || pgdat->classzone_idx);
53455364

5346-
reset_deferred_meminit(pgdat);
53475365
pgdat->node_id = nid;
53485366
pgdat->node_start_pfn = node_start_pfn;
53495367
#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
@@ -5362,6 +5380,7 @@ void __paginginit free_area_init_node(int nid, unsigned long *zones_size,
53625380
(unsigned long)pgdat->node_mem_map);
53635381
#endif
53645382

5383+
reset_deferred_meminit(pgdat);
53655384
free_area_init_core(pgdat);
53665385
}
53675386

0 commit comments

Comments
 (0)