Skip to content

Commit

Permalink
mm, show_mem: suppress page counts in non-blockable contexts
Browse files Browse the repository at this point in the history
On large systems with a lot of memory, walking all RAM to determine page
types may take a half second or even more.

In non-blockable contexts, the page allocator will emit a page allocation
failure warning unless __GFP_NOWARN is specified.  In such contexts, irqs
are typically disabled and such a lengthy delay may even result in NMI
watchdog timeouts.

To fix this, suppress the page walk in such contexts when printing the
page allocation failure warning.

Signed-off-by: David Rientjes <[email protected]>
Cc: Mel Gorman <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Dave Hansen <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
rientjes authored and torvalds committed Apr 29, 2013
1 parent fe0bfaa commit 4b59e6c
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions arch/arm/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ void show_mem(unsigned int filter)
printk("Mem-info:\n");
show_free_areas(filter);

if (filter & SHOW_MEM_FILTER_PAGE_COUNT)
return;

for_each_bank (i, mi) {
struct membank *bank = &mi->bank[i];
unsigned int pfn1, pfn2;
Expand Down
2 changes: 2 additions & 0 deletions arch/ia64/mm/contig.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void show_mem(unsigned int filter)
printk(KERN_INFO "Mem-info:\n");
show_free_areas(filter);
printk(KERN_INFO "Node memory in pages:\n");
if (filter & SHOW_MEM_FILTER_PAGE_COUNT)
return;
for_each_online_pgdat(pgdat) {
unsigned long present;
unsigned long flags;
Expand Down
2 changes: 2 additions & 0 deletions arch/ia64/mm/discontig.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ void show_mem(unsigned int filter)

printk(KERN_INFO "Mem-info:\n");
show_free_areas(filter);
if (filter & SHOW_MEM_FILTER_PAGE_COUNT)
return;
printk(KERN_INFO "Node memory in pages:\n");
for_each_online_pgdat(pgdat) {
unsigned long present;
Expand Down
2 changes: 2 additions & 0 deletions arch/parisc/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ void show_mem(unsigned int filter)

printk(KERN_INFO "Mem-info:\n");
show_free_areas(filter);
if (filter & SHOW_MEM_FILTER_PAGE_COUNT)
return;
#ifndef CONFIG_DISCONTIGMEM
i = max_mapnr;
while (i-- > 0) {
Expand Down
3 changes: 3 additions & 0 deletions arch/unicore32/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ void show_mem(unsigned int filter)
printk(KERN_DEFAULT "Mem-info:\n");
show_free_areas(filter);

if (filter & SHOW_MEM_FILTER_PAGE_COUNT)
return;

for_each_bank(i, mi) {
struct membank *bank = &mi->bank[i];
unsigned int pfn1, pfn2;
Expand Down
3 changes: 2 additions & 1 deletion include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,8 @@ extern void pagefault_out_of_memory(void);
* Flags passed to show_mem() and show_free_areas() to suppress output in
* various contexts.
*/
#define SHOW_MEM_FILTER_NODES (0x0001u) /* filter disallowed nodes */
#define SHOW_MEM_FILTER_NODES (0x0001u) /* disallowed nodes */
#define SHOW_MEM_FILTER_PAGE_COUNT (0x0002u) /* page type count */

extern void show_free_areas(unsigned int flags);
extern bool skip_free_areas_node(unsigned int flags, int nid);
Expand Down
3 changes: 3 additions & 0 deletions lib/show_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ void show_mem(unsigned int filter)
printk("Mem-Info:\n");
show_free_areas(filter);

if (filter & SHOW_MEM_FILTER_PAGE_COUNT)
return;

for_each_online_pgdat(pgdat) {
unsigned long i, flags;

Expand Down
7 changes: 7 additions & 0 deletions mm/page_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2002,6 +2002,13 @@ void warn_alloc_failed(gfp_t gfp_mask, int order, const char *fmt, ...)
debug_guardpage_minorder() > 0)
return;

/*
* Walking all memory to count page types is very expensive and should
* be inhibited in non-blockable contexts.
*/
if (!(gfp_mask & __GFP_WAIT))
filter |= SHOW_MEM_FILTER_PAGE_COUNT;

/*
* This documents exceptions given to allocations in certain
* contexts that are allowed to allocate outside current's set
Expand Down

0 comments on commit 4b59e6c

Please sign in to comment.