From patchwork Sat Apr 18 15:13:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11496607 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 E46816CA for ; Sat, 18 Apr 2020 15:13:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B19852076A for ; Sat, 18 Apr 2020 15:13:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F19MROdL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B19852076A 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 E4C1F8E0007; Sat, 18 Apr 2020 11:13:39 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DFB9F8E0003; Sat, 18 Apr 2020 11:13:39 -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 D38908E0007; Sat, 18 Apr 2020 11:13:39 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0129.hostedemail.com [216.40.44.129]) by kanga.kvack.org (Postfix) with ESMTP id BDAAF8E0003 for ; Sat, 18 Apr 2020 11:13:39 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 69E34181AEF30 for ; Sat, 18 Apr 2020 15:13:39 +0000 (UTC) X-FDA: 76721320158.30.eggs86_7730b0a800341 X-Spam-Summary: 2,0,0,a9f4ab79c23ae4a2,d41d8cd98f00b204,laoar.shao@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1345:1359:1437:1535:1542:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2693:2731:3138:3139:3140:3141:3142:3353:3865:3867:3868:3870:3871:3872:3874:4321:4605:5007:6261:6653:7514:9413:9592:10004:11026:11658:11914:12043:12048:12114:12291:12296:12297:12438:12517:12519:12555:12895:12986:14096:14181:14394:14687:14721:21080:21324:21444:21451:21627:21666:21990:30054,0,RBL:209.85.210.194:@gmail.com:.lbl8.mailshell.net-62.50.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: eggs86_7730b0a800341 X-Filterd-Recvd-Size: 5255 Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Sat, 18 Apr 2020 15:13:38 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id g30so2624937pfr.3 for ; Sat, 18 Apr 2020 08:13:38 -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:in-reply-to:references; bh=wjmCBOEfzqW0cnWbfi1j4+3Gc0dBrwK/JfJg9kdoLoo=; b=F19MROdL9nDqzx8p/pTE5VVVG6XlqGG2qlaVqfWrEo0i/3Nu0OD8AHQZJcKTctnG4W EqT+bzJx5TS4vdJivpj14sCy8pBlfRGGxkM4dxHBg5jZf2kSpZZZEQZzcul5o0nRk+Vj BcTWqA//7EN/gj57BUW7GUO+skSgDkMLqpA3bDxXGtfSAS0t1DJ/WcsCdTahYH/AFTWO uOq0deuW3iIJzP29YkMCEkoPUYCO9K1hRxii5Z9sniEGMOO8ZfFDCEa5dsyYloNGzwFr NtU7WAvRI7Wrkip5vh+UbrVvFVrkWk9Y3TcRbT8g5Xg+X3kA7UF/CurPKZ6mIQNI3LGg IWSQ== 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:in-reply-to :references; bh=wjmCBOEfzqW0cnWbfi1j4+3Gc0dBrwK/JfJg9kdoLoo=; b=RF6zUEIdTjlmOi6mdxzphM4z8jqVyMRi1S6W52m6LGnsm11ik9EAiOLpT6Z4lBQjrs xryc6HxStGfQvMToIATZhzvYJ7Wrk5KQS/oV4Ve5WhPkWGCljR67jnbf7eKqnB2h+To9 u8VI4TEzGCAY27tFY0AW+FU1n65rU2W5F/yhpHGCcSoOKW9FUNk30oH/tSBmVUGXTFEL KI2A1AAz/NRndSi6Cpp28mg0xW03Tlwr4WeBMdMrKHoBec8NJDTwGMTVOn431GRWlbbb i2D/ElzHCoBwvKRM36nviqAVXWQ7NCK+RQQomhm7nvAOm8muDaEvzdmUYtRRGwxblX9q c8xQ== X-Gm-Message-State: AGi0PubtakQwDr582bF1HmcIg0tiGgpFnrY9MYel1nQ1LwU9Bi2tYWp/ qjPyHgmVyTJFSbWD8YWiivY= X-Google-Smtp-Source: APiQypJABOuzzbrqt3TJLfEQ3bEMTLs0C224RdypiUg6zJtjyMNNwOKGHIs3l1rCtH9ak2kXsSnFiQ== X-Received: by 2002:a65:498f:: with SMTP id r15mr8279109pgs.345.1587222817757; Sat, 18 Apr 2020 08:13:37 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id j32sm9613028pgb.55.2020.04.18.08.13.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Apr 2020 08:13:37 -0700 (PDT) From: Yafang Shao To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Yafang Shao Subject: [PATCH 2/3] mm, memcg: introduce a new helper task_in_memcg_oom_set() Date: Sat, 18 Apr 2020 11:13:10 -0400 Message-Id: <20200418151311.7397-3-laoar.shao@gmail.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20200418151311.7397-1-laoar.shao@gmail.com> References: <20200418151311.7397-1-laoar.shao@gmail.com> 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: A new helper task_in_memcg_oom_set() is introduced for later use. It will be used to bail out from the charge path if no victim can be found in memcg oom. Signed-off-by: Yafang Shao --- include/linux/memcontrol.h | 25 +++++++++++++++++++++++++ mm/memcontrol.c | 12 ++---------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 98bd8fb2f5c7..767bac135787 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -565,6 +565,23 @@ static inline bool task_in_memcg_oom(struct task_struct *p) return p->memcg_in_oom; } +/* Bail out from the charge path if no victim found in memcg oom */ +static inline enum oom_status task_in_memcg_oom_set(struct task_struct *p, + struct mem_cgroup *memcg, + gfp_t mask, + int order) +{ + if (!current->in_user_fault) + return OOM_SKIPPED; + + css_get(&memcg->css); + p->memcg_in_oom = memcg; + p->memcg_oom_gfp_mask = mask; + p->memcg_oom_order = order; + + return OOM_ASYNC; +} + bool mem_cgroup_oom_synchronize(bool wait); struct mem_cgroup *mem_cgroup_get_oom_group(struct task_struct *victim, struct mem_cgroup *oom_domain); @@ -1031,6 +1048,14 @@ static inline bool task_in_memcg_oom(struct task_struct *p) return false; } +static inline enum oom_status task_in_memcg_oom_set(struct task_struct *p, + struct mem_cgroup *memcg, + gfp_t mask, + int order) +{ + return OOM_SUCCESS; +} + static inline bool mem_cgroup_oom_synchronize(bool wait) { return false; diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 22418b55804f..d6cb1b786045 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1800,16 +1800,8 @@ static enum oom_status mem_cgroup_oom(struct mem_cgroup *memcg, gfp_t mask, int * Please note that mem_cgroup_out_of_memory might fail to find a * victim and then we have to bail out from the charge path. */ - if (memcg->oom_kill_disable) { - if (!current->in_user_fault) - return OOM_SKIPPED; - css_get(&memcg->css); - current->memcg_in_oom = memcg; - current->memcg_oom_gfp_mask = mask; - current->memcg_oom_order = order; - - return OOM_ASYNC; - } + if (memcg->oom_kill_disable) + return task_in_memcg_oom_set(current, memcg, mask, order); mem_cgroup_mark_under_oom(memcg);