From patchwork Fri Apr 24 20:48:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Rientjes X-Patchwork-Id: 11509383 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E97092A for ; Fri, 24 Apr 2020 20:48:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3EAF82168B for ; Fri, 24 Apr 2020 20:48:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KPy7wj2M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EAF82168B Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 58B4E8E0005; Fri, 24 Apr 2020 16:48:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 514C98E0003; Fri, 24 Apr 2020 16:48:09 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DD928E0005; Fri, 24 Apr 2020 16:48:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0151.hostedemail.com [216.40.44.151]) by kanga.kvack.org (Postfix) with ESMTP id 1F02D8E0003 for ; Fri, 24 Apr 2020 16:48:09 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id CF19C180AD80F for ; Fri, 24 Apr 2020 20:48:08 +0000 (UTC) X-FDA: 76743935856.25.kitty59_29fa83c525e35 X-Spam-Summary: 2,0,0,f0cb1bafb089f5a3,d41d8cd98f00b204,rientjes@google.com,,RULES_HIT:41:355:379:800:960:966:968:973:988:989:1260:1277:1313:1314:1345:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:2693:2731:2898:2912:3138:3139:3140:3141:3142:3152:3355:3865:3866:3867:3868:3870:3871:3872:3874:4117:4321:4385:5007:6261:6653:10004:10400:10450:10455:11026:11473:11658:11914:12043:12294:12296:12297:12438:12517:12519:12555:12895:12986:13439:13869:13870:14093:14096:14097:14181:14659:14721:14819:19904:19999:21063:21080:21324:21433:21444:21451:21524:21627:21740:21771:21795:30005:30034:30051:30054:30070,0,RBL:209.85.210.196:@google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: kitty59_29fa83c525e35 X-Filterd-Recvd-Size: 6314 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by imf22.hostedemail.com (Postfix) with ESMTP for ; Fri, 24 Apr 2020 20:48:08 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id v63so5369008pfb.10 for ; Fri, 24 Apr 2020 13:48:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=PDTf+FwCag54Gix+XkZ+brAEDzVD747g0MZvcGy7XE0=; b=KPy7wj2MyP0KtwiHu32IxKWS9Qes02e9yin3KAala4NLgMm1VYdrAdwr8R5QkeoAax AV6XDCiajWl6bZojse0RsWdjHKVDx/QTxgsCtwI3f9jEAAE3qq2pzTryQ9Fu54fb2eWZ sAelmXTpQT+moDBXTrFrFjpIeNnGkF2gnhsexFwJufG4FMRsjy4aoBIMZfzgB4RTYRN6 uggAlfgC8WxPk5l1ZYSZdq40lfLyB+I+UsQ5FkIdcokI4sPvMZrrsovt90fmPTN5K2UV xQkKBLGA4zKXHilVWKPH14a6fAvJEM+hZhklmeX8y3qiqakYNpmE97QZFLPYgiy889vo iInw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=PDTf+FwCag54Gix+XkZ+brAEDzVD747g0MZvcGy7XE0=; b=Gvn2Gr/1UNSIzTlbMeRLlwfjU9yrUUHwe+UQsoMoWCQUZpJXR7xismgc2cYu0ZjulP IixMqzrhfk9ET5rZz3Te0Zcj/mitf0Jjc6turqIo/8zrZWlHcNSPnLf113tBG7OE4v0O +eHkG123L2hAThAt/GPiprbY8hWpuZdcj5G/qTCqsvk08MgB7/G7Q4mu/4cqRN5AL8pS KetsKDV7SRJBtuSg3kx7SCWOfF/ok7bFzNi8MncoE7ShzPJe3b/872hXZ0f+chjEIB6b 2QcXj6fcu0ZU/KNYoOkei/FeIpLU1M1Tl8oA8YSLRK7CyNztvBNX4py3FePeC1ruSZMp gKSw== X-Gm-Message-State: AGi0Puap2eEo0SFIUld9f1QzSAlRnY69Umo3bul49WIfAtIpIV01r21N ZUAWywFVB1WsHCdv6Nl8hXLV6g== X-Google-Smtp-Source: APiQypLbr3SMUctOMl8jKy4C36Pwrcoy0esZlXUBcjNAytAVSV5T3V1sQHTQBWvGQsaOgghOVd6afA== X-Received: by 2002:a63:ed50:: with SMTP id m16mr3271084pgk.271.1587761287198; Fri, 24 Apr 2020 13:48:07 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id 139sm2494798pfc.170.2020.04.24.13.48.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Apr 2020 13:48:06 -0700 (PDT) Date: Fri, 24 Apr 2020 13:48:06 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Andrew Morton cc: Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [patch] mm, oom: stop reclaiming if GFP_ATOMIC will start failing soon Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If GFP_ATOMIC allocations will start failing soon because the amount of free memory is substantially under per-zone min watermarks, it is better to oom kill a process rather than continue to reclaim. This intends to significantly reduce the number of page allocation failures that are encountered when the demands of user and atomic allocations overwhelm the ability of reclaim to keep up. We can see this with a high ingress of networking traffic where memory allocated in irq context can overwhelm the ability to reclaim fast enough such that user memory consistently loops. In that case, we have reclaimable memory, and reclaiming is successful, but we've fully depleted memory reserves that are allowed for non-blockable allocations. Commit 400e22499dd9 ("mm: don't warn about allocations which stall for too long") removed evidence of user allocations stalling because of this, but the situation can apply anytime we get "page allocation failures" where reclaim is happening but per-zone min watermarks are starved: Node 0 Normal free:87356kB min:221984kB low:416984kB high:611984kB active_anon:123009936kB inactive_anon:67647652kB active_file:429612kB inactive_file:209980kB unevictable:112348kB writepending:260kB present:198180864kB managed:195027624kB mlocked:81756kB kernel_stack:24040kB pagetables:11460kB bounce:0kB free_pcp:940kB local_pcp:96kB free_cma:0kB lowmem_reserve[]: 0 0 0 0 Node 1 Normal free:105616kB min:225568kB low:423716kB high:621864kB active_anon:122124196kB inactive_anon:74112696kB active_file:39172kB inactive_file:103696kB unevictable:204480kB writepending:180kB present:201326592kB managed:198174372kB mlocked:204480kB kernel_stack:11328kB pagetables:3680kB bounce:0kB free_pcp:1140kB local_pcp:0kB free_cma:0kB lowmem_reserve[]: 0 0 0 0 Without this patch, there is no guarantee that user memory allocations will ever be successful when non-blockable allocations overwhelm the ability to get above per-zone min watermarks. This doesn't solve page allocation failures entirely since it's a preemptive measure based on watermarks that requires concurrent blockable allocations to trigger the oom kill. To complete solve page allocation failures, it would be possible to do the same watermark check for non- blockable allocations and then queue a worker to asynchronously oom kill if it finds watermarks to be sufficiently low as well. Signed-off-by: David Rientjes --- mm/page_alloc.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4372,11 +4372,21 @@ should_reclaim_retry(gfp_t gfp_mask, unsigned order, ac->nodemask) { unsigned long available; unsigned long reclaimable; + unsigned long free; unsigned long min_wmark = min_wmark_pages(zone); bool wmark; + free = zone_page_state_snapshot(zone, NR_FREE_PAGES); + /* + * If this zone is approaching the point where even order-0 + * GFP_ATOMIC allocations will fail, stop considering reclaim. + */ + if (!__zone_watermark_ok(zone, 0, min_wmark, ac_classzone_idx(ac), + alloc_flags | ALLOC_HIGH, free)) + continue; + available = reclaimable = zone_reclaimable_pages(zone); - available += zone_page_state_snapshot(zone, NR_FREE_PAGES); + available += free; /* * Would the allocation succeed if we reclaimed all