From patchwork Mon Dec 18 15:35:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13497167 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 BDFCCC46CD2 for ; Mon, 18 Dec 2023 15:36:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 62E848D000C; Mon, 18 Dec 2023 10:36:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5DE838D0001; Mon, 18 Dec 2023 10:36:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40AA38D000C; Mon, 18 Dec 2023 10:36:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2CAF18D0001 for ; Mon, 18 Dec 2023 10:36:37 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 01AE61601AD for ; Mon, 18 Dec 2023 15:36:36 +0000 (UTC) X-FDA: 81580341234.30.5709956 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf07.hostedemail.com (Postfix) with ESMTP id 3347840015 for ; Mon, 18 Dec 2023 15:36:34 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=v8x9AkNH; spf=none (imf07.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702913795; a=rsa-sha256; cv=none; b=bJTRKfdZoipmqyWAJpsIFaMBnsmi2lRs/N51My6Zcjr/JKj3UmKkxLjPDPPA3rBJ4nm6bU PuLxr8KXOzbFYrMa5C3stqVGgA3u97TJzgOYmAnRinLTicQltXeQ5KmpYXm6PZWXJQY9gN UA8stRrazKBjnIum7ojlAvewuI36Hro= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=v8x9AkNH; spf=none (imf07.hostedemail.com: domain of BATV+09f18f96a25a69770120+7421+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+09f18f96a25a69770120+7421+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=1702913795; 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=wPsE/cfutq1rEAGOfLa3oRuKt43FXWjmjgTx/hXSxEs=; b=UXUoBS9zq1rG1AvJlg9DBNXHS8VU7M8Lm6iHDMH2Fnu0rJdB8w6B/tk//xZJYSv2s8OSKi a/WJM/voCEwj6DvvKgboLBvRGaF3maX94Tw6xgv0VvXZPuHftyH3hT/rmrg7IbYV+Bhuph BBAAF/Rz9HAMiCDlTi++bzAVNYmFkf8= 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=wPsE/cfutq1rEAGOfLa3oRuKt43FXWjmjgTx/hXSxEs=; b=v8x9AkNHKUmXVr4XL4EvllOnXA eHt9IpWbfIqZsl1l7GqGaWOhzmg7u5y0N6GXufr1QDG5Dy7byB/Ne/jM7TatIS09Ec2dHkXOUe7/u wOQSxttmSJUsViYu0u/sGGD8jd/9BN8AV+ZNSqlidRqS51/pJwK9kSVc6RvzUm2iAJ+W0choBCDJd bai/UgzHAqgH0KE8i6zm8sSU0/4s5FB3jvvqfsCsjkCv3EPmOP5o/6fiWeoS5HFappECuG9zpVo2N sMBisySZfzOCUvCGxwiPCRERS0bvvDG6T4NQRManmuNEyWGFFp5FR4NjXzlm6p4330y/hWtdN16Jg KZLsOkZQ==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rFFfV-00BEXI-2C; Mon, 18 Dec 2023 15:36:34 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 13/17] writeback: Factor writeback_get_folio() out of write_cache_pages() Date: Mon, 18 Dec 2023 16:35:49 +0100 Message-Id: <20231218153553.807799-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-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-Server: rspam08 X-Rspamd-Queue-Id: 3347840015 X-Stat-Signature: dkehmg9bc6ecqk1u9845ozh7hfqf76ah X-Rspam-User: X-HE-Tag: 1702913794-280501 X-HE-Meta: U2FsdGVkX18mnoa0TikPTJF+luWSCVyiclDynfecl1iSYfR+mMVss29fz56NFAs5mRnxkWEgQrugqrUVPQkclQQ/jWaFIMFWE7sA2K4pJiJdDi3GEbpbZg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o8wwbUjwuNN3FKYeDRMHFSlEPv6hZGTCPlX8ell5LPdolag9cFAglpFrWoJTEdgdlpaB+3iJlm5XmO/Lf490bo05Te6sVNS236wFdN/A/DPCdQ5BJ7gOSwa5cy2GHCNWM4iY7OmXJwCpMenYwS7g7BQfJ422EnMdQI2Ltsfz3mv607Sy0lO4MhxZTHNGv4cKmo0qKb4jfQOEF59y72gqhb99Ng6W7H4IMoxF3pbBwtRCXPFxxjRk72qWRCCpkIb6ysmRSA3dpRghDs5kw3IBLzPNaC9v2fc4+dJcH4lwll9JfziFBeMPUDxod+xYL6+H3Ejq+utSH4= 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 Reviewed-by: Jan Kara --- mm/page-writeback.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index efcfffa800884d..9d37dd5e58ffb6 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2442,6 +2442,25 @@ 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; + 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) { @@ -2455,7 +2474,7 @@ static struct folio *writeback_iter_init(struct address_space *mapping, wbc->err = 0; folio_batch_init(&wbc->fbatch); - return writeback_get_next(mapping, wbc); + return writeback_get_folio(mapping, wbc); } /** @@ -2498,17 +2517,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; - 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); wbc->nr_to_write -= nr;