From patchwork Wed Aug 26 07:27:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xunlei Pang X-Patchwork-Id: 11737541 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 665CC13B6 for ; Wed, 26 Aug 2020 07:27:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2666820825 for ; Wed, 26 Aug 2020 07:27:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2666820825 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 322686B0003; Wed, 26 Aug 2020 03:27:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2D1086B0005; Wed, 26 Aug 2020 03:27:58 -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 1E7156B0006; Wed, 26 Aug 2020 03:27:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0130.hostedemail.com [216.40.44.130]) by kanga.kvack.org (Postfix) with ESMTP id 066EF6B0003 for ; Wed, 26 Aug 2020 03:27:58 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id B75B01DE1 for ; Wed, 26 Aug 2020 07:27:57 +0000 (UTC) X-FDA: 77191890594.30.comb72_0400e1827062 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 795F8180B3C83 for ; Wed, 26 Aug 2020 07:27:57 +0000 (UTC) X-Spam-Summary: 1,0,0,2274431842a8bb52,d41d8cd98f00b204,xlpang@linux.alibaba.com,,RULES_HIT:41:355:379:541:960:966:973:988:989:1260:1261:1345:1437:1534:1541:1711:1730:1747:1777:1792:2196:2199:2393:2553:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3867:3870:3872:4385:5007:6261:8660:9038:10004:11026:11473:11658:11914:12043:12048:12295:12296:12297:12438:12555:12679:12895:13069:13148:13161:13229:13230:13311:13357:14181:14384:14394:14721:21080:21451:21627:21939:30054:30056:30090,0,RBL:115.124.30.56:@linux.alibaba.com:.lbl8.mailshell.net-62.20.2.100 64.201.201.201;04yrfqzmphfdotzc16msoe6d7ony5ycht68occm9ajf4hbgxpy6g1dgebr8jux8.7ne7xwajd9hxkce5kw6y81yfs4ue1784uppb7i17b1cqer8rat8ufpmymjukg7d.4-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:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: comb72_0400e1827062 X-Filterd-Recvd-Size: 2834 Received: from out30-56.freemail.mail.aliyun.com (out30-56.freemail.mail.aliyun.com [115.124.30.56]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Wed, 26 Aug 2020 07:27:51 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R921e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01355;MF=xlpang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0U6u0vBE_1598426822; Received: from localhost(mailfrom:xlpang@linux.alibaba.com fp:SMTPD_---0U6u0vBE_1598426822) by smtp.aliyun-inc.com(127.0.0.1); Wed, 26 Aug 2020 15:27:40 +0800 From: Xunlei Pang To: Johannes Weiner , Michal Hocko , Andrew Morton , Vladimir Davydov Cc: Xunlei Pang , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mm: memcg: Fix memcg reclaim soft lockup Date: Wed, 26 Aug 2020 15:27:02 +0800 Message-Id: <1598426822-93737-1-git-send-email-xlpang@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 X-Rspamd-Queue-Id: 795F8180B3C83 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000034, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We've met softlockup with "CONFIG_PREEMPT_NONE=y", when the target memcg doesn't have any reclaimable memory. It can be easily reproduced as below: watchdog: BUG: soft lockup - CPU#0 stuck for 111s![memcg_test:2204] CPU: 0 PID: 2204 Comm: memcg_test Not tainted 5.9.0-rc2+ #12 Call Trace: shrink_lruvec+0x49f/0x640 shrink_node+0x2a6/0x6f0 do_try_to_free_pages+0xe9/0x3e0 try_to_free_mem_cgroup_pages+0xef/0x1f0 try_charge+0x2c1/0x750 mem_cgroup_charge+0xd7/0x240 __add_to_page_cache_locked+0x2fd/0x370 add_to_page_cache_lru+0x4a/0xc0 pagecache_get_page+0x10b/0x2f0 filemap_fault+0x661/0xad0 ext4_filemap_fault+0x2c/0x40 __do_fault+0x4d/0xf9 handle_mm_fault+0x1080/0x1790 It only happens on our 1-vcpu instances, because there's no chance for oom reaper to run to reclaim the to-be-killed process. Add cond_resched() in such cases at the beginning of shrink_lruvec() to give up the cpu to others. Signed-off-by: Xunlei Pang --- mm/vmscan.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index 99e1796..349a88e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2449,6 +2449,12 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) scan_adjusted = (!cgroup_reclaim(sc) && !current_is_kswapd() && sc->priority == DEF_PRIORITY); + /* memcg reclaim may run into no reclaimable lru pages */ + if (nr[LRU_ACTIVE_FILE] == 0 && + nr[LRU_INACTIVE_FILE] == 0 && + nr[LRU_INACTIVE_ANON] == 0) + cond_resched(); + blk_start_plug(&plug); while (nr[LRU_INACTIVE_ANON] || nr[LRU_ACTIVE_FILE] || nr[LRU_INACTIVE_FILE]) {