Skip to content

Commit c928807

Browse files
Yu Zhaoakpm00
authored andcommitted
mm/page_alloc: keep track of free highatomic
OOM kills due to vastly overestimated free highatomic reserves were observed: ... invoked oom-killer: gfp_mask=0x100cca(GFP_HIGHUSER_MOVABLE), order=0 ... Node 0 Normal free:1482936kB boost:0kB min:410416kB low:739404kB high:1068392kB reserved_highatomic:1073152KB ... Node 0 Normal: 1292*4kB (ME) 1920*8kB (E) 383*16kB (UE) 220*32kB (ME) 340*64kB (E) 2155*128kB (UE) 3243*256kB (UE) 615*512kB (U) 1*1024kB (M) 0*2048kB 0*4096kB = 1477408kB The second line above shows that the OOM kill was due to the following condition: free (1482936kB) - reserved_highatomic (1073152kB) = 409784KB < min (410416kB) And the third line shows there were no free pages in any MIGRATE_HIGHATOMIC pageblocks, which otherwise would show up as type 'H'. Therefore __zone_watermark_unusable_free() underestimated the usable free memory by over 1GB, which resulted in the unnecessary OOM kill above. The comments in __zone_watermark_unusable_free() warns about the potential risk, i.e., If the caller does not have rights to reserves below the min watermark then subtract the high-atomic reserves. This will over-estimate the size of the atomic reserve but it avoids a search. However, it is possible to keep track of free pages in reserved highatomic pageblocks with a new per-zone counter nr_free_highatomic protected by the zone lock, to avoid a search when calculating the usable free memory. And the cost would be minimal, i.e., simple arithmetics in the highatomic alloc/free/move paths. Note that since nr_free_highatomic can be relatively small, using a per-cpu counter might cause too much drift and defeat its purpose, in addition to the extra memory overhead. Dependson e0932b6 ("mm: page_alloc: consolidate free page accounting") - see [1] [[email protected]: s/if/else if/, per Johannes, stealth whitespace tweak] Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] [1] Fixes: 0aaa29a ("mm, page_alloc: reserve pageblocks for high-order atomic allocations on demand") Signed-off-by: Yu Zhao <[email protected]> Reported-by: Link Lin <[email protected]> Acked-by: David Rientjes <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Acked-by: Johannes Weiner <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 5de1950 commit c928807

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

include/linux/mmzone.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ struct zone {
823823
unsigned long watermark_boost;
824824

825825
unsigned long nr_reserved_highatomic;
826+
unsigned long nr_free_highatomic;
826827

827828
/*
828829
* We don't know if the memory that we're going to allocate will be

mm/page_alloc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,18 @@ compaction_capture(struct capture_control *capc, struct page *page,
635635
static inline void account_freepages(struct zone *zone, int nr_pages,
636636
int migratetype)
637637
{
638+
lockdep_assert_held(&zone->lock);
639+
638640
if (is_migrate_isolate(migratetype))
639641
return;
640642

641643
__mod_zone_page_state(zone, NR_FREE_PAGES, nr_pages);
642644

643645
if (is_migrate_cma(migratetype))
644646
__mod_zone_page_state(zone, NR_FREE_CMA_PAGES, nr_pages);
647+
else if (is_migrate_highatomic(migratetype))
648+
WRITE_ONCE(zone->nr_free_highatomic,
649+
zone->nr_free_highatomic + nr_pages);
645650
}
646651

647652
/* Used for pages not on another list */
@@ -3079,11 +3084,10 @@ static inline long __zone_watermark_unusable_free(struct zone *z,
30793084

30803085
/*
30813086
* If the caller does not have rights to reserves below the min
3082-
* watermark then subtract the high-atomic reserves. This will
3083-
* over-estimate the size of the atomic reserve but it avoids a search.
3087+
* watermark then subtract the free pages reserved for highatomic.
30843088
*/
30853089
if (likely(!(alloc_flags & ALLOC_RESERVES)))
3086-
unusable_free += z->nr_reserved_highatomic;
3090+
unusable_free += READ_ONCE(z->nr_free_highatomic);
30873091

30883092
#ifdef CONFIG_CMA
30893093
/* If allocation can't use CMA areas don't use free CMA pages */

0 commit comments

Comments
 (0)