From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF297C43461 for ; Wed, 9 Sep 2020 17:59:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 11D2E21D46 for ; Wed, 9 Sep 2020 17:59:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 11D2E21D46 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3B3196B005D; Wed, 9 Sep 2020 13:59:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3645D8E0003; Wed, 9 Sep 2020 13:59:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A08C6B0074; Wed, 9 Sep 2020 13:59:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 154826B005D for ; Wed, 9 Sep 2020 13:59:49 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id BFA7F180AD802 for ; Wed, 9 Sep 2020 17:59:48 +0000 (UTC) X-FDA: 77244286056.08.drain87_3b12edf270df Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 967441819E76C for ; Wed, 9 Sep 2020 17:59:48 +0000 (UTC) X-HE-Tag: drain87_3b12edf270df X-Filterd-Recvd-Size: 4998 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Wed, 9 Sep 2020 17:59:47 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 5822FAD20; Wed, 9 Sep 2020 18:00:02 +0000 (UTC) Subject: Re: [PATCH v2] mm/vmscan: fix infinite loop in drop_slab_node To: zangchunxin@bytedance.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song References: <20200909152047.27905-1-zangchunxin@bytedance.com> From: Vlastimil Babka Message-ID: <16906d44-9e3c-76a1-f1a9-ced61e865467@suse.cz> Date: Wed, 9 Sep 2020 19:59:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <20200909152047.27905-1-zangchunxin@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Rspamd-Queue-Id: 967441819E76C X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 Content-Transfer-Encoding: quoted-printable 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: On 9/9/20 5:20 PM, zangchunxin@bytedance.com wrote: > From: Chunxin Zang >=20 > On our server, there are about 10k memcg in one machine. They use memor= y > very frequently. When I tigger drop caches=EF=BC=8Cthe process will inf= inite loop > in drop_slab_node. >=20 > There are two reasons: > 1.We have too many memcgs, even though one object freed in one memcg, t= he > sum of object is bigger than 10. >=20 > 2.We spend a lot of time in traverse memcg once. So, the memcg who > traversed at the first have been freed many objects. Traverse memcg n= ext > time, the freed count bigger than 10 again. >=20 > We can get the following info through 'ps': >=20 > root:~# ps -aux | grep drop > root 357956 ... R Aug25 21119854:55 echo 3 > /proc/sys/vm/drop_ca= ches > root 1771385 ... R Aug16 21146421:17 echo 3 > /proc/sys/vm/drop_ca= ches > root 1986319 ... R 18:56 117:27 echo 3 > /proc/sys/vm/drop_caches > root 2002148 ... R Aug24 5720:39 echo 3 > /proc/sys/vm/drop_caches > root 2564666 ... R 18:59 113:58 echo 3 > /proc/sys/vm/drop_caches > root 2639347 ... R Sep03 2383:39 echo 3 > /proc/sys/vm/drop_caches > root 3904747 ... R 03:35 993:31 echo 3 > /proc/sys/vm/drop_caches > root 4016780 ... R Aug21 7882:18 echo 3 > /proc/sys/vm/drop_caches >=20 > Use bpftrace follow 'freed' value in drop_slab_node: >=20 > root:~# bpftrace -e 'kprobe:drop_slab_node+70 {@ret=3Dhist(reg("bp"))= ; }' > Attaching 1 probe... > ^B^C >=20 > @ret: > [64, 128) 1 | = | > [128, 256) 28 | = | > [256, 512) 107 |@ = | > [512, 1K) 298 |@@@ = | > [1K, 2K) 613 |@@@@@@@ = | > [2K, 4K) 4435 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@= @@@| > [4K, 8K) 442 |@@@@@ = | > [8K, 16K) 299 |@@@ = | > [16K, 32K) 100 |@ = | > [32K, 64K) 139 |@ = | > [64K, 128K) 56 | = | > [128K, 256K) 26 | = | > [256K, 512K) 2 | = | >=20 > In the while loop, we can check whether the TASK_KILLABLE signal is set= , > if so, we should break the loop. That's definitely a good change, thanks. I would just maybe consider: - Test in the memcg iteration loop? If you have 10k memcgs as you mention= , this can still take long until the test happens? - Exit also on other signals such as SIGABRT, SIGTERM? If I write to drop= _caches and think it's too long, I would prefer to kill it by ctrl-c and not just= kill -9. Dunno if the canonical way of testing for this is if (signal_pending(current)) or differently. - IMHO it's still worth to bail out in your scenario even without a signa= l, e.g. by the doubling of threshold. But it can be a separate patch. Thanks! > Signed-off-by: Chunxin Zang > Signed-off-by: Muchun Song > --- > changelogs in v2:=20 > 1) Via check TASK_KILLABLE signal break loop. >=20 > mm/vmscan.c | 3 +++ > 1 file changed, 3 insertions(+) >=20 > diff --git a/mm/vmscan.c b/mm/vmscan.c > index b6d84326bdf2..c3ed8b45d264 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -704,6 +704,9 @@ void drop_slab_node(int nid) > do { > struct mem_cgroup *memcg =3D NULL; > =20 > + if (fatal_signal_pending(current)) > + return; > + > freed =3D 0; > memcg =3D mem_cgroup_iter(NULL, NULL, NULL); > do { >=20