Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp135411pxa; Wed, 26 Aug 2020 06:49:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6LwVTo0KFyHnHGZ5UtXq0yAXUFc7cfqkR0HSrHPdDF8LF2L33dYesZJwKpAPM5fdqua+5 X-Received: by 2002:a17:906:c1d8:: with SMTP id bw24mr15530197ejb.91.1598449796107; Wed, 26 Aug 2020 06:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598449796; cv=none; d=google.com; s=arc-20160816; b=MS/ye3wM21vEbeD49KcV8FlNYxTQksJe0aLokD2VxmOMlu0oOiS+aweDGIloJ5nN4n pbOZhUbJKV+QDvYhIhfOP0VsnAwEtaXzPTgudlnivVAYG1MsxtTWRi6DLFjioNjBKh4R ZqmKzxWq0q7dqJFG/w69JXke/uiHhXCDGSvOntJ0ArODBz6iyLNT/WWgiYPWay/c/AIG HXJQNSPqXaxRLP68aoZi9P8kYXqaWtltcZ9SKqOVNTniL3unvbUTBy3ggiYYPZ1yQUJw a1jiSdKyAKx4Fgrcb7aYA2O2Fqsug8VrUVrhpqDfA5TQEZYL3D6Zj1irjZitto6Bex4c gwMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=Kw4ff1J7D0KCKDhk1ug7B4RzBnjO29r1wYhjn0juNp8=; b=NbZjGWdn4ao9YbYrt9oTBuZknqfA5lMjblD9JM3K6Nam4U9iKoMAnD2ZXTTjbfAJEh 5T7+ngxMbx0m8i6FUuH+Oi2UiO64LpAsNbeV0NHXu7y69l8d02rWzV4h2CYynYf+wh3u eUPioQTvDtsTnBzO1KPQlanHX5tAs1uVMKKaWsvLhlnG74eJrxwk5gcTV+oWNRYispUo X+v9K9qfO3xlFDn/zCWzh1qmIl+Tyimmz3+ATCZ+2GA5el4eNfEkzP3aG3/plEf3OWqW Us/WlRP3Jv9uOyBPV6z+Z9UHVA3pEJSlaj3BxTy68DVkFsiDdly/ORgDr/rKQLmKqZvI 9Evw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx11si1548634edb.300.2020.08.26.06.49.32; Wed, 26 Aug 2020 06:49:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730405AbgHZNsK (ORCPT + 99 others); Wed, 26 Aug 2020 09:48:10 -0400 Received: from out30-44.freemail.mail.aliyun.com ([115.124.30.44]:35963 "EHLO out30-44.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730426AbgHZNrK (ORCPT ); Wed, 26 Aug 2020 09:47:10 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R411e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07488;MF=xlpang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0U6wHc3g_1598449622; Received: from localhost(mailfrom:xlpang@linux.alibaba.com fp:SMTPD_---0U6wHc3g_1598449622) by smtp.aliyun-inc.com(127.0.0.1); Wed, 26 Aug 2020 21:47:07 +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 v2] mm: memcg: Fix memcg reclaim soft lockup Date: Wed, 26 Aug 2020 21:47:02 +0800 Message-Id: <1598449622-108748-1-git-send-email-xlpang@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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() at the upper shrink_node_memcgs() to solve this issue, and any other possible issue like meomry.min protection. Suggested-by: Michal Hocko Signed-off-by: Xunlei Pang --- mm/vmscan.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index 99e1796..bbdc38b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2617,6 +2617,8 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc) mem_cgroup_calculate_protection(target_memcg, memcg); + cond_resched(); + if (mem_cgroup_below_min(memcg)) { /* * Hard protection. -- 1.8.3.1