Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3294249pxk; Mon, 21 Sep 2020 09:54:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCL90zHiPqHihex/dnffT/ukSU7yoIlg323Oun+DHQBLnwZTWqVneeH1ckdXGpvPxELcxe X-Received: by 2002:aa7:ce97:: with SMTP id y23mr618771edv.128.1600707290110; Mon, 21 Sep 2020 09:54:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600707290; cv=none; d=google.com; s=arc-20160816; b=Y0iYTKurBiADtyQ44jvhnwpO8ZFdWy99QozCwKm0vjvPB9PSSV1oDYPhVrvkYdo4V/ shkNwop+ArWZ8D9EdVTd2D0R9Ghxpbmpaf6vwo2sSjNVd8F2VKGYsprooI/qFdoYsx32 Hns1mK6yI11sQDWeojpeRLjd6LNGaRmFzSlE/8+DbqZjo7pn4MFQ0HWNlEcpmGbasTYO hwOlFGEi7++W7Gbn4GrcYDnxVm/7vSk19MRCykIIHy6KY5ruPGtuooKuWPFtkjLGXjQ7 vJPaLqbHc+/lePVYWp2+GrBqva0P0XXeepcNsNVwxVgpIzmBo/gutWTNB6K/VbIAWM/f vJdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yY07ky5AYhNu4dpZZPj9OT2CAT02qFXYh7bI8/38cHQ=; b=GVZ9zulq5X9Vc+9MHR9qwSYAIuWdT/Bm1nBE+ELfje0cXwDN/u48qb61tREJJeYWVe Ixkc4LKEEOoE5OdE2QXQRgkQYk3Xd09z8yo8EP+9VFxkRb7VP55BUOE02Gnc0t69/e/L v5lI0T0r0L6BXOs2enqeqo2hv9gHzZl0mig9UCajg3vbpsbl++CZ2sLXXvefFZ3fkTfM wt7yOHp4xZ5860SUO7EaPODTPZecBEnZZvFKEt0zYgLHlfrUpoWf+CVmMBC3VIaQ44Tf TnueO+kIqw8dxyhlnuBEFwh47H3DRIfLnDhxmgJFTpbhIeBaD7E9R4ZSe6pFBgBCkwTL qUUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RPHbx9Pn; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w4si8547259ede.468.2020.09.21.09.54.26; Mon, 21 Sep 2020 09:54:50 -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=@kernel.org header.s=default header.b=RPHbx9Pn; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730046AbgIUQx3 (ORCPT + 99 others); Mon, 21 Sep 2020 12:53:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:54364 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729089AbgIUQr3 (ORCPT ); Mon, 21 Sep 2020 12:47:29 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A900220874; Mon, 21 Sep 2020 16:47:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600706848; bh=7qjXt93LqJLtIYJoIL/cVsDmkkZU509KBhIGTT13k6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RPHbx9PnYJvQerDca+fNsqK9z26k3l8xwVyoUSiJjFl3tu8aXXGyPt1QX1boabonC 5aFGi/YsuqpGOzz+c47VmmoOzmg2rbZF0QXm/qy5VQYQUM28crEhQoyHs2GKYkBGQf z9gdE4zl9wNc/iq69VZl08BeyX0a4hFc6lHJbTck= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Hocko , Xunlei Pang , Andrew Morton , Chris Down , Johannes Weiner , Linus Torvalds , Julius Hemanth Pitti Subject: [PATCH 5.8 117/118] mm: memcg: fix memcg reclaim soft lockup Date: Mon, 21 Sep 2020 18:28:49 +0200 Message-Id: <20200921162041.829915522@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200921162036.324813383@linuxfoundation.org> References: <20200921162036.324813383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xunlei Pang commit e3336cab2579012b1e72b5265adf98e2d6e244ad upstream. 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 a cond_resched() at the upper shrink_node_memcgs() to solve this issue, this will mean that we will get a scheduling point for each memcg in the reclaimed hierarchy without any dependency on the reclaimable memory in that memcg thus making it more predictable. Suggested-by: Michal Hocko Signed-off-by: Xunlei Pang Signed-off-by: Andrew Morton Acked-by: Chris Down Acked-by: Michal Hocko Acked-by: Johannes Weiner Link: http://lkml.kernel.org/r/1598495549-67324-1-git-send-email-xlpang@linux.alibaba.com Signed-off-by: Linus Torvalds Fixes: b0dedc49a2da ("mm/vmscan.c: iterate only over charged shrinkers during memcg shrink_slab()") Cc: stable@vger.kernel.org Signed-off-by: Julius Hemanth Pitti Signed-off-by: Greg Kroah-Hartman --- mm/vmscan.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -2619,6 +2619,14 @@ static void shrink_node_memcgs(pg_data_t unsigned long reclaimed; unsigned long scanned; + /* + * This loop can become CPU-bound when target memcgs + * aren't eligible for reclaim - either because they + * don't have any reclaimable pages, or because their + * memory is explicitly protected. Avoid soft lockups. + */ + cond_resched(); + switch (mem_cgroup_protected(target_memcg, memcg)) { case MEMCG_PROT_MIN: /*