From patchwork Mon Jun 26 17:35:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113070 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7651258vqr; Mon, 26 Jun 2023 10:49:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5JQ+NT4HUQ++6VdsEfYy0pHC/0G7dzbUiHctikKIBXPojLhREhyxqUEZMddtvBfVMGkcxZ X-Received: by 2002:a05:6402:1290:b0:51d:a237:d45b with SMTP id w16-20020a056402129000b0051da237d45bmr1428225edv.36.1687801758215; Mon, 26 Jun 2023 10:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687801758; cv=none; d=google.com; s=arc-20160816; b=tZI3kqRe3+pVYpaOI5/gl9taDBK3uRuUgWo1UgwsGu5LdPzgEtuBTs5dt2K8CoUbph NSvxgAn0xOI62RrsVSj7lU6G6Mm2Md/a/wTmYn1kqFwiaVzCn6VsqlDXIR+zrHa6IiV4 TrdOFasDvegRY+JC41tqyCjEJVFqFuOzDQilETkRQvttUM+RLn/d7OXuJAwYao7idCHb D1clkwp2kmy0hupYDnGLR7VnOrc9oLdKjPkXgTDmCRz2CGm4EEl2YAgLN+nAkVUTzPs+ 1btcd06opsaHPtJbwWiV2KGXXxMQtEJ4lrVrdGSml76aCCMSG7c7PHen6ECWf+vofNLN Ro/A== 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=E3aum7WU0bI7IZ184SOLo7ZVUjIFr4d1vA4qDi5sBMk=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=AE1uU56I43LplYEduU/ALXm6Kqn3HBZfynyrsznYzHHzbqiBILQrufULBRtQ1g92X9 dJXiywvvVnzWfXr7L5zZ+WAgiOLzqcbvQM35yp5fsTA1CYuUrp84UJm1VJqM0upFUIMy kQqp6gqi9UPO52oDBWEpx4ajMrEVRutsMqxSi7DSpuVoovvJO9jmJFK/W8l/O03L1IFl GAe8PF4cUCb/MBnLSoUiaKXoWqXBXVsJFtebemhUbF6MqOTEB9Lui+uIZwZsaLpTeznV cjtOUlFZ1pe6c9Vj2IPSPFuVlVyIoyz2rur+40ImYBmdT2dE/knFqnwC+WvEPusWJKas yBFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=rbgGQajz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f19-20020a05640214d300b0051da01194a1si872798edx.164.2023.06.26.10.48.53; Mon, 26 Jun 2023 10:49:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=rbgGQajz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231365AbjFZRg2 (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230189AbjFZRf6 (ORCPT ); Mon, 26 Jun 2023 13:35:58 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7458E2947; Mon, 26 Jun 2023 10:35:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=E3aum7WU0bI7IZ184SOLo7ZVUjIFr4d1vA4qDi5sBMk=; b=rbgGQajzMWS1Zvm8l8B087MlBY fs44oUGNMU1wvCmN1CEVg8sLCwUHuiJlE08WOgKcUUJtDr9vSnXdpzQu4hlEVqGAcXaOveiLHWRJ1 1u6GHkry9xBdQ+r/N6cioIMqR/K0lH0Jf8YA7KNQuh3yKOHri1HNfo7aRakN0NWaL9VTHfI+TFQux TOzoFNpy0Ud+oGkcZUrTaqQ9Vujxhrvbn5RT2aQviJhsaKZjlRED4Zewl45kh+nmk/MNYILFiyZO1 5iKDAXUGwGzrxMmiWKexkmO63AcO7cu39YjbMncfmuaVnM7mc9wjySOtqZrDnAo8xwQ4xeVmtsNpf ddtVl8Nw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vVG-VE; Mon, 26 Jun 2023 17:35:24 +0000 From: "Matthew Wilcox (Oracle)" 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/12] writeback: Factor writeback_iter_next() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:18 +0100 Message-Id: <20230626173521.459345-10-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230626173521.459345-1-willy@infradead.org> References: <20230626173521.459345-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769788416108524207?= X-GMAIL-MSGID: =?utf-8?q?1769788416108524207?= 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) --- mm/page-writeback.c | 84 ++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 659df2b5c7c0..ef61d7006c5e 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, @@ -2438,7 +2438,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); @@ -2473,6 +2473,45 @@ 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) +{ + 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 + + folio_nr_pages(folio); + 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. + */ + 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 @@ -2513,46 +2552,11 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_folio(mapping, wbc)) { + folio = writeback_iter_next(mapping, wbc, folio, error)) { error = writepage(folio, wbc, data); - 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 + - folio_nr_pages(folio); - 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. - */ - 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);