From patchwork Thu Dec 14 13:25:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13493104 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4AB8C4332F for ; Thu, 14 Dec 2023 13:55:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55D0F8D00C0; Thu, 14 Dec 2023 08:55:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 50CAA8D00B1; Thu, 14 Dec 2023 08:55:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D3CB8D00C0; Thu, 14 Dec 2023 08:55:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2C6C68D00B1 for ; Thu, 14 Dec 2023 08:55:31 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id F2390A15D0 for ; Thu, 14 Dec 2023 13:55:30 +0000 (UTC) X-FDA: 81565571220.18.AB6FF49 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf30.hostedemail.com (Postfix) with ESMTP id 3B78C80017 for ; Thu, 14 Dec 2023 13:55:28 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fYKo14Qx; spf=none (imf30.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702562129; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kAPP6X55X6rvLdfMOtbLbsXeMDzuMOl2croRJo78UX4=; b=44gskunlsKuuG0/Peja9g/m2K+BSQpUfMc+d3czgwTihHJHBCzUCWcSYlEvcoQc1eG3oSZ XFNn17Cvr/8YFC+JSHJhUo+tz+BiOrbShGfRqxV8ztya2NvdV1zmW3nQPnYOOWuq9Amtbr AxE9aT1MZKwzOCPy7Z05JLCxV+UT6XY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702562129; a=rsa-sha256; cv=none; b=WjjhsGNxnU1Vd/QEvXfkdEQvlARwD0hjav/wpaIoYJIWUfFDUhxZ2aOdoo532MlvpRvFgb woaw96d4BkHZJDoYQwYuzXrXM+DqTs3PkL3BpygsoQhMjbqyA6QofvqOBwknxmEmM84Bf/ R0Vw9KkHlUyxim30b7/mAbXgQK06j28= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=fYKo14Qx; spf=none (imf30.hostedemail.com: domain of BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+55581d165dda9d0af87b+7417+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=kAPP6X55X6rvLdfMOtbLbsXeMDzuMOl2croRJo78UX4=; b=fYKo14QxQKLG96JxNh2gKkqwXa wsvp3uUwGV/Pnm6RVQ/FkMXvsez7eoeecA/pnOwd1vlL/3q7t/raPaZZEcb8RfyZEmpowiZMPLews ppeYWW2XD2womPwLiqiyZobEmdUTrc9J1baAEJ+PnEaO9wafX1ux6yu8ZSaE3ttElyNcNu5l7JyZ6 aE1PvkMIS0bXSJEWwBte6poJSIKKE0+N5v2kwDU42DTmDcVmeNJCjolZuPnbW6cySjI5L2MIe9N7t 820nBKAWHp+TfTTmFYqUoodssCijbcLm2oCZalIcEf11h3nd3Ltie7vsrHAttdJKjAc5duP5q0ioq LbAP1U3Q==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljI-000NBD-36; Thu, 14 Dec 2023 13:26:21 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 08/11] writeback: Factor writeback_get_folio() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:41 +0100 Message-Id: <20231214132544.376574-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 3B78C80017 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: poyp1m4au9s5zaht4ur19xyx8u167tz1 X-HE-Tag: 1702562128-942979 X-HE-Meta: U2FsdGVkX19nTOV4s/ycVk8qD9wrC0i23Kpne3CojIL/lqeRDOjBgF16DSwVZcrXhyTu15pLDZKIKVNH145EKNbvkHutBL3JDAGaXsAHfYMTVoTy9TfYhagd7FckaWI9t4UZ/srI8O/OB7vrwoj4VWrQuxldF47li2CzCTFuKfCLhwpZQxdcsE1Le8FM5Xqn1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3zhsPgBsUBM4qisGrW6gMrcRvHdOG0GdGyiccjAt4ESYklI8ucs/Qyf8Fs6dNy3UiwVq7PSyvMWAba/Nc+0/sgF7Lv5El+eKuUfzmtzTvPn3xtxG4NajnJ+9q3qxewOxSVbexqhO+bdIpJocxu3VJN6EJdgMYzv0HeLxlib1RmI7YxKAOZw1l7LhmTOPazKCPKaVMt2JGJD60J1WmRMr0A== 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: List-Subscribe: List-Unsubscribe: From: "Matthew Wilcox (Oracle)" Move the loop for should-we-write-this-folio to its own function. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- mm/page-writeback.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 8c220c6a7f824d..b0accca1f4bfa7 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2429,6 +2429,27 @@ static bool should_writeback_folio(struct address_space *mapping, return true; } +static struct folio *writeback_get_folio(struct address_space *mapping, + struct writeback_control *wbc) +{ + struct folio *folio; + + for (;;) { + folio = writeback_get_next(mapping, wbc); + if (!folio) + return NULL; + wbc->done_index = folio->index; + + folio_lock(folio); + if (likely(should_writeback_folio(mapping, wbc, folio))) + break; + folio_unlock(folio); + } + + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + return folio; +} + static struct folio *writeback_iter_init(struct address_space *mapping, struct writeback_control *wbc) { @@ -2448,7 +2469,7 @@ static struct folio *writeback_iter_init(struct address_space *mapping, folio_batch_init(&wbc->fbatch); wbc->err = 0; - return writeback_get_next(mapping, wbc); + return writeback_get_folio(mapping, wbc); } /** @@ -2491,19 +2512,9 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_next(mapping, wbc)) { + folio = writeback_get_folio(mapping, wbc)) { unsigned long nr; - wbc->done_index = folio->index; - - folio_lock(folio); - if (!should_writeback_folio(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } - - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - error = writepage(folio, wbc, data); nr = folio_nr_pages(folio); if (unlikely(error)) {