From patchwork Mon Oct 24 11:31:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 9387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp478180wru; Mon, 24 Oct 2022 07:16:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7iUMV12hKrjyDZkVM7xC76l1SIeovIB/94JZ52H4wsKYp32PXEijhs9ClRQeIg0xQbVqVA X-Received: by 2002:a17:907:7b94:b0:731:1b11:c241 with SMTP id ne20-20020a1709077b9400b007311b11c241mr28475347ejc.676.1666621016950; Mon, 24 Oct 2022 07:16:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666621016; cv=none; d=google.com; s=arc-20160816; b=Op8nP3qaWly89PSbsgQZK30y5ptr6ta52kZPU4Cv78SMwxBi/42KxII1+FqTRS0p0u LvYj64P5rvgTUoBoUf+zdUOCke8TThbjaHRfPrWDRPpsCFPZiZbF31T3RqNBNHUMxWT9 WcTFO2Ec7/tTKXezdJjvlwEggnaz5WKhxAdri9YIhoMaQvPj7Ka2mH2444NrdHRG/vw8 wV0zMViityxCzzUyoDBhgTxnLLsVGHKWEYjWptQ5LT5unaRrMV8wACi8jS4p23Wb/8zC CfGpOOtjciMrqSPRj/P59zI93yCcYofcOZoUi3f8V+9CZPZdQ0sK3bGRgYzUJzF/FYsl 7yAg== 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=eDLJJAY+5uIUqz7jDifqGbVUhvea7zHpB6Apq6tX1Mk=; b=HrqJZ9vnymccpebeDf5c2Iu0kGkcHLCv1RWoYtVCGFUmrzXeKekRKUpR29HwLivJZe rcUH7b1Ne6tv6P37r8fgVDpGAjDbTMUeG9zVC7rnJ1rAYMulhjSivY4oN1ZWKb0QGFoE Bn/DT6erQcLukfRHNiTgqGp6AX6Hcuc6thxYmNgrc6nEsslFpme8JALvLFcoyMiPP5gH t18D6agiQVbYTJV443/pNScIxgcJb5cTGutYMIvcQxAd0+Ts3UBePCeRoe0H8hg3AqO/ +LZ1Cq4zaec1donfXp/dpG3kzkxWIRcC9zBzmJaHWd+zpHZaVTISd+buO9SDNOfKDt88 IhwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KiYibeJ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm4-20020a170907948400b007894b9de062si14861661ejc.631.2022.10.24.07.16.31; Mon, 24 Oct 2022 07:16:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KiYibeJ+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234643AbiJXOGW (ORCPT + 99 others); Mon, 24 Oct 2022 10:06:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235392AbiJXOCu (ORCPT ); Mon, 24 Oct 2022 10:02:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10A709083D; Mon, 24 Oct 2022 05:48:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8544C612E6; Mon, 24 Oct 2022 12:28:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69A34C433C1; Mon, 24 Oct 2022 12:28:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666614525; bh=la6Focf99ixLU4gXyDPCNI6jI7AOOZrRr8SSC+3kks4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KiYibeJ+4YFAQx1zcFpOkZgBQGYXmQbXn5+7NM8+ZKwFCvZNt+AYEMryAmdI1uO4b u4FfC6q5IgHr6XQUUIouc99mGgXIN1fTn6S4Io1DcVg/eCCQS5UZSaEu6CRIq23e9B tSH1gH/gWCJ3cCiddYS0STlGfIdNRVwvuB1ZRco8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Uladzislau Rezki (Sony)" , "Paul E. McKenney" , Frederic Weisbecker , Neeraj Upadhyay , Josh Triplett , Steven Rostedt , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , Michal Hocko , Sasha Levin Subject: [PATCH 5.10 295/390] rcu: Back off upon fill_page_cache_func() allocation failure Date: Mon, 24 Oct 2022 13:31:32 +0200 Message-Id: <20221024113035.566284035@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113022.510008560@linuxfoundation.org> References: <20221024113022.510008560@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747578799245569443?= X-GMAIL-MSGID: =?utf-8?q?1747578799245569443?= From: Michal Hocko [ Upstream commit 093590c16b447f53e66771c8579ae66c96f6ef61 ] The fill_page_cache_func() function allocates couple of pages to store kvfree_rcu_bulk_data structures. This is a lightweight (GFP_NORETRY) allocation which can fail under memory pressure. The function will, however keep retrying even when the previous attempt has failed. This retrying is in theory correct, but in practice the allocation is invoked from workqueue context, which means that if the memory reclaim gets stuck, these retries can hog the worker for quite some time. Although the workqueues subsystem automatically adjusts concurrency, such adjustment is not guaranteed to happen until the worker context sleeps. And the fill_page_cache_func() function's retry loop is not guaranteed to sleep (see the should_reclaim_retry() function). And we have seen this function cause workqueue lockups: kernel: BUG: workqueue lockup - pool cpus=93 node=1 flags=0x1 nice=0 stuck for 32s! [...] kernel: pool 74: cpus=37 node=0 flags=0x1 nice=0 hung=32s workers=2 manager: 2146 kernel: pwq 498: cpus=249 node=1 flags=0x1 nice=0 active=4/256 refcnt=5 kernel: in-flight: 1917:fill_page_cache_func kernel: pending: dbs_work_handler, free_work, kfree_rcu_monitor Originally, we thought that the root cause of this lockup was several retries with direct reclaim, but this is not yet confirmed. Furthermore, we have seen similar lockups without any heavy memory pressure. This suggests that there are other factors contributing to these lockups. However, it is not really clear that endless retries are desireable. So let's make the fill_page_cache_func() function back off after allocation failure. Cc: Uladzislau Rezki (Sony) Cc: "Paul E. McKenney" Cc: Frederic Weisbecker Cc: Neeraj Upadhyay Cc: Josh Triplett Cc: Steven Rostedt Cc: Mathieu Desnoyers Cc: Lai Jiangshan Cc: Joel Fernandes Signed-off-by: Michal Hocko Reviewed-by: Uladzislau Rezki (Sony) Signed-off-by: Paul E. McKenney Signed-off-by: Sasha Levin --- kernel/rcu/tree.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index b41009a283ca..b10d6bcea77d 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3393,15 +3393,16 @@ static void fill_page_cache_func(struct work_struct *work) bnode = (struct kvfree_rcu_bulk_data *) __get_free_page(GFP_KERNEL | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN); - if (bnode) { - raw_spin_lock_irqsave(&krcp->lock, flags); - pushed = put_cached_bnode(krcp, bnode); - raw_spin_unlock_irqrestore(&krcp->lock, flags); + if (!bnode) + break; - if (!pushed) { - free_page((unsigned long) bnode); - break; - } + raw_spin_lock_irqsave(&krcp->lock, flags); + pushed = put_cached_bnode(krcp, bnode); + raw_spin_unlock_irqrestore(&krcp->lock, flags); + + if (!pushed) { + free_page((unsigned long) bnode); + break; } }