Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp256737pxa; Wed, 26 Aug 2020 09:45:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxZaV2p/TF33cSFFtyz1HW82BDPDxDwlYHK0rSTyuuhWuwWhfOBe2uXR4fTHMJ0bETpjR3n X-Received: by 2002:a17:906:c001:: with SMTP id e1mr17467487ejz.390.1598460353327; Wed, 26 Aug 2020 09:45:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598460353; cv=none; d=google.com; s=arc-20160816; b=qzjW0hS++qtKwwaoWG2uwbI9cK+vB72cXa1CZV5A4al4uAbjj6QWyUgmF8JitPvYw/ iDNZRnmHhHDk8s8sz3xz+w7vVCQ54430PbR2eMcbUVScePesc5U/k9g+/8iJxe6f4oxy I3vvy2spshoTwd31H6UPxxMVSz3jb/KpHxTfYvHcRECbsp0jNcGJ7kxD9/zDWXVFQk55 2UZu0KH0D/EAZSE2yqY2XOXoiM+6GWu11caiJSCziwrDvXg9/0JXuiPynudMyoIB8Fa0 SbqtsIf8iyOaTZm9iCePndt6uA7O1iRxOxHwRQ7LhdSv1tc15VGpsYYGbKnI8XhqXhXB OGbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=JMlIvAM6M5w9dD2eayY13lUR07MsoMvR9kGoMcT+/Vc=; b=fPU94mYAtj4ETQ2Cdc8xrZgi9LisGVQGgoqWxUX4Om2xT16BdNex2X6mIXoQKpxfA6 CjACZeTLIrJljuVVE8JeWfcUY2xJcXtlZr6oKIDmcIw+QEYOveZnjUni3tq/vlt9j7Ib LfClzfrjJqMDuXaiA3bKJtZCq+qgXBxnmupsR3G9vAIkzLfFEXpxnI27ImTiBgssktEs Ssbl40BBKuTjoobQaTz3GN4HDb/O4+ygIKexhT9XK9fz/lqkda1uYXQYTmFE4lzzLwzZ q1YYlPYc7rhH2bMQ0cPJxc11uLm61alycrQDOMr2q5M8kDo/ICUfbsu2GU1uevjlYyx5 nVCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=sa4INENi; 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=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t7si196754edt.107.2020.08.26.09.45.30; Wed, 26 Aug 2020 09:45:53 -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; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=sa4INENi; 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=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727080AbgHZQow (ORCPT + 99 others); Wed, 26 Aug 2020 12:44:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726820AbgHZQot (ORCPT ); Wed, 26 Aug 2020 12:44:49 -0400 Received: from mail-qv1-xf41.google.com (mail-qv1-xf41.google.com [IPv6:2607:f8b0:4864:20::f41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FED4C061574 for ; Wed, 26 Aug 2020 09:44:48 -0700 (PDT) Received: by mail-qv1-xf41.google.com with SMTP id x7so1021754qvi.5 for ; Wed, 26 Aug 2020 09:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=JMlIvAM6M5w9dD2eayY13lUR07MsoMvR9kGoMcT+/Vc=; b=sa4INENi9XADKc047/PpGSBs9OMWCrJoNYxa3t1qJ5P2krTtixPAqQnLcE52OIziLw CFk5ZjD/kvInASBoNghbOcXThF4viWJW1YQOOJvmsGWxWaTYxn0Yz147rbv4xMi2KWgN QbHm9FRDrpY3hXjAreEdCaIct/hfd7Q7eeMU7JHLXeKAR27Slz8XOGnkxa8/MREG7eEb jMNB0qKlQvnHrOO2WVvHSjzDNvjVs25xHHGWlMZ3mv/mzhNPpsci2lPogBR2ObtwkxC1 gYjfNoBmaN3A/oZ6ddcGThYGqYbBWB3wmmsBWYUa4lIHN8vxzknbzsar8iqHuLfGWEEY o3Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=JMlIvAM6M5w9dD2eayY13lUR07MsoMvR9kGoMcT+/Vc=; b=NiCOLvWfWU5BhABTtZAg6ljSe2f5BfsdEhh4VlbbwWzH4eSpCOFl7zR7QRJW0m1XSL GQY+8DAcjzVox7Z3DlWb7G05kY0sYzIwB+SdKrWbmE0TtbM6oMKX0PVfEhDecl7xI/Vg 2yD0yNmxorxm1wGapST+qBRRFo+7uXCU0uFPReNcmFlbqB/v4rqg74WAkYIWQ7YDOx/L yuNCkfSQU5KNZJI4wkK7K+tMP8n/MOZ5ZaTTWV1c/ZTInf6nCSMAGit5ptEe4ik8rJRR eyNylFjs0t15J8fcAM0aH2J31bSbXDWDQi2Vk+4EqKbrxyq+4/hx8NuAdEwvakJCFy/M oINQ== X-Gm-Message-State: AOAM531aHOdOpltYsIWxovSyRF5m5VF762i2Y8TKpfMGQvHP+Qu+XsZJ Q8tvjaSrvRCUIcxQjkWZMy2XOw== X-Received: by 2002:a0c:fbd1:: with SMTP id n17mr15033373qvp.4.1598460287847; Wed, 26 Aug 2020 09:44:47 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:412a]) by smtp.gmail.com with ESMTPSA id 73sm2396864qtf.74.2020.08.26.09.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2020 09:44:47 -0700 (PDT) Date: Wed, 26 Aug 2020 12:43:32 -0400 From: Johannes Weiner To: Xunlei Pang Cc: Michal Hocko , Andrew Morton , Vladimir Davydov , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v2] mm: memcg: Fix memcg reclaim soft lockup Message-ID: <20200826164332.GB995045@cmpxchg.org> References: <1598449622-108748-1-git-send-email-xlpang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1598449622-108748-1-git-send-email-xlpang@linux.alibaba.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 26, 2020 at 09:47:02PM +0800, Xunlei Pang wrote: > 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 This generally makes sense to me but really should have a comment: /* * This loop can become CPU-bound when there are thousands * of cgroups that aren't eligible for reclaim - either * because they don't have any pages, or because their * memory is explicitly protected. Avoid soft lockups. */ cond_resched(); The placement in the middle of the multi-part protection checks is a bit odd too. It would be better to have it either at the top of the loop, or at the end, by replacing the continues with goto next.