Received: by 2002:a05:7412:8d06:b0:f9:332d:97f1 with SMTP id bj6csp13260rdb; Mon, 18 Dec 2023 07:41:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBsnRhefy/S11uVF8BdpNWrN+y2bjW+RxFSJ4c5Q4bTr7y1Q5itJpcDrSo1ib3gvVuqdXP X-Received: by 2002:a17:907:944b:b0:a23:52b7:c0c7 with SMTP id dl11-20020a170907944b00b00a2352b7c0c7mr1415134ejc.132.1702914106507; Mon, 18 Dec 2023 07:41:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914106; cv=none; d=google.com; s=arc-20160816; b=QLwdJ9ruMj3ujwB2fyinzUVrlrH9u5X7RlI+cfjHfDfEO6ruwf3cJGlC3cgLDyjLlg JN2YrTnnK+i88Zc/EqxkAUaeHbF28V6VoFww+uLXVSpl0qqv9hR8bahsYzGPBJT/s+WD Mk9rgyF4P9JSj7VPN+Bffpamit2Ai1UNCsOXEp1LK1jslDXcaRUua/WBKO9dCxJvA7wd 9AcvC7mwLauUaisMpANDH8bQrh7Nfj2vPD9nkV1de9MGjkppKyq1hq6Orkp+f0XEqAZx RNTHUPo0ZkTOfyUQT5W9V8T7Tm7lzp7JTsnGU8A0W0w7M941YK4Jp7P8dpPcobFK+a7Z F6kw== 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=wPsE/cfutq1rEAGOfLa3oRuKt43FXWjmjgTx/hXSxEs=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=mO2/chr++Glo9ocX+nXY9IfusgIYaJW0GznGTvJ1u+Wc96b/H/EQ4s+U0nf8L9Mnk1 HPccebMiNjyLQqmbfSG0LD6Y4BWe5J8W7CN5uOVfVGq0r7SUFsv7PjmnewVVhNeePUK9 vSeygZz4t5WIihR13xZOTovBwlD5oXJbe3JYwVyTunOyJ0sDxgGWt5uDWO+FOBhAQRdt GEg6VgqB7GqQ/7YnPRZKG05iro3KElbtD9ewXWny/ThnIZlgR7UTIn9PZ0JwID3T+MNz vg8nXFX9g2GuF8vvNavFzjSnmmSX2KDrBkhkcBAFRRKYwQ6wfP9hwN3LS3Ik5r7G3kHK Wf6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=v8x9AkNH; spf=pass (google.com: domain of linux-kernel+bounces-3956-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3956-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gy19-20020a170906f25300b00a2354f78a92si1104172ejb.7.2023.12.18.07.41.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:41:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3956-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=v8x9AkNH; spf=pass (google.com: domain of linux-kernel+bounces-3956-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3956-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 2E0F91F22BEE for ; Mon, 18 Dec 2023 15:41:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F0CE37349E; Mon, 18 Dec 2023 15:36:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="v8x9AkNH" 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 11FED4239E; Mon, 18 Dec 2023 15:36:37 +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=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> 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)" 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 | 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; -- 2.39.2