Skip to content

Commit b37f1dd

Browse files
Mel Gormantorvalds
authored andcommitted
mm: introduce __GFP_MEMALLOC to allow access to emergency reserves
__GFP_MEMALLOC will allow the allocation to disregard the watermarks, much like PF_MEMALLOC. It allows one to pass along the memalloc state in object related allocation flags as opposed to task related flags, such as sk->sk_allocation. This removes the need for ALLOC_PFMEMALLOC as callers using __GFP_MEMALLOC can get the ALLOC_NO_WATERMARK flag which is now enough to identify allocations related to page reclaim. Signed-off-by: Peter Zijlstra <[email protected]> Signed-off-by: Mel Gorman <[email protected]> Cc: David Miller <[email protected]> Cc: Neil Brown <[email protected]> Cc: Mike Christie <[email protected]> Cc: Eric B Munson <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Sebastian Andrzej Siewior <[email protected]> Cc: Mel Gorman <[email protected]> Cc: Christoph Lameter <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 5091b74 commit b37f1dd

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

include/linux/gfp.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct vm_area_struct;
2323
#define ___GFP_REPEAT 0x400u
2424
#define ___GFP_NOFAIL 0x800u
2525
#define ___GFP_NORETRY 0x1000u
26+
#define ___GFP_MEMALLOC 0x2000u
2627
#define ___GFP_COMP 0x4000u
2728
#define ___GFP_ZERO 0x8000u
2829
#define ___GFP_NOMEMALLOC 0x10000u
@@ -76,9 +77,14 @@ struct vm_area_struct;
7677
#define __GFP_REPEAT ((__force gfp_t)___GFP_REPEAT) /* See above */
7778
#define __GFP_NOFAIL ((__force gfp_t)___GFP_NOFAIL) /* See above */
7879
#define __GFP_NORETRY ((__force gfp_t)___GFP_NORETRY) /* See above */
80+
#define __GFP_MEMALLOC ((__force gfp_t)___GFP_MEMALLOC)/* Allow access to emergency reserves */
7981
#define __GFP_COMP ((__force gfp_t)___GFP_COMP) /* Add compound page metadata */
8082
#define __GFP_ZERO ((__force gfp_t)___GFP_ZERO) /* Return zeroed page on success */
81-
#define __GFP_NOMEMALLOC ((__force gfp_t)___GFP_NOMEMALLOC) /* Don't use emergency reserves */
83+
#define __GFP_NOMEMALLOC ((__force gfp_t)___GFP_NOMEMALLOC) /* Don't use emergency reserves.
84+
* This takes precedence over the
85+
* __GFP_MEMALLOC flag if both are
86+
* set
87+
*/
8288
#define __GFP_HARDWALL ((__force gfp_t)___GFP_HARDWALL) /* Enforce hardwall cpuset memory allocs */
8389
#define __GFP_THISNODE ((__force gfp_t)___GFP_THISNODE)/* No fallback, no policies */
8490
#define __GFP_RECLAIMABLE ((__force gfp_t)___GFP_RECLAIMABLE) /* Page is reclaimable */
@@ -129,7 +135,7 @@ struct vm_area_struct;
129135
/* Control page allocator reclaim behavior */
130136
#define GFP_RECLAIM_MASK (__GFP_WAIT|__GFP_HIGH|__GFP_IO|__GFP_FS|\
131137
__GFP_NOWARN|__GFP_REPEAT|__GFP_NOFAIL|\
132-
__GFP_NORETRY|__GFP_NOMEMALLOC)
138+
__GFP_NORETRY|__GFP_MEMALLOC|__GFP_NOMEMALLOC)
133139

134140
/* Control slab gfp mask during early boot */
135141
#define GFP_BOOT_MASK (__GFP_BITS_MASK & ~(__GFP_WAIT|__GFP_IO|__GFP_FS))

include/linux/mm_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct page {
5555
pgoff_t index; /* Our offset within mapping. */
5656
void *freelist; /* slub/slob first free object */
5757
bool pfmemalloc; /* If set by the page allocator,
58-
* ALLOC_PFMEMALLOC was set
58+
* ALLOC_NO_WATERMARKS was set
5959
* and the low watermark was not
6060
* met implying that the system
6161
* is under some pressure. The

include/trace/events/gfpflags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
{(unsigned long)__GFP_COMP, "GFP_COMP"}, \
3131
{(unsigned long)__GFP_ZERO, "GFP_ZERO"}, \
3232
{(unsigned long)__GFP_NOMEMALLOC, "GFP_NOMEMALLOC"}, \
33+
{(unsigned long)__GFP_MEMALLOC, "GFP_MEMALLOC"}, \
3334
{(unsigned long)__GFP_HARDWALL, "GFP_HARDWALL"}, \
3435
{(unsigned long)__GFP_THISNODE, "GFP_THISNODE"}, \
3536
{(unsigned long)__GFP_RECLAIMABLE, "GFP_RECLAIMABLE"}, \

mm/page_alloc.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,6 @@ struct page *buffered_rmqueue(struct zone *preferred_zone,
15131513
#define ALLOC_HARDER 0x10 /* try to alloc harder */
15141514
#define ALLOC_HIGH 0x20 /* __GFP_HIGH set */
15151515
#define ALLOC_CPUSET 0x40 /* check for correct cpuset */
1516-
#define ALLOC_PFMEMALLOC 0x80 /* Caller has PF_MEMALLOC set */
15171516

15181517
#ifdef CONFIG_FAIL_PAGE_ALLOC
15191518

@@ -2294,11 +2293,10 @@ gfp_to_alloc_flags(gfp_t gfp_mask)
22942293
} else if (unlikely(rt_task(current)) && !in_interrupt())
22952294
alloc_flags |= ALLOC_HARDER;
22962295

2297-
if ((current->flags & PF_MEMALLOC) ||
2298-
unlikely(test_thread_flag(TIF_MEMDIE))) {
2299-
alloc_flags |= ALLOC_PFMEMALLOC;
2300-
2301-
if (likely(!(gfp_mask & __GFP_NOMEMALLOC)) && !in_interrupt())
2296+
if (likely(!(gfp_mask & __GFP_NOMEMALLOC))) {
2297+
if (gfp_mask & __GFP_MEMALLOC)
2298+
alloc_flags |= ALLOC_NO_WATERMARKS;
2299+
else if (likely(!(gfp_mask & __GFP_NOMEMALLOC)) && !in_interrupt())
23022300
alloc_flags |= ALLOC_NO_WATERMARKS;
23032301
}
23042302

@@ -2307,7 +2305,7 @@ gfp_to_alloc_flags(gfp_t gfp_mask)
23072305

23082306
bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
23092307
{
2310-
return !!(gfp_to_alloc_flags(gfp_mask) & ALLOC_PFMEMALLOC);
2308+
return !!(gfp_to_alloc_flags(gfp_mask) & ALLOC_NO_WATERMARKS);
23112309
}
23122310

23132311
static inline struct page *
@@ -2498,12 +2496,12 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
24982496
return page;
24992497
got_pg:
25002498
/*
2501-
* page->pfmemalloc is set when the caller had PFMEMALLOC set or is
2502-
* been OOM killed. The expectation is that the caller is taking
2503-
* steps that will free more memory. The caller should avoid the
2504-
* page being used for !PFMEMALLOC purposes.
2499+
* page->pfmemalloc is set when the caller had PFMEMALLOC set, is
2500+
* been OOM killed or specified __GFP_MEMALLOC. The expectation is
2501+
* that the caller is taking steps that will free more memory. The
2502+
* caller should avoid the page being used for !PFMEMALLOC purposes.
25052503
*/
2506-
page->pfmemalloc = !!(alloc_flags & ALLOC_PFMEMALLOC);
2504+
page->pfmemalloc = !!(alloc_flags & ALLOC_NO_WATERMARKS);
25072505

25082506
if (kmemcheck_enabled)
25092507
kmemcheck_pagealloc_alloc(page, order, gfp_mask);

mm/slab.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ static void *kmem_getpages(struct kmem_cache *cachep, gfp_t flags, int nodeid)
18841884
return NULL;
18851885
}
18861886

1887-
/* Record if ALLOC_PFMEMALLOC was set when allocating the slab */
1887+
/* Record if ALLOC_NO_WATERMARKS was set when allocating the slab */
18881888
if (unlikely(page->pfmemalloc))
18891889
pfmemalloc_active = true;
18901890

0 commit comments

Comments
 (0)