Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5981037rdb; Thu, 14 Dec 2023 05:26:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IH3RCHzu/AtUtqfRwUjJGmYe12N9HjUv6zUuLubXYTaoLc7w2uqwVZJuHgg5bsDbuYs6qxG X-Received: by 2002:a05:6e02:310f:b0:35f:7f8e:6241 with SMTP id bg15-20020a056e02310f00b0035f7f8e6241mr1314782ilb.58.1702560409729; Thu, 14 Dec 2023 05:26:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702560409; cv=none; d=google.com; s=arc-20160816; b=sisx1DS1mV5IOa2B2Fq2GoGzo+9sLBPuqTtONi2LXz7YYi4qc9FHg8e2QKWgfVApHM LBsbLBpjFRhvLHqhqLXQbRztjLmMJjajVvAHLWQWR7/Qy5AHa9p8XrAKJ8Xsiva3gaKj WdLuEPHyScrj6jJF24zT4DvO77GFDE898NDTcIRmATVBjzJDJH07RruINdIMwULb1WAy sa72PeK+Lv3y5Ya5G8ysWEfhD43mfyeWIyTiYybQ62slA1tLYz+9DQjQCjJTfiZ3EfZg 6AkxdLgGjHmOUMq07Dild3VtZX8aMYpkMiTXD4MTWoHMMRpJkpB396ZN3XTE918KQuEb j1sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rO9jeRnP/+STXFpOLNVshKgFr5PxJQ0M9NIzpjYwpKk=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=mYUFfhT+3s2mfQtCkHYn7Sggg/FzMj5JE21Q/qsIFrrS6t1PeiY+VYr+lvKQo53Bck 3ufHL/nx/mFu5Ki9Am3NSt/XmGro5x6fBZIQ3l31W19W1ydPOZXAr9r1zoX2xChrQhJ/ D8gT9F+K/bextVLo0U0RHgmn0XnPfd0YhfhctwzXaQ2ie9XO4Z+BQPZt1vgnuSCLjJWV 62Lon/51cpY99JbQHsfli7ggtTbmldavcXbsScnZBFGqh+GpVz60Z+5ShoUkOA+RfF2P BaeMNbfn7BKxX5MEDupbww+Cm1DXIKSx28pTta96Cd3GR8IdQqGCo6FDtggDw4/Ibqvr r/Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=D7Kg0BZm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id f3-20020a631f03000000b005b92ab9ce80si11039363pgf.460.2023.12.14.05.26.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 05:26:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=D7Kg0BZm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 0E46881829E5; Thu, 14 Dec 2023 05:26:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573340AbjLNN01 (ORCPT + 99 others); Thu, 14 Dec 2023 08:26:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573282AbjLNN0T (ORCPT ); Thu, 14 Dec 2023 08:26:19 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E8A6114; Thu, 14 Dec 2023 05:26:25 -0800 (PST) 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=rO9jeRnP/+STXFpOLNVshKgFr5PxJQ0M9NIzpjYwpKk=; b=D7Kg0BZmQc0TuV5ZDIwkGWmB/U Zo/YYkysOcmLOYlozdFyDhxa/ft5aO9Cpo/k651xsSCKrfdaDuLo44vbjtNNrh2wJQ9+cchXfBLuq 52wt6O1lBjWPFKacUOOT0H6TFOCL9zAmeCIUotwrsb6M0Ls/iKQoZdgpswJlT/0ecl/g6lqqJ1eTD GBt+L35/mOQ6ziE4gdB/7Px8A2gzSuvP4JaXARqb3q50wAVbCEFXdR0tscS9tuCrax0JCmgiAdGRp WH627gbw6OvYJO1pQ4KXk9boZ03t3PQWs9UTlHu/z27Y8n4kE/5UKpUwziRa5Zf4TxcquJiO/5XKV BTZpC1JA==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDljM-000NCz-2K; Thu, 14 Dec 2023 13:26:25 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 09/11] writeback: Factor writeback_iter_next() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:42 +0100 Message-Id: <20231214132544.376574-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-1-hch@lst.de> 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 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 14 Dec 2023 05:26:46 -0800 (PST) From: "Matthew Wilcox (Oracle)" Pull the post-processing of the writepage_t callback into a separate function. That means changing writeback_finish() to return NULL, and writeback_get_next() to call writeback_finish() when we naturally run out of folios. Signed-off-by: Matthew Wilcox (Oracle) Signed-off-by: Christoph Hellwig --- mm/page-writeback.c | 89 +++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index b0accca1f4bfa7..4fae912f7a86e2 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,7 +2360,7 @@ void tag_pages_for_writeback(struct address_space *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); -static int writeback_finish(struct address_space *mapping, +static struct folio *writeback_finish(struct address_space *mapping, struct writeback_control *wbc, bool done) { folio_batch_release(&wbc->fbatch); @@ -2375,7 +2375,7 @@ static int writeback_finish(struct address_space *mapping, if (wbc->range_cyclic || (wbc->range_whole && wbc->nr_to_write > 0)) mapping->writeback_index = wbc->done_index; - return wbc->err; + return NULL; } static struct folio *writeback_get_next(struct address_space *mapping, @@ -2437,7 +2437,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, for (;;) { folio = writeback_get_next(mapping, wbc); if (!folio) - return NULL; + return writeback_finish(mapping, wbc, false); wbc->done_index = folio->index; folio_lock(folio); @@ -2472,6 +2472,47 @@ static struct folio *writeback_iter_init(struct address_space *mapping, return writeback_get_folio(mapping, wbc); } +static struct folio *writeback_iter_next(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int error) +{ + unsigned long nr = folio_nr_pages(folio); + + if (unlikely(error)) { + /* + * Handle errors according to the type of writeback. + * There's no need to continue for background writeback. + * Just push done_index past this folio so media + * errors won't choke writeout for the entire file. + * For integrity writeback, we must process the entire + * dirty set regardless of errors because the fs may + * still have state to clear for each folio. In that + * case we continue processing and return the first error. + */ + if (error == AOP_WRITEPAGE_ACTIVATE) { + folio_unlock(folio); + error = 0; + } else if (wbc->sync_mode != WB_SYNC_ALL) { + wbc->err = error; + wbc->done_index = folio->index + nr; + return writeback_finish(mapping, wbc, true); + } + if (!wbc->err) + wbc->err = error; + } + + /* + * We stop writing back only if we are not doing integrity + * sync. In case of integrity sync we have to keep going until + * we have written all the folios we tagged for writeback prior + * to entering this loop. + */ + wbc->nr_to_write -= nr; + if (wbc->nr_to_write <= 0 && wbc->sync_mode == WB_SYNC_NONE) + return writeback_finish(mapping, wbc, true); + + return writeback_get_folio(mapping, wbc); +} + /** * 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 @@ -2512,49 +2553,11 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_folio(mapping, wbc)) { - unsigned long nr; - + folio = writeback_iter_next(mapping, wbc, folio, error)) { error = writepage(folio, wbc, data); - nr = folio_nr_pages(folio); - if (unlikely(error)) { - /* - * Handle errors according to the type of - * writeback. There's no need to continue for - * background writeback. Just push done_index - * past this page so media errors won't choke - * writeout for the entire file. For integrity - * writeback, we must process the entire dirty - * set regardless of errors because the fs may - * still have state to clear for each page. In - * that case we continue processing and return - * the first error. - */ - if (error == AOP_WRITEPAGE_ACTIVATE) { - folio_unlock(folio); - error = 0; - } else if (wbc->sync_mode != WB_SYNC_ALL) { - wbc->err = error; - wbc->done_index = folio->index + nr; - return writeback_finish(mapping, wbc, true); - } - if (!wbc->err) - wbc->err = error; - } - - /* - * We stop writing back only if we are not doing - * integrity sync. In case of integrity sync we have to - * keep going until we have written all the pages - * we tagged for writeback prior to entering this loop. - */ - wbc->nr_to_write -= nr; - if (wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) - return writeback_finish(mapping, wbc, true); } - return writeback_finish(mapping, wbc, false); + return wbc->err; } EXPORT_SYMBOL(write_cache_pages); -- 2.39.2