Skip to content

Commit 7877cdc

Browse files
Michal Hockotorvalds
authored andcommitted
mm: consolidate warn_alloc_failed users
warn_alloc_failed is currently used from the page and vmalloc allocators. This is a good reuse of the code except that vmalloc would appreciate a slightly different warning message. This is already handled by the fmt parameter except that "%s: page allocation failure: order:%u, mode:%#x(%pGg)" is printed anyway. This might be quite misleading because it might be a vmalloc failure which leads to the warning while the page allocator is not the culprit here. Fix this by always using the fmt string and only print the context that makes sense for the particular context (e.g. order makes only very little sense for the vmalloc context). Rename the function to not miss any user and also because a later patch will reuse it also for !failure cases. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Michal Hocko <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Cc: Tetsuo Handa <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Dave Hansen <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent c2a9737 commit 7877cdc

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

include/linux/mm.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1916,9 +1916,8 @@ extern void si_meminfo_node(struct sysinfo *val, int nid);
19161916
extern unsigned long arch_reserved_kernel_pages(void);
19171917
#endif
19181918

1919-
extern __printf(3, 4)
1920-
void warn_alloc_failed(gfp_t gfp_mask, unsigned int order,
1921-
const char *fmt, ...);
1919+
extern __printf(2, 3)
1920+
void warn_alloc(gfp_t gfp_mask, const char *fmt, ...);
19221921

19231922
extern void setup_per_cpu_pageset(void);
19241923

mm/page_alloc.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2979,9 +2979,11 @@ static DEFINE_RATELIMIT_STATE(nopage_rs,
29792979
DEFAULT_RATELIMIT_INTERVAL,
29802980
DEFAULT_RATELIMIT_BURST);
29812981

2982-
void warn_alloc_failed(gfp_t gfp_mask, unsigned int order, const char *fmt, ...)
2982+
void warn_alloc(gfp_t gfp_mask, const char *fmt, ...)
29832983
{
29842984
unsigned int filter = SHOW_MEM_FILTER_NODES;
2985+
struct va_format vaf;
2986+
va_list args;
29852987

29862988
if ((gfp_mask & __GFP_NOWARN) || !__ratelimit(&nopage_rs) ||
29872989
debug_guardpage_minorder() > 0)
@@ -2999,22 +3001,16 @@ void warn_alloc_failed(gfp_t gfp_mask, unsigned int order, const char *fmt, ...)
29993001
if (in_interrupt() || !(gfp_mask & __GFP_DIRECT_RECLAIM))
30003002
filter &= ~SHOW_MEM_FILTER_NODES;
30013003

3002-
if (fmt) {
3003-
struct va_format vaf;
3004-
va_list args;
3004+
pr_warn("%s: ", current->comm);
30053005

3006-
va_start(args, fmt);
3006+
va_start(args, fmt);
3007+
vaf.fmt = fmt;
3008+
vaf.va = &args;
3009+
pr_cont("%pV", &vaf);
3010+
va_end(args);
30073011

3008-
vaf.fmt = fmt;
3009-
vaf.va = &args;
3012+
pr_cont(", mode:%#x(%pGg)\n", gfp_mask, &gfp_mask);
30103013

3011-
pr_warn("%pV", &vaf);
3012-
3013-
va_end(args);
3014-
}
3015-
3016-
pr_warn("%s: page allocation failure: order:%u, mode:%#x(%pGg)\n",
3017-
current->comm, order, gfp_mask, &gfp_mask);
30183014
dump_stack();
30193015
if (!should_suppress_show_mem())
30203016
show_mem(filter);
@@ -3680,7 +3676,8 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
36803676
}
36813677

36823678
nopage:
3683-
warn_alloc_failed(gfp_mask, order, NULL);
3679+
warn_alloc(gfp_mask,
3680+
"page allocation failure: order:%u", order);
36843681
got_pg:
36853682
return page;
36863683
}

mm/vmalloc.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,7 +1601,6 @@ static void *__vmalloc_node(unsigned long size, unsigned long align,
16011601
static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
16021602
pgprot_t prot, int node)
16031603
{
1604-
const int order = 0;
16051604
struct page **pages;
16061605
unsigned int nr_pages, array_size, i;
16071606
const gfp_t nested_gfp = (gfp_mask & GFP_RECLAIM_MASK) | __GFP_ZERO;
@@ -1629,9 +1628,9 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
16291628
struct page *page;
16301629

16311630
if (node == NUMA_NO_NODE)
1632-
page = alloc_pages(alloc_mask, order);
1631+
page = alloc_page(alloc_mask);
16331632
else
1634-
page = alloc_pages_node(node, alloc_mask, order);
1633+
page = alloc_pages_node(node, alloc_mask, 0);
16351634

16361635
if (unlikely(!page)) {
16371636
/* Successfully allocated i pages, free them in __vunmap() */
@@ -1648,8 +1647,8 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
16481647
return area->addr;
16491648

16501649
fail:
1651-
warn_alloc_failed(gfp_mask, order,
1652-
"vmalloc: allocation failure, allocated %ld of %ld bytes\n",
1650+
warn_alloc(gfp_mask,
1651+
"vmalloc: allocation failure, allocated %ld of %ld bytes",
16531652
(area->nr_pages*PAGE_SIZE), area->size);
16541653
vfree(area->addr);
16551654
return NULL;
@@ -1710,9 +1709,8 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
17101709
return addr;
17111710

17121711
fail:
1713-
warn_alloc_failed(gfp_mask, 0,
1714-
"vmalloc: allocation failure: %lu bytes\n",
1715-
real_size);
1712+
warn_alloc(gfp_mask,
1713+
"vmalloc: allocation failure: %lu bytes", real_size);
17161714
return NULL;
17171715
}
17181716

0 commit comments

Comments
 (0)