From patchwork Sat Apr 18 15:13:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 11496603 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 A652781 for ; Sat, 18 Apr 2020 15:13:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 695C92223C for ; Sat, 18 Apr 2020 15:13:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OJ516pfF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 695C92223C 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 65B498E0005; Sat, 18 Apr 2020 11:13:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 60BF18E0003; Sat, 18 Apr 2020 11:13:29 -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 548E48E0005; Sat, 18 Apr 2020 11:13:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id 3B02B8E0003 for ; Sat, 18 Apr 2020 11:13:29 -0400 (EDT) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id EEC5D52C7 for ; Sat, 18 Apr 2020 15:13:28 +0000 (UTC) X-FDA: 76721319696.24.basin19_75aea20568a0b X-Spam-Summary: 2,0,0,27f8a6601cfaf1f5,d41d8cd98f00b204,laoar.shao@gmail.com,,RULES_HIT:41:69:355:379:541:973:988:989:1260:1345:1437:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:4321:4605:5007:6261:6653:7903:9121:9413:10004:11026:11658:11914:12043:12048:12291:12297:12438:12517:12519:12555:12679:12683:12895:12986:13069:13161:13229:13311:13357:14096:14181:14384:14394:14664:14687:14721:14819:21080:21324:21444:21451:21627:21666:21990:30054:30070,0,RBL:209.85.214.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:none,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: basin19_75aea20568a0b X-Filterd-Recvd-Size: 4406 Received: from mail-pl1-f194.google.com (mail-pl1-f194.google.com [209.85.214.194]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Sat, 18 Apr 2020 15:13:28 +0000 (UTC) Received: by mail-pl1-f194.google.com with SMTP id t16so2154414plo.7 for ; Sat, 18 Apr 2020 08:13:28 -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=JbhXqo4Pzw+3vU65jqKk/Fx3gGljRODErS133jaXDtc=; b=OJ516pfFZ9wqcckJQo0cAd5hvs4jllbYqK4+UxGRjpLUC+T+xq9mAOMrePQCaZSiOX vNP//tqMzFHnRaunP+0c8vfIGArkrq5d/wHDmoQ1Yd5CWqOtzHmH+sR6558Xc3cIoAJU J2wulRNHBKJKtE9kB3ARZoVy6hewqbEy7CJT+5sGOuV5nyUg+7OAqpmUdjboRAcCS6FM tTe7UFK5BuNnWoUrjL2Xile+BBoKW1/QmDorNWvQFTqWRA7NYytGgWiUtZsjLvQjq8F5 mowl0+Zhw91A4SwfEHBj0KdNZGSGNDAJHjYPUA2kZXu5+Hf9VK9de2J3brkUjPfoxBjT svXA== 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=JbhXqo4Pzw+3vU65jqKk/Fx3gGljRODErS133jaXDtc=; b=sX6akklpzH3rz5ccMdiOCpL27xr7ECNX5UV1gDe/AXoRtbWBMMjd635CfsBP30Uurt CR9BsYy1aqQslp3IZkGXK/uEDqOfUjAkAEfFmpcA1Nynv/uTb0JxF0fgQeCnL92zz/W0 zf4ynT1yRbfQ8SZewiJYy4sR8DZ4yfcL66eLBnU7A52UJw+CCOWtaS2RpePEFfHJXq9F XypkCC3J2kGf7uQmpq5pBE4EpsblZD4r7AXzvjE4oxJptJccNlGv59prcOV9nzAdWqVN Rn8YqAtiYM1DxsTiki1u72vtBUUOtsUSy3Q9w6gXqOm72zozymVObC5Q4zhp1BcBFktf GLxQ== X-Gm-Message-State: AGi0PuaPlvH8JO/9HXo5RpHhxCQf58SmCwpNDFbgaOaR9vy7hN3os38k p6dmbroD9SSlxOWZ8RImlhI= X-Google-Smtp-Source: APiQypKC9P+5aSnUx92AdXqRiXgkRIpzpVRKVCi2GNHcwAPsRu2cEpiNpxuRLTPZiFQARAMzfqiF6w== X-Received: by 2002:a17:90a:ce02:: with SMTP id f2mr11047333pju.144.1587222807724; Sat, 18 Apr 2020 08:13:27 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id j32sm9613028pgb.55.2020.04.18.08.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Apr 2020 08:13:26 -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 0/3] memcg oom: bail out from the charge path if no victim found Date: Sat, 18 Apr 2020 11:13:08 -0400 Message-Id: <20200418151311.7397-1-laoar.shao@gmail.com> X-Mailer: git-send-email 2.18.1 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: Without considering the manually triggered OOM, if no victim found in system OOM, the system will be deadlocked on memory, however if no victim found in memcg OOM, it can charge successfully and runs well. This behavior in memcg oom is not proper because that can prevent the memcg from being limited. Take an easy example. $ cd /sys/fs/cgroup/foo/ $ echo $$ > cgroup.procs $ echo 200M > memory.max $ cat memory.max 209715200 $ echo -1000 > /proc/$$/oom_score_adj Then, let's run a memhog task in memcg foo, which will allocate 1G memory and keeps running. $ /home/yafang/test/memhog & Then memory.current will be greater than memory.max. Run bellow command in another shell. $ cat /sys/fs/cgroup/foo/memory.current 1097228288 The tasks which have already allocated memory and won't allocate new memory still runs well. This behavior makes nonsense. This patch is to improve it. If no victim found in memcg oom, we should force the current task to wait until there's available pages. That is similar with the behavior in memcg1 when oom_kill_disable is set. Patch #1 and #2 are the preparation of patch #3. Yafang Shao (3): mm: change the return type of out_of_memory() mm, memcg: introduce a new helper task_in_memcg_oom_set() memcg oom: bail out from the charge path if no victim found include/linux/memcontrol.h | 30 ++++++++++++++++++ include/linux/oom.h | 9 +++++- include/linux/sched.h | 1 + mm/memcontrol.c | 63 ++++++++++++++++++++------------------ mm/oom_kill.c | 36 +++++++++++++++++----- mm/page_alloc.c | 3 +- 6 files changed, 104 insertions(+), 38 deletions(-)