Received: by 2002:a05:7412:8d06:b0:f9:332d:97f1 with SMTP id bj6csp11773rdb; Mon, 18 Dec 2023 07:39:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IFj7GHpnZfNoB0Ol6NKZ/Q0PEtK+qIX+/ulMgPd3SUeUU+gHNfXYf/4Gh1YJ35uSQMPpq1e X-Received: by 2002:a05:6e02:b41:b0:35f:86d0:5e03 with SMTP id f1-20020a056e020b4100b0035f86d05e03mr9892287ilu.9.1702913965205; Mon, 18 Dec 2023 07:39:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702913965; cv=none; d=google.com; s=arc-20160816; b=01auz/IbQ6uhZPI0YKpnsIQGYSaod++/Sd8U7hW0NGhjvp1vlh14skXKBElLGelWy5 VomKzQPWDIoY7jUwzJmPN5BTRjz6ZsSAvtyehAdxWvk3HiQrddQvnB5jhKIbHv7mwvih +L+zvpSLXjrP19RvgF4GQ7jgb65kitTIa1QnnaMXYXCcbVhXJB9AgB9bY3RimIt1HRGB 5ofcLh+g1EsmNBb7vOLzT+KHu3PE3hdIpt4n3t0MiBm8HRDj+pbmgQkUhBb9Mm27h7Aw /QSoujVkJpZ7PJ/GTN1AcntN6F9Wfk4rQOoAxlAL3FlnCcugTR17TxBVKaS11M6e+gUX 5zFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FNt5drM75tskFSjmTVt5X4B1n0+AI4vg4FZ50KNwnlI=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=Lmm9Zyd6Pw+nnjaBUy4Ci6pAFB1AvWA2GPOkRROyTDcNMIltDKb6CDc/x40e9Xa722 PZmCFjE2cFkxatOnJr/QYL5o2EZG4526RD+uSNQ8OHPrfuvUVF9qeqwhUQNDgXvuL95E LRV5ScHV2S2Syp5Dpp2AvTQYXDqXx0oWSWwFTN7tTqcIy7yZyNYshX9ye9MW6Wn8jDgP ekBiyKINBLq/lSozoulZcG1ez/8UK4trgJn5MhaonmnN5MtYGigaTubcdDM8snoSBI18 nDcGp+uRO57T3Y1JC4gQMu7p8QjToIyEjPPGjQVeXykNi5IPKEfq1znMEUEONxzlgylF MCAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=QbDL69GR; spf=pass (google.com: domain of linux-kernel+bounces-3951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3951-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id kq17-20020ac86191000000b00417fda900b7si22513040qtb.374.2023.12.18.07.39.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:39:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=QbDL69GR; spf=pass (google.com: domain of linux-kernel+bounces-3951-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3951-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DF4FA1C24D05 for ; Mon, 18 Dec 2023 15:39:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F43142387; Mon, 18 Dec 2023 15:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QbDL69GR" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB7C971441; Mon, 18 Dec 2023 15:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org 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=FNt5drM75tskFSjmTVt5X4B1n0+AI4vg4FZ50KNwnlI=; b=QbDL69GRW7vcyaByv+sL4EM+jX e1QFZOSXKXPkEb+eHP3GiM6UxRPacz9vafLmcd5vlzhMaNWjnWNm72N3eC5D3DOMxmjaWumGDpjGr XM6FXOQJMz+HmusWg+1LvjoRZGZU2wpeb6PIpggTeUTU3a+7tMOXiJPs2b8G376PygzwpKTNPmEIs hMmgGXMFBpTBYKLuq7Eb1xdpwVhL/ExPQOMB+E9OezOoHgfinlWKM3AQzMwJIsUS75WJ0yGWCDtN5 eQcmtSldtT3O7o6PWVWQLoa8KFVGz3GXZDRsAm5iHAYmgw9nL9j365MYyfJKPnp5qDf1Z929i1sSr k+mKxi/w==; 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 1rFFfE-00BEOe-2o; Mon, 18 Dec 2023 15:36:17 +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 08/17] writeback: Factor should_writeback_folio() out of write_cache_pages() Date: Mon, 18 Dec 2023 16:35:44 +0100 Message-Id: <20231218153553.807799-9-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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) Signed-off-by: Christoph Hellwig --- mm/page-writeback.c | 59 ++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 798e5264dc0353..2a004c0b9bdfbf 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2406,6 +2406,36 @@ static void writeback_get_batch(struct address_space *mapping, wbc_to_tag(wbc), &wbc->fbatch); } +static bool should_writeback_folio(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 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 @@ -2470,38 +2500,13 @@ int write_cache_pages(struct address_space *mapping, unsigned long nr; 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 (!should_writeback_folio(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); nr = folio_nr_pages(folio); wbc->nr_to_write -= nr; -- 2.39.2