Skip to content

Commit cfd19c5

Browse files
Mel Gormantorvalds
authored andcommitted
mm: only set page->pfmemalloc when ALLOC_NO_WATERMARKS was used
__alloc_pages_slowpath() is called when the number of free pages is below the low watermark. If the caller is entitled to use ALLOC_NO_WATERMARKS then the page will be marked page->pfmemalloc. This protects more pages than are strictly necessary as we only need to protect pages allocated below the min watermark (the pfmemalloc reserves). This patch only sets page->pfmemalloc when ALLOC_NO_WATERMARKS was required to allocate the page. [[email protected]: David noticed the problem during review] Signed-off-by: Mel Gorman <[email protected]> Cc: David Miller <[email protected]> Cc: Neil Brown <[email protected]> Cc: Peter Zijlstra <[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 907aed4 commit cfd19c5

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

mm/page_alloc.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,8 +2116,8 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,
21162116

21172117
page = get_page_from_freelist(gfp_mask, nodemask,
21182118
order, zonelist, high_zoneidx,
2119-
alloc_flags, preferred_zone,
2120-
migratetype);
2119+
alloc_flags & ~ALLOC_NO_WATERMARKS,
2120+
preferred_zone, migratetype);
21212121
if (page) {
21222122
preferred_zone->compact_considered = 0;
21232123
preferred_zone->compact_defer_shift = 0;
@@ -2209,8 +2209,8 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order,
22092209
retry:
22102210
page = get_page_from_freelist(gfp_mask, nodemask, order,
22112211
zonelist, high_zoneidx,
2212-
alloc_flags, preferred_zone,
2213-
migratetype);
2212+
alloc_flags & ~ALLOC_NO_WATERMARKS,
2213+
preferred_zone, migratetype);
22142214

22152215
/*
22162216
* If an allocation failed after direct reclaim, it could be because
@@ -2381,8 +2381,17 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
23812381
page = __alloc_pages_high_priority(gfp_mask, order,
23822382
zonelist, high_zoneidx, nodemask,
23832383
preferred_zone, migratetype);
2384-
if (page)
2384+
if (page) {
2385+
/*
2386+
* page->pfmemalloc is set when ALLOC_NO_WATERMARKS was
2387+
* necessary to allocate the page. The expectation is
2388+
* that the caller is taking steps that will free more
2389+
* memory. The caller should avoid the page being used
2390+
* for !PFMEMALLOC purposes.
2391+
*/
2392+
page->pfmemalloc = true;
23852393
goto got_pg;
2394+
}
23862395
}
23872396

23882397
/* Atomic allocations - we can't balance anything */
@@ -2499,14 +2508,6 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
24992508
warn_alloc_failed(gfp_mask, order, NULL);
25002509
return page;
25012510
got_pg:
2502-
/*
2503-
* page->pfmemalloc is set when the caller had PFMEMALLOC set, is
2504-
* been OOM killed or specified __GFP_MEMALLOC. The expectation is
2505-
* that the caller is taking steps that will free more memory. The
2506-
* caller should avoid the page being used for !PFMEMALLOC purposes.
2507-
*/
2508-
page->pfmemalloc = !!(alloc_flags & ALLOC_NO_WATERMARKS);
2509-
25102511
if (kmemcheck_enabled)
25112512
kmemcheck_pagealloc_alloc(page, order, gfp_mask);
25122513

0 commit comments

Comments
 (0)