linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: page_alloc: unreserve highatomic page blocks before oom
@ 2023-10-30 12:39 Charan Teja Kalla
  2023-10-31  7:53 ` Pavan Kondeti
  2023-10-31  8:14 ` Michal Hocko
  0 siblings, 2 replies; 8+ messages in thread
From: Charan Teja Kalla @ 2023-10-30 12:39 UTC (permalink / raw)
  To: akpm, mgorman, mhocko, david, vbabka
  Cc: linux-mm, linux-kernel, Charan Teja Kalla

__alloc_pages_direct_reclaim() is called from slowpath allocation where
high atomic reserves can be unreserved after there is a progress in
reclaim and yet no suitable page is found. Later should_reclaim_retry()
gets called from slow path allocation to decide if the reclaim needs to
be retried before OOM kill path is taken.

should_reclaim_retry() checks the available(reclaimable + free pages)
memory against the min wmark levels of a zone and returns:
a)  true, if it is above the min wmark so that slow path allocation will
do the reclaim retries.
b) false, thus slowpath allocation takes oom kill path.

should_reclaim_retry() can also unreserves the high atomic reserves
**but only after all the reclaim retries are exhausted.**

In a case where there are almost none reclaimable memory and free pages
contains mostly the high atomic reserves but allocation context can't
use these high atomic reserves, makes the available memory below min
wmark levels hence false is returned from should_reclaim_retry() leading
the allocation request to take OOM kill path. This is an early oom kill
because high atomic reserves are holding lot of free memory and 
unreserving of them is not attempted.

(early)OOM is encountered on a machine in the below state(excerpt from
the oom kill logs):
[  295.998653] Normal free:7728kB boost:0kB min:804kB low:1004kB
high:1204kB reserved_highatomic:8192KB active_anon:4kB inactive_anon:0kB
active_file:24kB inactive_file:24kB unevictable:1220kB writepending:0kB
present:70732kB managed:49224kB mlocked:0kB bounce:0kB free_pcp:688kB
local_pcp:492kB free_cma:0kB
[  295.998656] lowmem_reserve[]: 0 32
[  295.998659] Normal: 508*4kB (UMEH) 241*8kB (UMEH) 143*16kB (UMEH)
33*32kB (UH) 7*64kB (UH) 0*128kB 0*256kB 0*512kB 0*1024kB 0*2048kB
0*4096kB = 7752kB

Per above log, the free memory of ~7MB exist in the high atomic
reserves is not freed up before falling back to oom kill path.

This fix includes unreserving these atomic reserves in the OOM path
before going for a kill. The side effect of unreserving in oom kill path
is that these free pages are checked against the high wmark. If
unreserved from should_reclaim_retry()/__alloc_pages_direct_reclaim(),
they are checked against the min wmark levels.

Signed-off-by: Charan Teja Kalla <quic_charante@quicinc.com>
---
 mm/page_alloc.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index 95546f3..2a2536d 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -3281,6 +3281,8 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
 		.order = order,
 	};
 	struct page *page;
+	struct zone *zone;
+	struct zoneref *z;
 
 	*did_some_progress = 0;
 
@@ -3295,6 +3297,16 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
 	}
 
 	/*
+	 * If should_reclaim_retry() encounters a state where:
+	 * reclaimable + free doesn't satisfy the wmark levels,
+	 * it can directly jump to OOM without even unreserving
+	 * the highatomic page blocks. Try them for once here
+	 * before jumping to OOM.
+	 */
+retry:
+	unreserve_highatomic_pageblock(ac, true);
+
+	/*
 	 * Go through the zonelist yet one more time, keep very high watermark
 	 * here, this is only to catch a parallel oom killing, we must fail if
 	 * we're still under heavy pressure. But make sure that this reclaim
@@ -3307,6 +3319,12 @@ __alloc_pages_may_oom(gfp_t gfp_mask, unsigned int order,
 	if (page)
 		goto out;
 
+	for_each_zone_zonelist_nodemask(zone, z, ac->zonelist, ac->highest_zoneidx,
+								ac->nodemask) {
+		if (zone->nr_reserved_highatomic > 0)
+			goto retry;
+	}
+
 	/* Coredumps can quickly deplete all memory reserves */
 	if (current->flags & PF_DUMPCORE)
 		goto out;
-- 
2.7.4



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-11-01  9:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-30 12:39 [PATCH] mm: page_alloc: unreserve highatomic page blocks before oom Charan Teja Kalla
2023-10-31  7:53 ` Pavan Kondeti
2023-10-31  8:14 ` Michal Hocko
2023-10-31 13:13   ` Charan Teja Kalla
2023-10-31 13:43     ` Michal Hocko
2023-11-01  6:46     ` Pavan Kondeti
2023-11-01  6:53       ` Charan Teja Kalla
2023-11-01  9:41         ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox