From patchwork Thu Dec 14 13:25:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 178732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8541694dys; Thu, 14 Dec 2023 05:26:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHWSXLupv2himzUOggfGL3f+tNpAspem/sz+fMUm2TIn2nvFdUwSzl4AbaFyaAH08smz4F0 X-Received: by 2002:a17:902:8696:b0:1cf:ef92:18f3 with SMTP id g22-20020a170902869600b001cfef9218f3mr9187281plo.58.1702560403348; Thu, 14 Dec 2023 05:26:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702560403; cv=none; d=google.com; s=arc-20160816; b=kYIOjYnytht9lUDB8BIwYIjm5f55QD0MPw9UF5CdFln2Gb26l7n3c16UFoYrWjU+eJ FbRWFuhN0O78cxGTznbg1kCddV3Tpl5uG6tiGrEt92oDYD5sHRZyd/5pj6u0KmykDJNq BtmuJT3WkFA1pf1I1IsgpqB9nBHz9y2KmMDh6GdBdCiWatX1zkP+/YEILCytM2SlwUPY lkKb23yDwdDx71aZp3qjFG0FxlPG5AkLmm2X+6YAyUkfh8134rgI7jAxop9GW/WrQ5wQ m/4+4q/97+rZqZujS5U+AFFCtWuw7fjRcKa6mq1SzUaXydipaYYwxoylsNy3D8nakmNX hkxg== 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 Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id c8-20020a170903234800b001d09013a13csi11354809plh.329.2023.12.14.05.26.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 05:26:43 -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 4D842823B3E3; Thu, 14 Dec 2023 05:26:39 -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 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=ham 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:39 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785263977228902586 X-GMAIL-MSGID: 1785263977228902586 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);