From patchwork Sat Feb 3 07:11:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13543901 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 DD968C4828D for ; Sat, 3 Feb 2024 07:12:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 64CDD6B007D; Sat, 3 Feb 2024 02:12:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D57D6B007E; Sat, 3 Feb 2024 02:12:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 450886B0080; Sat, 3 Feb 2024 02:12:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 322356B007D for ; Sat, 3 Feb 2024 02:12:31 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C63F3160455 for ; Sat, 3 Feb 2024 07:12:30 +0000 (UTC) X-FDA: 81749624460.10.D4A517A Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id 26BB140007 for ; Sat, 3 Feb 2024 07:12:28 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QtHTeuf+; spf=none (imf17.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+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=1706944349; 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=jfeyOGGqJMEhwjwDWY78Dxs/MD9XWP1Zn49OkkJuspU=; b=RX0ofPWOAKlahAOKfTcnS8/s3QHzSh4lHDt9/et4CGJahtybLmF0nzPpEFEfvsjQ3M4Uhe xDy3GgsjJrjVBdGd3xPpVdOCBYV6M7H5dozh+eEuVo18Qd6Moby7wQ1eDxrpsAfFObvRWT w9hC8qZhOD5U3Oe7eIfC3ev6VGstZjA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=QtHTeuf+; spf=none (imf17.hostedemail.com: domain of BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a0ed29cff9639d748e7e+7468+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706944349; a=rsa-sha256; cv=none; b=kWueTmOIzPX7TUb0yLKuJQ6YUqe3QwzZd58irOyO1UeiAGed3xsj9zog32ARBB3OGh+EDJ cv3H8F33LCfTTdcTAZZXr8pVZc+cRsrbzOGV4p3pFf/QxVPR1r4prUeMYR+ECiqGBTsLtl aUoa38+NYHCMaAVfvLQl32WCoo9VsKY= 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=jfeyOGGqJMEhwjwDWY78Dxs/MD9XWP1Zn49OkkJuspU=; b=QtHTeuf+5e3JSMI6nOmskVdXn2 G8jz9FhabBgFanvh596iAi7noXgATwCi8VOdtCyLoUHl0L23Nt+Egfg2/qpZAHF/W78ZpJNpLkMwB tWjQjqHjUneWK8LK2zuwoMrnCEyUN+CmhqZ4ZRSFYbptSY4swVURu/4e3Wboeen9MkaDWNvQqFMcN dJYtx4TWqYx60UTzX1pE7h6Qqr6AZd0lfbtQep3EuRDdIA4AR7a8KjkW2ll/n7LfL6rU4nSfL1ow2 tWQyVWXrjWKzWGksYBzaHtM9g2dn5LHuKdQbFjjcm3XvN0izvhzgH9QM6RVm05E3b4IZ19SOjZh9w dmh0Pezg==; Received: from [89.144.222.32] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.97.1 #2 (Red Hat Linux)) id 1rWACQ-0000000Fk6W-3iJc; Sat, 03 Feb 2024 07:12:28 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 06/13] writeback: Factor folio_prepare_writeback() out of write_cache_pages() Date: Sat, 3 Feb 2024 08:11:40 +0100 Message-Id: <20240203071147.862076-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240203071147.862076-1-hch@lst.de> References: <20240203071147.862076-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: 26BB140007 X-Rspam-User: X-Stat-Signature: mprr9rymncih95ajw3a3yf3rde4koozr X-Rspamd-Server: rspam01 X-HE-Tag: 1706944348-228409 X-HE-Meta: U2FsdGVkX1+ZElTdqTLhRtUSUbj/1iqv06hya77DjTZqxg9tgUw3pnxmfk1E+QEIMf+b1Jw2ewZ6IPEX00l8/Uwi/aQ/vGZI7cZzzn5vWGgzd2lKPWz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0+TE72RXRRJKtuTE3AWRMA+K+LeuBnTLGwt1V+ufQspwFq3of/S/TBQcN4joHB0yzannR5xRliXRa4ZYD61phwh3qXmrMX+SDziBo6Ld1eTO6R0hELb2zcznaKReazbJNh99vpx49lZjhlthqzvQzaS9UYPuTIf4ni7MRB5HrQoRu3esX62ZczX28extxpiZzJ5ZiYJdPw/BMK7ooD143IKUC2f3eMTEo9Dh3QL7BFVFVLazPdDffY7cJhZ30UVjGsVnckoov/3HSYnFPmXZw4wNjPCtJnJmaODK8GDAO3kLSOx0UfKYkn5cYRYstFAuyGQTgHGWRQkcHhkUICU= 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)" Reduce write_cache_pages() by about 30 lines; much of it is commentary, but it all bundles nicely into an obvious function. Signed-off-by: Matthew Wilcox (Oracle) [hch: rename should_writeback_folio to folio_prepare_writeback based on a comment from Jan Kara] Signed-off-by: Christoph Hellwig Reviewed-by: Brian Foster Reviewed-by: Jan Kara Acked-by: Dave Chinner --- mm/page-writeback.c | 61 +++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 88b2c4c111c01b..949193624baa38 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,6 +2360,38 @@ void tag_pages_for_writeback(struct address_space *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); +static bool folio_prepare_writeback(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio) +{ + /* + * Folio truncated or invalidated. We can freely skip it then, + * even for data integrity operations: the folio has disappeared + * concurrently, so there could be no real expectation of this + * data integrity operation even if there is now a new, dirty + * folio at the same pagecache index. + */ + if (unlikely(folio->mapping != mapping)) + return false; + + /* + * Did somebody else write it for us? + */ + if (!folio_test_dirty(folio)) + return false; + + if (folio_test_writeback(folio)) { + if (wbc->sync_mode == WB_SYNC_NONE) + return false; + folio_wait_writeback(folio); + } + BUG_ON(folio_test_writeback(folio)); + + if (!folio_clear_dirty_for_io(folio)) + return false; + + return true; +} + /** * write_cache_pages - walk the list of dirty pages of the given address space and write all of them. * @mapping: address space structure to write @@ -2430,38 +2462,13 @@ int write_cache_pages(struct address_space *mapping, for (i = 0; i < nr_folios; i++) { folio = fbatch.folios[i]; folio_lock(folio); - - /* - * Page truncated or invalidated. We can freely skip it - * then, even for data integrity operations: the page - * has disappeared concurrently, so there could be no - * real expectation of this data integrity operation - * even if there is now a new, dirty page at the same - * pagecache address. - */ - if (unlikely(folio->mapping != mapping)) { -continue_unlock: + if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); continue; } - if (!folio_test_dirty(folio)) { - /* someone wrote it for us */ - goto continue_unlock; - } - - if (folio_test_writeback(folio)) { - if (wbc->sync_mode != WB_SYNC_NONE) - folio_wait_writeback(folio); - else - goto continue_unlock; - } - - BUG_ON(folio_test_writeback(folio)); - if (!folio_clear_dirty_for_io(folio)) - goto continue_unlock; - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + error = writepage(folio, wbc, data); wbc->nr_to_write -= folio_nr_pages(folio);