From patchwork Thu Feb 15 06:36:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13557441 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 2B388C4829E for ; Thu, 15 Feb 2024 06:37:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0F9DD6B00B2; Thu, 15 Feb 2024 01:37:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 05CC36B00B3; Thu, 15 Feb 2024 01:37:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DC9896B00B4; Thu, 15 Feb 2024 01:37:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C67E56B00B2 for ; Thu, 15 Feb 2024 01:37:18 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A835BC01B6 for ; Thu, 15 Feb 2024 06:37:18 +0000 (UTC) X-FDA: 81793081356.19.6E7FFE2 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf10.hostedemail.com (Postfix) with ESMTP id 02B9FC0006 for ; Thu, 15 Feb 2024 06:37:16 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Sq+z8AZs; spf=none (imf10.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+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=1707979037; 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=j7oK7/19ACOHFK7IfrqUkUYg5wgn+UHWF7oPozt79Xs=; b=vc3xyx7raRLnHuw/hwtUWfPYNWcTVwNAf7nZ8QVWQlAPLlGiAMHxP+gYL3xWhEUr7f1/OB O6DdEmQqNrhmqFNaR/OQjE564QF95DVzAPNEmYdJ3t9lmFf1k3Pp0Q14frqwDgs/YhxySJ nzWuAcrpub1fUHFtU/XT60uzuvsWZQ0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707979037; a=rsa-sha256; cv=none; b=TZ9RCbcCjpPWyCjugaZtAvmLm+MxZ+m9B9WvJ6+Cx7S5R2eLOTm4brJ5Rk7j80Q6H7LX7v VMBipCxuuDsH/F2JgsbprscRnRTSRTOQSwRP1gkrw/GtPVA+O1n86ejMTSoEQ8vOKIWTly elJQhiqU4UZdeY7LpMeatsILAaHkDy8= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Sq+z8AZs; spf=none (imf10.hostedemail.com: domain of BATV+a252b21bd4a653ddb6e6+7480+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+a252b21bd4a653ddb6e6+7480+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=j7oK7/19ACOHFK7IfrqUkUYg5wgn+UHWF7oPozt79Xs=; b=Sq+z8AZsN0OQbwPCVzc+xwQZGf fm7ViVlN00hHrVnU8bKUDWgWsINORFCOeB+0xJoU8o4n9XW0DUTNhYVyHCWo2D9EAbYlSs+mH2Zi3 cpFB3g/my0T6zfQauarrKIvaavz8csDa0WZzcqjrtb46C+vOL7IhnqPIra1qjqOttDVVXV53wU0kx dOUAlCiVv+TEA9PIDtoJZSnY8o+DS3Fln0eJY88JIE/JF/a8psprUrXFNayGPEzIQfuLeMwDKSV7y ukZ6Q+vsJSn6lKCKVRjJtjtBjaraFHqZiwoUa3zHZQcOnCDCId4RHZYS8dh0gHaO5Do9icAR8Jgfd DIfn1KdA==; 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.97.1 #2 (Red Hat Linux)) id 1raVMx-0000000F6uZ-36cp; Thu, 15 Feb 2024 06:37:16 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 07/14] writeback: Factor folio_prepare_writeback() out of write_cache_pages() Date: Thu, 15 Feb 2024 07:36:42 +0100 Message-Id: <20240215063649.2164017-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240215063649.2164017-1-hch@lst.de> References: <20240215063649.2164017-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-Stat-Signature: 8deb8ucpsjxn7okzwbhsx9656743oh7x X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 02B9FC0006 X-Rspam-User: X-HE-Tag: 1707979036-522891 X-HE-Meta: U2FsdGVkX1+AmyvSUVs+Jf3DKh7hDZQl50Vxff1a6cM8c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Vmr0S2MUQB4nKsJcUT78HUrjoLxcdufwOXDGFR8fnjO8xEY3mdS0fZLWrovnAaFMUxmTyHXz5AsURfHRxa2zgib+5vqfhbaj3Cuqb/F3+d7324vsMZx7U8PsP065rL4FsJbYwCo+j6z0RqqDGbY9KjKGWvtbnqeZP9lyU5t/RrmkQlqV4p7+Qg9Pt2sJrSCU0DmqDooal2Lb8CqeHd6jySvn2X2P5kE9u1XuL8mZt2zKGpkpvI2JUJSjbbAzfv8KT/AESj9SKOW+3KDPzyeywwpy1q4oJ3dx6WYHbZs5sfu0nNWYmw2p/e7lybPWJjkL6dnwLs4uEzeTsPGMAVbtElUwrj1nUm0cbBaTJrNpevHYvK03j3aj0qkyF90vzGA7irnbT3qSvvqq 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 3a1e23bed4052c..4bc55ce9597d13 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);