From patchwork Tue Jul 14 12:08:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11662523 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 EC91613B4 for ; Tue, 14 Jul 2020 12:09:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B99672220D for ; Tue, 14 Jul 2020 12:09:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dO1ByTGv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B99672220D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BD1D46B0003; Tue, 14 Jul 2020 08:09:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BA9196B0005; Tue, 14 Jul 2020 08:09:01 -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 ABF278D0001; Tue, 14 Jul 2020 08:09:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0181.hostedemail.com [216.40.44.181]) by kanga.kvack.org (Postfix) with ESMTP id 967416B0003 for ; Tue, 14 Jul 2020 08:09:01 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 598561DFD for ; Tue, 14 Jul 2020 12:09:01 +0000 (UTC) X-FDA: 77036560482.14.word45_31079a726ef0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id B640818229837 for ; Tue, 14 Jul 2020 12:09:00 +0000 (UTC) X-Spam-Summary: 1,0,0,d12ae4d2770ec67b,d41d8cd98f00b204,laoar.shao@gmail.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1345:1437:1534:1541:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2553:2559:2562:2731:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3872:3874:4250:4321:4385:5007:6261:6653:7514:9203:9413:10004:11026:11658:11914:12043:12048:12296:12297:12438:12517:12519:12533:12555:12895:13069:13075:13161:13229:13311:13357:14093:14096:14181:14384:14394:14687:14721:14819:21080:21324:21444:21451:21627:21666:21990:30054:30070:30090,0,RBL:209.85.160.194:@gmail.com:.lbl8.mailshell.net-62.50.0.100 66.100.201.100;04yffopgsg56menx66y9fhyrfafn6yc71ch8kpmibc3gogui39cd6dpittnqadw.84ceqdpnxq45c57bhqehx7zwws5fjaqdqbaetmbygu8z9sjsbxzku5nonbqcxza.n-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:26,LUA_SUMMARY:none X-HE-Tag: word45_31079a726ef0 X-Filterd-Recvd-Size: 4549 Received: from mail-qt1-f194.google.com (mail-qt1-f194.google.com [209.85.160.194]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Tue, 14 Jul 2020 12:09:00 +0000 (UTC) Received: by mail-qt1-f194.google.com with SMTP id k18so12514984qtm.10 for ; Tue, 14 Jul 2020 05:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=pcndyQekX+ofF0O9rLPJFTl+G5ycc38MD2OUmgUgIOA=; b=dO1ByTGvQXqN/xS+/TQoUjQcygvFD/fkCmNoo/5GUMGKvweXGvkckkeOnjcWO3B1GM p/B0xkWpjVFsbPDuP4z0FZz9B2Wm2n8bKCnCsvDXPS0b6Uo/1VzsVrHTiuzL7Btmgj0x nY/ZLVIKX3vxUGxQm3oexqU+566SlBMB3BffMgi7cOrH0IiodL6vlQZ/cwSAEGfA20X+ 4a7hwHLfexZ/LG54DwU7j+5leo7L2RjdobAR/uTF/l0seRVWFhomYDNkwSbmDCpLn4EW KXkaYbl+UiTXtI9OstY+4OeliInD84SIeia0c0bBSTkza0EoY5ej0tYKgnapK3t+e5fG teTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pcndyQekX+ofF0O9rLPJFTl+G5ycc38MD2OUmgUgIOA=; b=Le34l9ZmidRZWpDntGMKyijpsFxoJ6zvBMPSQg5lbuLkpmwB0WO6ZQrLYnPijkArsM raoRggsgnOqN11tAONWoMxqjJDw4874zWoc8skj89mcHtm2aQdUQs5H4aBbq54HCBwKE Ir1BoVj/5x6WRTYaGdjasCjVCLo3mmIo5Mc94ZfpbnfiIFLI+twU30NY5qUBKTpOYz/3 GhAuRZ7qrsUbH33wFdh0TCFbDhGmuolBB11S5OJRNZD1m+iiCBNhMYER4M4xCAZOcEV9 Voyr4w5Oup1o/ECw7/5cs0CBMhDTY6w/B7MS7428pUslXIAePIADGi54xCSJf5rkcsXN UbfA== X-Gm-Message-State: AOAM531vSH2iwhctYJ+JUwYC75sSqu5g4LdePGa/tNdthP/Qeqgzqohd M8sfp92qI4sc5XV4KeFq+gM= X-Google-Smtp-Source: ABdhPJxBQflc2tdV08JjkPDpwWSCzFn0KnOk5uVFKNJ7jnMWIZ6sHpDB0Z9Ke7YU0LWjihsYZzxyBQ== X-Received: by 2002:ac8:7b57:: with SMTP id m23mr4133806qtu.379.1594728539757; Tue, 14 Jul 2020 05:08:59 -0700 (PDT) Received: from dev.localdomain ([183.134.211.52]) by smtp.gmail.com with ESMTPSA id r22sm22067865qke.34.2020.07.14.05.08.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Jul 2020 05:08:59 -0700 (PDT) From: Yafang Shao To: mhocko@kernel.org, penguin-kernel@i-love.sakura.ne.jp, rientjes@google.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Yafang Shao Subject: [PATCH] mm, oom: check memcg margin for parallel oom Date: Tue, 14 Jul 2020 08:08:32 -0400 Message-Id: <1594728512-18969-1-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-Rspamd-Queue-Id: B640818229837 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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: The commit 7775face2079 ("memcg: killed threads should not invoke memcg OOM killer") resolves the problem that different threads in a multi-threaded task doing parallel memcg oom, but it doesn't solve the problem that different tasks doing parallel memcg oom. It may happens that many different tasks in the same memcg are waiting oom_lock at the same time, if one of them has already made progress and freed enough available memory, the others don't need to trigger the oom killer again. By checking memcg margin after hold oom_lock can help achieve it. Suggested-by: Michal Hocko Signed-off-by: Yafang Shao Cc: Michal Hocko Cc: Tetsuo Handa Cc: David Rientjes --- mm/memcontrol.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 1962232..df141e1 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1560,16 +1560,31 @@ static bool mem_cgroup_out_of_memory(struct mem_cgroup *memcg, gfp_t gfp_mask, .gfp_mask = gfp_mask, .order = order, }; - bool ret; + bool ret = true; if (mutex_lock_killable(&oom_lock)) return true; + /* * A few threads which were not waiting at mutex_lock_killable() can * fail to bail out. Therefore, check again after holding oom_lock. */ - ret = should_force_charge() || out_of_memory(&oc); + if (should_force_charge()) + goto out; + + /* + * Different tasks may be doing parallel oom, so after hold the + * oom_lock the task should check the memcg margin again to check + * whether other task has already made progress. + */ + if (mem_cgroup_margin(memcg) >= (1 << order)) + goto out; + + ret = out_of_memory(&oc); + +out: mutex_unlock(&oom_lock); + return ret; }