From patchwork Mon Jun 26 17:35:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113068 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7647594vqr; Mon, 26 Jun 2023 10:42:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6nqdsXH3SIg3fBxgGXyiCfCppZNqyQr4RiHJntVoiyCtcQsEfHNJY7tSLagqTRuJvrLptp X-Received: by 2002:a17:907:2683:b0:975:63f4:46 with SMTP id bn3-20020a170907268300b0097563f40046mr24660086ejc.57.1687801324045; Mon, 26 Jun 2023 10:42:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687801324; cv=none; d=google.com; s=arc-20160816; b=xy1KJvpLcLRQ2BKUHeCkEgx8+qmzqLfgUGS6XUBzJKrgmOWNHs7u0t5bJHCxNykSKJ cvI/J7AZ5tnI3qLvfCK97VyfF1aiGaRe+SrEEH5hwACP+4ZHnwffxvK/GuNUsvKEzduA KKlOErPRCJFB8XLpH46sZos6uMbMTlriQ9tJS4dp140++xX+VtOTIWPPDxVWUlRnqO8u +LyGvcxmf6NX77qBnyF19la5a+iaMVwddbYgvaTu0Z+SHTPBa6ZkyTr0eCzWsJoYUroZ zv6FmegQFXjFxKK9CIifcJw6TicrVjAoP/6aP8NzNtETYgqwlEB6EcuAVrjg/cdYhZY6 HCQA== 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=X5nRO0yDxZXWnd7LdLo4tOM7JIHXSxr3v1Ba4laEERQ=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=v+f2+F3eQ6ORPXhRLrox1KTqX4RbnMeHDcxsPx5JcazW0KhA/aBh3pZFuri5ka9Q6u Z9PDHR70sKbgY8/TABXNi8lU6gS9pve1uh14Hr+pD6BiJokpZ/+OWrWiDERwzGQFY7VL UoAU569KyGIjFE8/9UWMpr+GovHkumspvTjQhW/1wgz5EepRTGlCQkwjzYk9Wsbdtvqa yijSWsEeQDLd88AMfN3p3p34s9g370feZ1iT0aFLksbcAXxR50USMOVXErPowXHAh4Fq Nb/+DJETGZmGWWDbfH3kbKsC8V1YQdH3ILFdAoSv+ShxXJiF2UJCmfDwPWxorsAxQnpM gyjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=dHEryiCM; 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 kk22-20020a170907767600b0098e422d6761si1962436ejc.287.2023.06.26.10.41.39; Mon, 26 Jun 2023 10:42:04 -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=dHEryiCM; 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 S231240AbjFZRgZ (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbjFZRf5 (ORCPT ); Mon, 26 Jun 2023 13:35:57 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B02B2943; 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=X5nRO0yDxZXWnd7LdLo4tOM7JIHXSxr3v1Ba4laEERQ=; b=dHEryiCMCiT4PhowBmljTazeb4 RfsGun/8AwiFhnxjHPY2gvtCCziQPaTgjIcWGU73SOzA0fIcWSc+KbOLrgdYC4Zw96YeQhBZRALK/ NSBPdxwMWaRAijWdgrt+j34hxyho6y0P1lr64rSX2UkSY1tDGNfQdbrrGFebrtmHVEhAv0KlkYeFU ujdjqmyJB88r6R4mfBfQoxY25rsKXKRMoVEo5+adJIWvQ62By9WrCtZs+R2PDfdlY39s3mGEwpvNk KHhl2zlWg2zGwPsq6yaIwOvK4o9yUved9e1DKnPqix1EiRAggAwzHGMIQkutgfy3RkGGM5orcLDHJ 6asH01mQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vUz-9V; Mon, 26 Jun 2023 17:35:23 +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 01/12] writeback: Factor out writeback_finish() Date: Mon, 26 Jun 2023 18:35:10 +0100 Message-Id: <20230626173521.459345-2-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?1769787960814881122?= X-GMAIL-MSGID: =?utf-8?q?1769787960814881122?= Instead of having a 'done' variable that controls the nested loops, have a writeback_finish() that can be returned directly. This involves keeping more things in writeback_control, but it's just moving stuff allocated on the stack to being allocated slightly earlier on the stack. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/writeback.h | 6 ++++ mm/page-writeback.c | 74 +++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index fba937999fbf..5b7d11f54013 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -11,6 +11,7 @@ #include #include #include +#include struct bio; @@ -52,6 +53,10 @@ struct writeback_control { loff_t range_start; loff_t range_end; + struct folio_batch fbatch; + pgoff_t done_index; + int err; + enum writeback_sync_modes sync_mode; unsigned for_kupdate:1; /* A kupdate writeback */ @@ -59,6 +64,7 @@ struct writeback_control { unsigned tagged_writepages:1; /* tag-and-write to avoid livelock */ unsigned for_reclaim:1; /* Invoked from the page allocator */ unsigned range_cyclic:1; /* range_start is cyclic */ + unsigned range_whole:1; /* entire file */ unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */ unsigned unpinned_fscache_wb:1; /* Cleared I_PINNING_FSCACHE_WB */ diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 1d17fb1ec863..abd7c0eebc72 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2360,6 +2360,24 @@ void tag_pages_for_writeback(struct address_space *mapping, } EXPORT_SYMBOL(tag_pages_for_writeback); +static int writeback_finish(struct address_space *mapping, + struct writeback_control *wbc, bool done) +{ + folio_batch_release(&wbc->fbatch); + + /* + * If we hit the last page and there is more work to be done: + * wrap the index back to the start of the file for the next + * time we are called. + */ + if (wbc->range_cyclic && !done) + wbc->done_index = 0; + if (wbc->range_cyclic || (wbc->range_whole && wbc->nr_to_write > 0)) + mapping->writeback_index = wbc->done_index; + + return wbc->err; +} + /** * 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 @@ -2395,18 +2413,12 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { - int ret = 0; - int done = 0; int error; - struct folio_batch fbatch; int nr_folios; pgoff_t index; pgoff_t end; /* Inclusive */ - pgoff_t done_index; - int range_whole = 0; xa_mark_t tag; - folio_batch_init(&fbatch); if (wbc->range_cyclic) { index = mapping->writeback_index; /* prev offset */ end = -1; @@ -2414,7 +2426,7 @@ int write_cache_pages(struct address_space *mapping, index = wbc->range_start >> PAGE_SHIFT; end = wbc->range_end >> PAGE_SHIFT; if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) - range_whole = 1; + wbc->range_whole = 1; } if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) { tag_pages_for_writeback(mapping, index, end); @@ -2422,20 +2434,24 @@ int write_cache_pages(struct address_space *mapping, } else { tag = PAGECACHE_TAG_DIRTY; } - done_index = index; - while (!done && (index <= end)) { + + wbc->done_index = index; + folio_batch_init(&wbc->fbatch); + wbc->err = 0; + + while (index <= end) { int i; nr_folios = filemap_get_folios_tag(mapping, &index, end, - tag, &fbatch); + tag, &wbc->fbatch); if (nr_folios == 0) break; for (i = 0; i < nr_folios; i++) { - struct folio *folio = fbatch.folios[i]; + struct folio *folio = wbc->fbatch.folios[i]; - done_index = folio->index; + wbc->done_index = folio->index; folio_lock(folio); @@ -2488,14 +2504,14 @@ int write_cache_pages(struct address_space *mapping, folio_unlock(folio); error = 0; } else if (wbc->sync_mode != WB_SYNC_ALL) { - ret = error; - done_index = folio->index + - folio_nr_pages(folio); - done = 1; - break; + wbc->err = error; + wbc->done_index = folio->index + + folio_nr_pages(folio); + return writeback_finish(mapping, + wbc, true); } - if (!ret) - ret = error; + if (!wbc->err) + wbc->err = error; } /* @@ -2505,26 +2521,14 @@ int write_cache_pages(struct address_space *mapping, * we tagged for writeback prior to entering this loop. */ if (--wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) { - done = 1; - break; - } + wbc->sync_mode == WB_SYNC_NONE) + return writeback_finish(mapping, wbc, true); } - folio_batch_release(&fbatch); + folio_batch_release(&wbc->fbatch); cond_resched(); } - /* - * If we hit the last page and there is more work to be done: wrap - * back the index back to the start of the file for the next - * time we are called. - */ - if (wbc->range_cyclic && !done) - done_index = 0; - if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) - mapping->writeback_index = done_index; - - return ret; + return writeback_finish(mapping, wbc, false); } EXPORT_SYMBOL(write_cache_pages); From patchwork Mon Jun 26 17:35:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113083 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7666534vqr; Mon, 26 Jun 2023 11:13:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Kkk3t3YSBlu9Q5nG8gWwbg9m9eVkukYzyENStVtGg/j7q2tB3pL6GJMwbzMO9OatDHLNS X-Received: by 2002:a05:6808:4246:b0:398:2c02:20a2 with SMTP id dp6-20020a056808424600b003982c0220a2mr24170204oib.17.1687803214799; Mon, 26 Jun 2023 11:13:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687803214; cv=none; d=google.com; s=arc-20160816; b=Llo5DBKKAVwQ7qOSPZ41n0bgkOOsESIJNNhwl63KlSJP6bG1VO6EEgtVylbPY3ZjL1 fXFSJw6EfL7KdhYRGGGNmVvP1IQ8lTk/v5YcFCvQD2Xoh6M1QA+UcFoP4gDRKbBaNfdy 0N3NSSstrKjO88lpZODALkXaoRgmpzv7o3TU3tNtucexymBqsqnqmH+EZ1rXbKYtuPov qsO7mt/ZXOzGtwB3IxdeJdn710srmXjOBYpV6DV+iEw4AjtKpr2n0E2eFFaPgQQgRu1o EiONX5iphAAZKJqRI9EUp7Zhu1nf/W/q4HPvCHyMklwwKUGa26t7iibbFq1hf4aDqPtk VK1w== 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=Eb8+i22W56HZAod8nWQSK472UiI/gYMP48K8do/ME/8=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=hXGdC7lRRxlG/XEvNGSXU/wFCZTH2SHyaBZpzRq0THRcEAwplw9lTDjYWzpxexppTD 3DCCyQOGs1L5wGMH3CO29wHVMOSTE39sZSYY6yRSf4Q+ZO+XKmIn+F6n9cDZIxrPabCY WIFXvz46sPJZz6xrXz8s1EIP/YyVapXQyo2DWRDGgKUCrxmWHNVKqsyMLyDmKrnAXfUD 0V29wUOq9c3BDARz+gd9FN9H2ysNymcRpgLftw7QC4bKOk6F2gCIxLJ/jpgrBx9t1yPD yXsrHGRlKNPV/M/kVaJoH5o/6NACMP4rLiq7viXQf2EUnhMD+q7TemqHPVvibJGCMBbh UQ4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=I8BvqJCH; 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 k10-20020a17090a9d8a00b00260a6621b4bsi8086060pjp.117.2023.06.26.11.13.20; Mon, 26 Jun 2023 11:13:34 -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=I8BvqJCH; 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 S231518AbjFZRhg (ORCPT + 99 others); Mon, 26 Jun 2023 13:37:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbjFZRgO (ORCPT ); Mon, 26 Jun 2023 13:36:14 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22D2C170D; Mon, 26 Jun 2023 10:35:44 -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=Eb8+i22W56HZAod8nWQSK472UiI/gYMP48K8do/ME/8=; b=I8BvqJCHhBej30amkNnVaHN6rH u9uO/sVt2f+jz7JcGOSx+zl/f70NIeziA/OlCB4o62GnbbwwGLVv/hBjABtamZ47YbH1j4ZOO4hoc QRtJcd7ZjBN83uepkFoGD0dLghMKRhe+wpJC6dFdWan3E0U1OHu3sqtiCt8ZD7+zxqDSwb0Vbi5uq nOyJHt2ANqAHJbdn5QtHLs8S1Ecyurt3g/m+y5pugk3uH39x/eU2jWFeYf7aR2cgIn9Y2zwwl/ozy mNgR7J1eV9HCBuDFaS061IwieX96E0vWyEzjHBhaHEzX9wLQ2iAiERfPCLB4uIn1bhmMDv7lULBmZ j2uURkZQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV1-CW; Mon, 26 Jun 2023 17:35:23 +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 02/12] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:11 +0100 Message-Id: <20230626173521.459345-3-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?1769789943375167587?= X-GMAIL-MSGID: =?utf-8?q?1769789943375167587?= This simple helper will be the basis of the writeback iterator. To make this work, we need to remember the current index and end positions in writeback_control. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/writeback.h | 2 ++ mm/page-writeback.c | 49 +++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 5b7d11f54013..7dd050b40e4b 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -54,6 +54,8 @@ struct writeback_control { loff_t range_end; struct folio_batch fbatch; + pgoff_t index; + pgoff_t end; /* Inclusive */ pgoff_t done_index; int err; diff --git a/mm/page-writeback.c b/mm/page-writeback.c index abd7c0eebc72..67c7f1564727 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2378,6 +2378,22 @@ static int writeback_finish(struct address_space *mapping, return wbc->err; } +static void writeback_get_batch(struct address_space *mapping, + struct writeback_control *wbc) +{ + xa_mark_t tag; + + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag = PAGECACHE_TAG_TOWRITE; + else + tag = PAGECACHE_TAG_DIRTY; + + folio_batch_release(&wbc->fbatch); + cond_resched(); + filemap_get_folios_tag(mapping, &wbc->index, wbc->end, tag, + &wbc->fbatch); +} + /** * 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 @@ -2414,41 +2430,32 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; - int nr_folios; - pgoff_t index; - pgoff_t end; /* Inclusive */ - xa_mark_t tag; if (wbc->range_cyclic) { - index = mapping->writeback_index; /* prev offset */ - end = -1; + wbc->index = mapping->writeback_index; /* prev offset */ + wbc->end = -1; } else { - index = wbc->range_start >> PAGE_SHIFT; - end = wbc->range_end >> PAGE_SHIFT; + wbc->index = wbc->range_start >> PAGE_SHIFT; + wbc->end = wbc->range_end >> PAGE_SHIFT; if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) wbc->range_whole = 1; } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) { - tag_pages_for_writeback(mapping, index, end); - tag = PAGECACHE_TAG_TOWRITE; - } else { - tag = PAGECACHE_TAG_DIRTY; - } + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc->end); - wbc->done_index = index; + wbc->done_index = wbc->index; folio_batch_init(&wbc->fbatch); wbc->err = 0; - while (index <= end) { + while (wbc->index <= wbc->end) { int i; - nr_folios = filemap_get_folios_tag(mapping, &index, end, - tag, &wbc->fbatch); + writeback_get_batch(mapping, wbc); - if (nr_folios == 0) + if (wbc->fbatch.nr == 0) break; - for (i = 0; i < nr_folios; i++) { + for (i = 0; i < wbc->fbatch.nr; i++) { struct folio *folio = wbc->fbatch.folios[i]; wbc->done_index = folio->index; @@ -2524,8 +2531,6 @@ int write_cache_pages(struct address_space *mapping, wbc->sync_mode == WB_SYNC_NONE) return writeback_finish(mapping, wbc, true); } - folio_batch_release(&wbc->fbatch); - cond_resched(); } return writeback_finish(mapping, wbc, false); From patchwork Mon Jun 26 17:35:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113085 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7666702vqr; Mon, 26 Jun 2023 11:13:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6zz1wa1n0cY1BwcaoS63qV8RAg/KR8S7cqhkmu0aXH6QpIV+4DVhYreMgQOB0f9QSoe7xq X-Received: by 2002:a17:903:24d:b0:1ae:8595:153 with SMTP id j13-20020a170903024d00b001ae85950153mr10927903plh.20.1687803236046; Mon, 26 Jun 2023 11:13:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687803236; cv=none; d=google.com; s=arc-20160816; b=kdyj2GzzR7n/ymYjvBJvaqAD+ZC40nm7cU3BZ5FCc3053yVS8dB/ek/ikeYVy2LIuF +t9X9Whxsk/dKS2wyz8TIyFHK525GOJ0uuxBI6u9JyvP+/F63+H3GOMfFk9NJ75DW3qc Jy+1A5haR7HMS+ypXHBzAyR9W/bhGVDLYTsFKwUCFNrvbxhbJq+mWQPMbmAVz9Twpffi buxlnNNSs+1bI5/gEr033ue4sW1jHeVPeCKSR6fPjAC/ZrkqbO6asPX0LxIj5EgIkUdB FvL9XcutOtTrKS3L7I/L5v0f62Gya/PmYem5PEEcv25rFVa01hzR5SgeQRq/ENIv4B8b bPtg== 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=v6PqW+r7ocyNrYaEadNjC9yXbOPBKSknhOaHoHVmJpk=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=sJkiDbuJAj3qK/CKD4KgReby+BcM3TPIBYFwxiiJE6KuGrfRW22IjMKcKNo86h1h9W /Iz9XEbYHiFBhYjx1agJifaPBkPkPx3xx+eSuTJvkjy7UAB9J/FknkLdaCBbJeIXz0jw 9/HltpOWcs/r3Umm2EBhlzh1qyZUB5fF2bSidaamxzqc/sUfIz2lDtWnP9/Rj64gHoEB sN2QrVjBOJYaAblXXlOUJoAEgTShYnzj2Ub0Y+tAOFBAx1PzcZIIGknA9k57YOqvvhUB FUVS7xAJz7uASxrFSSitK6IATGkAo4jMzQkt+oBd394R+bKcIxhXBZe6lXnoYtkfyv8H dq3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=GH5JrXCe; 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 n12-20020a170902f60c00b001b5621062c4si5303204plg.151.2023.06.26.11.13.42; Mon, 26 Jun 2023 11:13:56 -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=GH5JrXCe; 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 S231294AbjFZRhy (ORCPT + 99 others); Mon, 26 Jun 2023 13:37:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231175AbjFZRgS (ORCPT ); Mon, 26 Jun 2023 13:36:18 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71AA32D4F; Mon, 26 Jun 2023 10:35:47 -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=v6PqW+r7ocyNrYaEadNjC9yXbOPBKSknhOaHoHVmJpk=; b=GH5JrXCeoj/GgOPu3iWjttA4pE R9WD1MiCBTid7jEiZMHLeGsbpndBGL7pWST3FhxBWC5vruJtb8/vXrvH0+f62gbXnsXZRlsky8pJq 9+M9D8g1czSuBHKCI6CMEd9w5TLyOR/pLQ95L/J/rI+M7DmyKqKs1a6+MLyLQd2/ds8H1fO846FuZ n8cEC0dArDnoP6JGY1ECb59L60b5jQv8FpFk5u65nzfMXMt5F7+6Z/YkjT4frnabjEqYJXLozDGS7 3U7dQlvwCi5sQU/ji6nNPG8IbAEl5U5k7LHM+ju+XzD5CgDWD6fjTcbsn7X1Y6zVcs+D6Xlzu9mZ+ XAvaJBew==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV3-FD; Mon, 26 Jun 2023 17:35:23 +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 03/12] writeback: Factor should_writeback_folio() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:12 +0100 Message-Id: <20230626173521.459345-4-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?1769789965859594158?= X-GMAIL-MSGID: =?utf-8?q?1769789965859594158?= 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) --- mm/page-writeback.c | 60 +++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 67c7f1564727..54f2972dab45 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2394,6 +2394,37 @@ static void writeback_get_batch(struct address_space *mapping, &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) + folio_wait_writeback(folio); + else + return false; + } + + 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 @@ -2461,38 +2492,13 @@ int write_cache_pages(struct address_space *mapping, wbc->done_index = folio->index; 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); if (unlikely(error)) { /* From patchwork Mon Jun 26 17:35:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113071 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7651266vqr; Mon, 26 Jun 2023 10:49:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4jx8BrISiSBWtlq1cU7SlCS99x8rz5jTemFrCrWRy2F/wmXHOyzD71m8Sza9IZwWtGsFyv X-Received: by 2002:aa7:ccd1:0:b0:51d:9149:6311 with SMTP id y17-20020aa7ccd1000000b0051d91496311mr4013388edt.6.1687801759553; Mon, 26 Jun 2023 10:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687801759; cv=none; d=google.com; s=arc-20160816; b=bOJrLjEsx/hd57CyA/T2xiBQYEpBThGFKUUaYzn6K3C7GjPFDr5B8U9L/3dh64kPHH /KsW0AsZ3g1RRd4DB+JZ0Qhz8VYDCTfjYMCNC73mIhs7vO68f3j8+/lEWHAAoo1wIlF3 3sesF7aVa1iYO4l1RKxXnkOx8K7f0U+ElNN7c284CCNfHI4R6W03URuQ/WRUBOCBGYfA 05FJxyHyOh0ZkcFHUsC7KiGlOUPi7AX11HM8qJW1u8Q821UdUBX5UHfUz1KMHb9f8Sz9 6GViHK2hvvLXH95GUsaZGyrr+f5ClYIewFmNzdKMQaNpijWfiLAgcVhYQjHTPZELOr1B zF1w== 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=Hry/pakf3XrjxtX3FxEBHlEHaVaCFV/OlgXU52VAJV8=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=oXf4e7MMId7ny143GB8cEuKLT5YJTTUCvJoZ+obH3UyA/QsKYy82/CI6ULNV406kTd TyS3fkZwBcdvnkUDQuuMgYKF4vSE3hNu9uVi9UuuAX6jafQTed5rv01d2KxswKcrbI+y o+edLWW82bYQ7hFmPk8xQFI48tfDcLRVVIIW18hoU95wR4OYkp0tr+KGChpP1ti1wvER austE9t1hiOYljrwEKcGnkV3aUjxySap4K4sNzRV3aXLhJcucOx3SJPaQ2G6GKxGkkw3 pCCn5x6ZBphq3EjhmLIZvAE5mImRl5jyQahneZJN0WnrNVrqNNRwgR28Uufwdhe0HXfB PKsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=jW+KKslS; 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 z8-20020a50eb48000000b0051bdf8b726bsi2826639edp.623.2023.06.26.10.48.54; Mon, 26 Jun 2023 10:49:19 -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=jW+KKslS; 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 S231493AbjFZRhR (ORCPT + 99 others); Mon, 26 Jun 2023 13:37:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbjFZRgH (ORCPT ); Mon, 26 Jun 2023 13:36:07 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 246EC10D7; Mon, 26 Jun 2023 10:35:41 -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=Hry/pakf3XrjxtX3FxEBHlEHaVaCFV/OlgXU52VAJV8=; b=jW+KKslSaTipXxmpNDSSeOnylL hzbQCyN3wKzjlszSqjc4HEgvviOgGGjspRJs0Vjv5zO3/R9XMbjtxpTsmS+9Gcwuw/ZcmCCyUnNeN H4tbBHnB66YtrhxCVg35T1Z99VBOHuc93t96BguJpmXgSVovFmRpL3E4/mslcgF20oYguKO1t+f7E aUfCqCMqXZB9pkY6yvUPK4VnHdbnXMwfDHnVDWMQUOAefkCf44Iu/CmD4lgC7Vnrxqd1w5+fQwu8z //QbapaLS3fMPaq6e7Ev6OQIihxf6gBxNalmqp3q/qnWQWabKWAZg/iTq63WdoLJnsWBSSCUnMJEx OM6BZUcg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV5-HI; Mon, 26 Jun 2023 17:35:23 +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 04/12] writeback: Simplify the loops in write_cache_pages() Date: Mon, 26 Jun 2023 18:35:13 +0100 Message-Id: <20230626173521.459345-5-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?1769788417878998309?= X-GMAIL-MSGID: =?utf-8?q?1769788417878998309?= Collapse the two nested loops into one. This is needed as a step towards turning this into an iterator. --- mm/page-writeback.c | 94 ++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 54f2972dab45..68f28eeb15ed 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2461,6 +2461,7 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; + int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2478,65 +2479,64 @@ int write_cache_pages(struct address_space *mapping, folio_batch_init(&wbc->fbatch); wbc->err = 0; - while (wbc->index <= wbc->end) { - int i; - - writeback_get_batch(mapping, wbc); + for (;;) { + struct folio *folio; + if (i == wbc->fbatch.nr) { + writeback_get_batch(mapping, wbc); + i = 0; + } if (wbc->fbatch.nr == 0) break; - for (i = 0; i < wbc->fbatch.nr; i++) { - struct folio *folio = wbc->fbatch.folios[i]; + folio = wbc->fbatch.folios[i++]; - wbc->done_index = folio->index; + wbc->done_index = folio->index; - folio_lock(folio); - if (!should_writeback_folio(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } + 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); - 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; - } + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); + error = writepage(folio, wbc, data); + if (unlikely(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. + * 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 (--wbc->nr_to_write <= 0 && - wbc->sync_mode == WB_SYNC_NONE) + 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); From patchwork Mon Jun 26 17:35:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113074 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7653606vqr; Mon, 26 Jun 2023 10:54:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4t73je8qI3KyHzY9S1yPeRsNcqbsYjdX1JAkmy8nPy+jbJEjbyOj8zN8ysIflczTkGBnmu X-Received: by 2002:aa7:db4f:0:b0:51a:5ac3:4df8 with SMTP id n15-20020aa7db4f000000b0051a5ac34df8mr14648361edt.5.1687802054588; Mon, 26 Jun 2023 10:54:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687802054; cv=none; d=google.com; s=arc-20160816; b=oggCHQwHZ4s94FK0hn+jxYdQ9ro/e9vVSSHQRzBqglKY+Vs8TT9OorppQUW1F0vS4I t/8ur5KMSgcr2d2kD2dXQLRvHNW/TO1Niau3PXe67g60M9oD7/n9nNmu8Dj9KUS1PPHu 8WhpAmRT9xuR7Ea2trw5GXbSyp407JOpU14pWbkt+a1AfhigLQbwQyBE+OzH3/icIoEs WIl8y8ptFZLkTySxxH3Sr258xZS/ePLiKTi/SGPQ/ssEUGrr70x97yzhxC4hfsdrGiTD 8u1Nr/hUltRNRbCMRBsvJp11CSt+x++ZQlqfkv2RVry1aA1TQdlPMivdkU0h02eXaHur x7ug== 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=E+4oLVAPfstR5U6aMi6Troa+YNi9gddz/xau+Gpg+rc=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=i6Hj1+oTUIPd1aJO57A3kC5V6GvYdndkh2Xyx7f4FaDtrrJczlmfNTdeR90iJD3qBR NVZNh1iH8gaq4XNbhOlhoW64EU/r8cSWjNaCYZgbABRRwOamFKMEsfQXVQzMvlDtn4Ia h3fmlQqGCbOlwaYx18Y8XF/++qw2HIhrHOOpCLFffrTUBRp8uqmWq9kxpmPEESbCatvR 1/CcPLHhgjfKpDTGxEM6kxec6DiMHZ/jZj1CrX1orHPVi+Ih4luYSsvLElp2xtoBID3j s9zwejOOz/VOVPu+EsYyq164ebMPaKO0WWI6xUR4ZRzXmwt34grqexr4WgJCwX+N9YB9 klLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=UixsKVyP; 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 y21-20020a50e615000000b0051a52a48ed4si3143288edm.156.2023.06.26.10.53.50; Mon, 26 Jun 2023 10:54:14 -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=UixsKVyP; 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 S231433AbjFZRgr (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjFZRgB (ORCPT ); Mon, 26 Jun 2023 13:36:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 302162952; Mon, 26 Jun 2023 10:35:32 -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=E+4oLVAPfstR5U6aMi6Troa+YNi9gddz/xau+Gpg+rc=; b=UixsKVyP80nb0Gf7F4Lg+jN462 veiCIiZ5m1gznewobjOw1LIlCVl+NQ9bzKtGc1cy/FIFA2ZFOyC31yskGu3ZRnQRQ486TqTOhj/gr MYy4BGRtCU3MWPXCVKFnpYRI0SO+7rxcxT4MHuv18Sude5qsPpa5V0wVCVDJPMg+CxWSEWOj5iYYW AJDD8UCC+LOhQrktHVtCdUQ+V85q2O0pIp+RIDy4myAwlxwJ/KnWBqgsQgybdKyrahLZIt/KPAliX Z7BL5LWIbRipCNRi/kU84/66Ojv2G0K94IDEtnbMk2QxnYFxyp6hwCZ51e4XG35VOJT7z4XE1c+22 +qrDsMow==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV7-Jz; Mon, 26 Jun 2023 17:35:23 +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 05/12] pagevec: Add ability to iterate a queue Date: Mon, 26 Jun 2023 18:35:14 +0100 Message-Id: <20230626173521.459345-6-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?1769788727111366303?= X-GMAIL-MSGID: =?utf-8?q?1769788727111366303?= Add a loop counter inside the folio_batch to let us iterate from 0-nr instead of decrementing nr and treating the batch as a stack. It would generate some very weird and suboptimal I/O patterns for page writeback to iterate over the batch as a stack. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagevec.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h index 87cc678adc85..fcc06c300a72 100644 --- a/include/linux/pagevec.h +++ b/include/linux/pagevec.h @@ -27,6 +27,7 @@ struct folio; */ struct folio_batch { unsigned char nr; + unsigned char i; bool percpu_pvec_drained; struct folio *folios[PAGEVEC_SIZE]; }; @@ -40,12 +41,14 @@ struct folio_batch { static inline void folio_batch_init(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; fbatch->percpu_pvec_drained = false; } static inline void folio_batch_reinit(struct folio_batch *fbatch) { fbatch->nr = 0; + fbatch->i = 0; } static inline unsigned int folio_batch_count(struct folio_batch *fbatch) @@ -75,6 +78,21 @@ static inline unsigned folio_batch_add(struct folio_batch *fbatch, return folio_batch_space(fbatch); } +/** + * folio_batch_next - Return the next folio to process. + * @fbatch: The folio batch being processed. + * + * Use this function to implement a queue of folios. + * + * Return: The next folio in the queue, or NULL if the queue is empty. + */ +static inline struct folio *folio_batch_next(struct folio_batch *fbatch) +{ + if (fbatch->i == fbatch->nr) + return NULL; + return fbatch->folios[fbatch->i++]; +} + void __folio_batch_release(struct folio_batch *pvec); static inline void folio_batch_release(struct folio_batch *fbatch) From patchwork Mon Jun 26 17:35:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7645560vqr; Mon, 26 Jun 2023 10:38:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ57aGFuzOHfdM34wCwfwGPE286f9vqGLlHV8GAWIH8fBB0ZbfFF8waxhAxyj5gtT0r6y45S X-Received: by 2002:a05:6a20:938f:b0:10c:322:72d5 with SMTP id x15-20020a056a20938f00b0010c032272d5mr38812177pzh.23.1687801087515; Mon, 26 Jun 2023 10:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687801087; cv=none; d=google.com; s=arc-20160816; b=CaFKA1mJBGwwqOabEV2IZpIFH8OZG4JdfGG+ca20CSBKSW1jSiPaetjzDvfZcPJuY5 bRhy2af/Y92iSHUs85o5BlABfroElVNv+7/qWp1uwUBsQtYqU21XZtVM2vjJlGo6CNTU 1mhmZaiMnrcP1NjrdMZGf3rLGn8+avz2TXW7Pp/nNlD+Erfxut0wYZNEv9s36j7hlu6K eg8VANl7yQE2uzB0FV1ZhMG7VvdIUpNSx5yR2NZeL3cPFMzuR2/GkYy4IVOkf+WFVzCA phgZf4zMGGlF4L5JsUmRwGf2Pcz6DBiSGwkGVCOk6wPg9rL+SK2B29YLzNsN7o4Ve5g5 EafQ== 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=9GHSvlYBgCYCqD7sma1ZZnKYfGDXP4peUgN6BejXrU0=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=PqvEuCiF9b7HIqbAP0NWOBg2ZxC8W1JawZvvYP6x3MQWqIceffUrKyAZnNzUdQjAtp Rx9/m0+fgOPmQ3SRR1BQdm3tXP+6zpvQvWxKyGokQYZR9ko/HIp5PEM64dd7jQQ0HJzk sB1AUJOnf3tTBv4JzDcQc/DcGRUTKLrDxi0pSsTXr210eGo04MIdgYk2lL5Vp3uJlbzk 4cFFcrfjDRKURBy7qeLcAYkJ4xdO1I/LZCRCaRxbHB/db/bJTW8QZY3xtvAcmKy3nCJN CtboX4FPd1XlBLARcciti8YfpWxytNCntOZe9ZCB7EembaHfyBQ9rf/+ErQoj0Iu8Fh+ uaiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=H2DjqGYq; 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 v15-20020a056a00148f00b00652c20d3522si908762pfu.303.2023.06.26.10.37.55; Mon, 26 Jun 2023 10:38:07 -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=H2DjqGYq; 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 S231451AbjFZRgu (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbjFZRgB (ORCPT ); Mon, 26 Jun 2023 13:36:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21687295B; Mon, 26 Jun 2023 10:35:35 -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=9GHSvlYBgCYCqD7sma1ZZnKYfGDXP4peUgN6BejXrU0=; b=H2DjqGYqS0ifPU6GyJXK8/BxHu vFVfQGhUx+x0NN019oG/9u6ta/c935isFdskogz6Zi5wk9YpfV1rQeHd3yOr16sdWHX3Sm1wYo4Tl q8Fc6gm3j5a09vRX3D7oa0aXQ+iDxgDnkfjvdQIGdTEVvqcbxfdqAXQOe5yO1SaLR+j0jt7+c+sW9 Pf8KrI7ur+AjXLjxw7Oxzr9qKsXddBrG4X2eYIqgC9KINNGsUfczjLXew+6IH5c7gUiUOekAEY/4T S1ZXhpeY87W/eVlS6lP9H5r3hIaN6in+5mIpOPY/vuuee0LlE5XFsUlbax1JnG8mOLDe9HZw6BXwb 4sjyyKCg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vV9-Mf; Mon, 26 Jun 2023 17:35:23 +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 06/12] writeback: Use the folio_batch queue iterator Date: Mon, 26 Jun 2023 18:35:15 +0100 Message-Id: <20230626173521.459345-7-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?1769787713387034586?= X-GMAIL-MSGID: =?utf-8?q?1769787713387034586?= Instead of keeping our own local iterator variable, use the one just added to folio_batch. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 68f28eeb15ed..f782b48c5b0c 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2378,11 +2378,15 @@ static int writeback_finish(struct address_space *mapping, return wbc->err; } -static void writeback_get_batch(struct address_space *mapping, +static struct folio *writeback_get_next(struct address_space *mapping, struct writeback_control *wbc) { + struct folio *folio = folio_batch_next(&wbc->fbatch); xa_mark_t tag; + if (folio) + return folio; + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) tag = PAGECACHE_TAG_TOWRITE; else @@ -2392,6 +2396,7 @@ static void writeback_get_batch(struct address_space *mapping, cond_resched(); filemap_get_folios_tag(mapping, &wbc->index, wbc->end, tag, &wbc->fbatch); + return folio_batch_next(&wbc->fbatch); } static bool should_writeback_folio(struct address_space *mapping, @@ -2461,7 +2466,6 @@ int write_cache_pages(struct address_space *mapping, void *data) { int error; - int i = 0; if (wbc->range_cyclic) { wbc->index = mapping->writeback_index; /* prev offset */ @@ -2480,17 +2484,11 @@ int write_cache_pages(struct address_space *mapping, wbc->err = 0; for (;;) { - struct folio *folio; + struct folio *folio = writeback_get_next(mapping, wbc); - if (i == wbc->fbatch.nr) { - writeback_get_batch(mapping, wbc); - i = 0; - } - if (wbc->fbatch.nr == 0) + if (!folio) break; - folio = wbc->fbatch.folios[i++]; - wbc->done_index = folio->index; folio_lock(folio); From patchwork Mon Jun 26 17:35:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113082 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7665600vqr; Mon, 26 Jun 2023 11:12:12 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6uFJXqY+3Q6e2WSn4S0KmDeyrz27l621wFKGhfmTbKXCQhl4JbnVCN/ug2NduMVTsCVYbJ X-Received: by 2002:a05:6a00:2d04:b0:672:264c:e8cf with SMTP id fa4-20020a056a002d0400b00672264ce8cfmr5203855pfb.7.1687803132261; Mon, 26 Jun 2023 11:12:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687803132; cv=none; d=google.com; s=arc-20160816; b=NGGpzuAn4LHw1/M6kTaqhRFDZEk1juSzz9VZAKM8nZyLl2ipCT3P2uQrLIAUWewFyy lG5ogxNOcKnG6N6xtdnsKCpcR3/WV7FWP/QfjG87H79XRuaDMfrWZoy9PeyFtohGOBoN CnamBw19OvMo3aXrDn8zN4msvZ8jbjyicilHmNifFmjO1ooMTf+WDwTDJTcUKmmwBJT3 nxEXrScPa2P21YuSBp0EVCkXu5Lj+Eu4sgDAhgkaQgDLASMA6twTrmSUxayaoDalvGBK Gjx1AgyqNlaWwIxQQQvPpT171ip/7mQB9wQhbcoPumsH/TwwApEmECnL3QkKZ07w1aWW dtwA== 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=Rl4mK631QVfMYqrn657sw5cU2nYiKao9j/G8hhMJYQc=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=sKvg7Om6/RTagsJq1QES1i9EnhljfZYRc815wpvnfxO6LZQPqV+rC9qhoWakqgXqmQ i0Qsa+RPTaPRIts5TLOSXjFVzBGQeEYErfa/7KOxQXSiEHZRgDfAJgTuaRg8E58eBGRV MN1ABnlj5XKWr89/TJUax0VX7QekKL1ihsDPMdODc3QMnChuxzDfJPQUNsBq5wQ+U28U +9oPAY5CIQioghTzgpOBJcfPkWEAFLDhgECB/ihJUfTzbrxCa4JnntZ42qfUGcGnBJrZ Eogww1nzjj6ORZMZDxKjO/K8ENo4cyjaLWFdcB+yBfyc9n3GX2P9I612BJr8JPQvVvs4 rxow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=nbsu3asm; 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 cp27-20020a056a00349b00b00675807330bfsi3003999pfb.194.2023.06.26.11.11.58; Mon, 26 Jun 2023 11:12:12 -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=nbsu3asm; 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 S230087AbjFZRiD (ORCPT + 99 others); Mon, 26 Jun 2023 13:38:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229910AbjFZRhD (ORCPT ); Mon, 26 Jun 2023 13:37:03 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 757FB19A4; Mon, 26 Jun 2023 10:35:50 -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=Rl4mK631QVfMYqrn657sw5cU2nYiKao9j/G8hhMJYQc=; b=nbsu3asmGLUEUJkp+PGufwS657 4CnYI/PCw6l8Xww27U0CYRwuyhdw3qbIis63qGdeGzCtVLsJOFwYt3NxR09Tdc5xZeJfOY8HBxSpD ML123J3s2go0dLVKtO7JpczdsBdChbc2qdUxfvc7R/nlZz9ke8A7G0kVR8Pe3BeM8cYwULIOBI4va QsVz+e8awbc3irLZPqIwC6yclmfeLbv2Eyi3WV9YAYsgEKeC1gNGPKT8+flhqRnRCmJZMdmeKgqPH POUXY9Q1cVqApg0noTgC9DVH6ZMLKwAsYN6jYt4BOAsygoP/Us8PMzM8KNlDC/dCF+nMklunLylR/ u0gT4KlA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vVB-PR; Mon, 26 Jun 2023 17:35:23 +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 07/12] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:16 +0100 Message-Id: <20230626173521.459345-8-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?1769789857195471785?= X-GMAIL-MSGID: =?utf-8?q?1769789857195471785?= Make it return the first folio in the batch so that we can use it in a typical for() pattern. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 48 ++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index f782b48c5b0c..18f332611a52 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2430,6 +2430,28 @@ static bool should_writeback_folio(struct address_space *mapping, return true; } +static struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc) +{ + if (wbc->range_cyclic) { + wbc->index = mapping->writeback_index; /* prev offset */ + wbc->end = -1; + } else { + wbc->index = wbc->range_start >> PAGE_SHIFT; + wbc->end = wbc->range_end >> PAGE_SHIFT; + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) + wbc->range_whole = 1; + } + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc->end); + + wbc->done_index = wbc->index; + folio_batch_init(&wbc->fbatch); + wbc->err = 0; + + return writeback_get_next(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 @@ -2465,30 +2487,12 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { + struct folio *folio; int error; - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - wbc->end = -1; - } else { - wbc->index = wbc->range_start >> PAGE_SHIFT; - wbc->end = wbc->range_end >> PAGE_SHIFT; - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) - wbc->range_whole = 1; - } - if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) - tag_pages_for_writeback(mapping, wbc->index, wbc->end); - - wbc->done_index = wbc->index; - folio_batch_init(&wbc->fbatch); - wbc->err = 0; - - for (;;) { - struct folio *folio = writeback_get_next(mapping, wbc); - - if (!folio) - break; - + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_next(mapping, wbc)) { wbc->done_index = folio->index; folio_lock(folio); From patchwork Mon Jun 26 17:35:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113073 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7651824vqr; Mon, 26 Jun 2023 10:50:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7joGvFzWsayS74b4wsJ61MJrwbPv/m+wkS82u1EanDZrSz+j3bbmH90Kh4lrAWm445Mo5Y X-Received: by 2002:aa7:db51:0:b0:51d:a24c:db20 with SMTP id n17-20020aa7db51000000b0051da24cdb20mr1203303edt.18.1687801822743; Mon, 26 Jun 2023 10:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687801822; cv=none; d=google.com; s=arc-20160816; b=YU4xA72dwOt41dgi3fVex/HnXkBn9A+Uy9oHxzbhdDOsCgvX5zVt7fmIDKfM2tzvN3 8StIOOH58y+A6Zz6y53stC/SUknMB3/xqQuBLLODckoBMTkG9y8e9RwC20oiHLLYqeDR Au/yX8ZqyP63JV5GqcIqMENtMYyoXqenqJEVTaISdeEYgHBOLX2yXmHWR3Y5W74STB6a cLsll4Bh0Bdtb7BnrRuRpQ2YdVOITHQP28q9cNdpiOK2uUhkdIsQNtVd+i5/oO/R8POL RTSCMlSTEtd7VTQUhlWKo+JS7ogew9ciiNEXQ5nPTH+aG3SfuETvTOnMjjBoFYucf84K gaeQ== 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=4j8qD1VIDkeu8FuhbX23YTq3SVJUsBomytwghqZoPiA=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=F5+3xvqrZaVEA0z8Y1zkB+Bmy6v8RV8fzy8rmlop41n1fLZ34IITB4jyGMQiuzTAiG rgKK0+KQtdbduFohWI8R78XGpSwPLFvVH7STry7q6mY7KRVrfSw8l7QFrwJd5CU55RbA i+LlCRnrDWI0CVD+cwNqmBdiYl/tFOWGfsN7UYgHnECrt5tlRQQ+dHtudQrkL8S3TkFo tt26AMdJ0dYNmnayzK62Bi1j6Ivq8G55KZe5OsKQZ0SllMrtT+gMZfNsriCAD7lP6XDo GpXOLWJG00BniEr+15F4JpldCPF6brDfHul3nQte13gUxrpL6HKuml24tsl9kfSTMVuH 95gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=jO+IuqRO; 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 w18-20020aa7da52000000b0051a4886f920si2863173eds.548.2023.06.26.10.49.58; Mon, 26 Jun 2023 10:50:22 -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=jO+IuqRO; 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 S231213AbjFZRgV (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231666AbjFZRf4 (ORCPT ); Mon, 26 Jun 2023 13:35:56 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FC05272C; Mon, 26 Jun 2023 10:35:27 -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=4j8qD1VIDkeu8FuhbX23YTq3SVJUsBomytwghqZoPiA=; b=jO+IuqRONCDpfM0ToVlDzBovD9 NnIpFqCSVbzcdzA354Ai8J4uwvQXN3vjxzaPqsdl/xu+9TkLDzcRKCal7PcOkbcF4dV4DToUbguua DhQc5GIdojQ+898Vu6UjYABB/NZtHhCqnv6dR6n3B4zANWT8SgicSzfUO8KQHTKbqL3iiVruTyBBi TgOxqzuFcqc3rCbML9MBL2LZcXwzT5+YcSAaJsyE93G9W7FkKk1k0a6BL0e2AQngll3EYEidWhOx1 MbKdipsmpf8sBpR98d+bhM2uO0wX76Fuou4HTdMTNuQoYS1f6L3Oed9cA/g5bqwApTqNnCdDFN0wS UGzEVQmg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7X-001vVD-S2; Mon, 26 Jun 2023 17:35:23 +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 08/12] writeback: Factor writeback_get_folio() out of write_cache_pages() Date: Mon, 26 Jun 2023 18:35:17 +0100 Message-Id: <20230626173521.459345-9-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?1769788484490766846?= X-GMAIL-MSGID: =?utf-8?q?1769788484490766846?= Move the loop for should-we-write-this-folio to its own function. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 18f332611a52..659df2b5c7c0 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2430,6 +2430,27 @@ 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; + wbc->done_index = folio->index; + + 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) { @@ -2449,7 +2470,7 @@ static struct folio *writeback_iter_init(struct address_space *mapping, folio_batch_init(&wbc->fbatch); wbc->err = 0; - return writeback_get_next(mapping, wbc); + return writeback_get_folio(mapping, wbc); } /** @@ -2492,17 +2513,7 @@ int write_cache_pages(struct address_space *mapping, for (folio = writeback_iter_init(mapping, wbc); folio; - folio = writeback_get_next(mapping, wbc)) { - wbc->done_index = folio->index; - - folio_lock(folio); - if (!should_writeback_folio(mapping, wbc, folio)) { - folio_unlock(folio); - continue; - } - - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); - + folio = writeback_get_folio(mapping, wbc)) { error = writepage(folio, wbc, data); if (unlikely(error)) { /* 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); From patchwork Mon Jun 26 17:35:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113075 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7653978vqr; Mon, 26 Jun 2023 10:55:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6qfZDv0thHxFepVanI6sv5LziTmNwWamdGlN8oqMk6bC3Ahs84zluAJ2dKMZywefHU4KFs X-Received: by 2002:a2e:9c56:0:b0:2b5:93c0:bbb with SMTP id t22-20020a2e9c56000000b002b593c00bbbmr6853749ljj.26.1687802102690; Mon, 26 Jun 2023 10:55:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687802102; cv=none; d=google.com; s=arc-20160816; b=WH0MxIJP6Pq3GT5/JcrZM6J+Vlz6NZcV8yuB6lTA49i4+jd8Ld77JQFsXaqZkCpwZ1 CiR9SBaDNy4Ms2VOamalDv5Mgmtp0LrR1WJX9PZaEgZrnG1tG8XzBkc6vrFegyUQjdja FbSPRtavlisz0jI4qJCeL8QTZrIh06CPYo9XR76ft7mpfawUZI/alNuZ17BoLpntrm4n j7sqQznWsYhr+eZ3lfPa9yc9B9e/xrIeuIQIXo3x+2LIffRP+fMuUnc35qR+nxhLrmxV gJ0QWBjg4UadyW2BcgI1xi4ipJTO19LsnutjCnInjKa73e0vL1E+Sqm5npYGtWNPVlU0 D6zg== 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=DbRDOwy4aGYzGm5HeqIsIhOnoGhV3uqwtbzHnV71lmw=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=irYENTFCQzcOqKF5LLYArmXT6r9IhHUV/36KCNw2kBlJqIok8NEwfnWUID+kffTNnV EKDShabbIj4idM4o5mAklORfx/myJm3Fqa5QuT96D8AhwRnzOpCM06u1M1aJwqDZ4WoM 7Tanchm1ubp61dySrKsXiOeXos6Ef1OVgTHUra8/IG8pszSmIVOy9nivmypULYox3iVk MXZlPxcXkzNf3LE9jNtRrrWY+Z9tyJnslI948lfJsonzoEIUI00Y983+oPh4xfCi+mGu SYx2aiGfr3Xe1lNFUTE/JlETBQaQQ8M/hllb+ayvb8jpdR3MlaNUS/saDqr/U1lIpy5m 7UcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b="W1PA+/Bi"; 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 jp18-20020a170906f75200b00991db88c470si896308ejb.184.2023.06.26.10.54.38; Mon, 26 Jun 2023 10:55:02 -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="W1PA+/Bi"; 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 S229780AbjFZRgm (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231682AbjFZRgB (ORCPT ); Mon, 26 Jun 2023 13:36:01 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75E542955; Mon, 26 Jun 2023 10:35:32 -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=DbRDOwy4aGYzGm5HeqIsIhOnoGhV3uqwtbzHnV71lmw=; b=W1PA+/Bi8v1fqLdsB7yl772V0f RgwlNsF3bvGRmX6GeWkooNi1wYpT1f3iUIzX4l7MUM38mQ9Zw5s7SQOuMEMB53KdS5tSL+OHJSisS K87JMB2fNoyImDp7TG+shhEPLoq4/BISTARhOn43kcMebEMFO3G44dQ5TWC3FZLmULKJjwLPoTUNq WUIpgwde5+sWTO8N2dyN3HIV4wxNNuQ+5Pvpm5cCn3mV9Sxw1bvQhXNl0ETOjQa+6UJarTN7j2N2A ahz+Xz2UCRm0wunSNn5GNma/A151vXBBaymuvJ4fLZ0+HcnPGNDiVY6mFsk/ZzC0yxz2xPztK9RUp bM2BXbXg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7Y-001vVI-28; 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 10/12] writeback: Add for_each_writeback_folio() Date: Mon, 26 Jun 2023 18:35:19 +0100 Message-Id: <20230626173521.459345-11-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?1769788777614936690?= X-GMAIL-MSGID: =?utf-8?q?1769788777614936690?= Wrap up the iterator with a nice bit of syntactic sugar. Now the caller doesn't need to know about wbc->err and can just return error, not knowing that the iterator took care of storing errors correctly. Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/writeback.h | 14 +++++++++++--- mm/page-writeback.c | 11 ++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 7dd050b40e4b..84d5306ef045 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -369,14 +369,22 @@ int balance_dirty_pages_ratelimited_flags(struct address_space *mapping, bool wb_over_bg_thresh(struct bdi_writeback *wb); +struct folio *writeback_iter_init(struct address_space *mapping, + struct writeback_control *wbc); +struct folio *writeback_iter_next(struct address_space *mapping, + struct writeback_control *wbc, struct folio *folio, int error); + +#define for_each_writeback_folio(mapping, wbc, folio, error) \ + for (folio = writeback_iter_init(mapping, wbc); \ + folio || ((error = wbc->err), false); \ + folio = writeback_iter_next(mapping, wbc, folio, error)) + typedef int (*writepage_t)(struct folio *folio, struct writeback_control *wbc, void *data); - -void tag_pages_for_writeback(struct address_space *mapping, - pgoff_t start, pgoff_t end); int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data); + int do_writepages(struct address_space *mapping, struct writeback_control *wbc); void writeback_set_ratelimit(void); void tag_pages_for_writeback(struct address_space *mapping, diff --git a/mm/page-writeback.c b/mm/page-writeback.c index ef61d7006c5e..245d6318dfb2 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2451,7 +2451,7 @@ static struct folio *writeback_get_folio(struct address_space *mapping, return folio; } -static struct folio *writeback_iter_init(struct address_space *mapping, +struct folio *writeback_iter_init(struct address_space *mapping, struct writeback_control *wbc) { if (wbc->range_cyclic) { @@ -2473,7 +2473,7 @@ 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 folio *writeback_iter_next(struct address_space *mapping, struct writeback_control *wbc, struct folio *folio, int error) { if (unlikely(error)) { @@ -2550,13 +2550,10 @@ int write_cache_pages(struct address_space *mapping, struct folio *folio; int error; - for (folio = writeback_iter_init(mapping, wbc); - folio; - folio = writeback_iter_next(mapping, wbc, folio, error)) { + for_each_writeback_folio(mapping, wbc, folio, error) error = writepage(folio, wbc, data); - } - return wbc->err; + return error; } EXPORT_SYMBOL(write_cache_pages); From patchwork Mon Jun 26 17:35:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113076 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7654327vqr; Mon, 26 Jun 2023 10:55:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5CNPp50o5hts3EwxeNbtfEh+KVf+TFMC9OdLCb6RFQITQzNJmitLLurT0KazHLggyq/bVu X-Received: by 2002:a05:6402:1250:b0:51b:ebd7:641a with SMTP id l16-20020a056402125000b0051bebd7641amr9239667edw.7.1687802151404; Mon, 26 Jun 2023 10:55:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687802151; cv=none; d=google.com; s=arc-20160816; b=k6bQ4ro29dRFfPZUldKw0meJv9p6pce+nPjoKq3otVE7AF/dsEN5Vo9N+4MUScroBW XMkQvVJsTud2pFXryQhgCychlc3/en1pl4gNGgUFC1Ot10NmWhVB19G/rSMiAeloaEUz G7ZnF3V9aN9r1jSqSs0249wq9GYaYqwIyKti05B71G4eXGbBuGmPL0KFe/UH0Vr7dKaE zaqityXRU2RkT9slqMnbS9zkyPLXCYniEgoVR3znox4xK91Xi6+yqe5BAvwylW3uHQaY xa0b7Buv0ePIhr9q+GbVsz1a5oQ7xVFxUvkdCh27yYgu1NxrTPGGc9B2hhsp9YAOUJb8 aETg== 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=sd4UR031RbDntAg7Q2TtCsIA81STdESVBYZOrBi6xDM=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=dq5KaQNKDh7X0G2WLBNWlvwbw0/Y9vyKNz1SB19y0JNCQgcXszHaraGUqSBJ7niJYn y6zIYP0HoVXklR+LUKdN3ZeRHY0Iyw+3+W2m+ADdih2fYH25bPbrj2lgCkulKLGDVV0b Fs/c/9zTSJyQlDaaIWl1uJ8FRptS8IwmRBgUg6sY25xsETcgfEVVdw1wtDUTBohgovpy tp0c5I2W/HCXu8DH+3JPXTaaMLuV3mucLGP63SPhKGw8Ws9wLWUjt5cJ6DiKnor2DN6k IlIPrWHaCx0oZYo68FXNxN4t+xxJFBHkqiBUtb0w673bgF630zKN/RVZKWcqqWqqbf47 NdDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=qIKh3LKN; 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 m16-20020aa7c490000000b0051d7d8497dcsi2965433edq.512.2023.06.26.10.55.27; Mon, 26 Jun 2023 10:55:51 -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=qIKh3LKN; 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 S229965AbjFZRgR (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231670AbjFZRf4 (ORCPT ); Mon, 26 Jun 2023 13:35:56 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6A562738; Mon, 26 Jun 2023 10:35:27 -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=sd4UR031RbDntAg7Q2TtCsIA81STdESVBYZOrBi6xDM=; b=qIKh3LKNsyIKL6wn9vPVDEzZ+D eEqSPJa/7CQUC5xinii35WBEGVSuPYk98nQd3Rk665j4winBw8s0gcTwod5j//SI78kDfO8LiKpb2 QxPbWsAW0AuHq/5s0VxBqJ9MT/wDfN/+rlOdpY2Fk2YtsFFIPIG9BsONHh4138hmsct/3ELFT9roh e0+vNhPUTa71jfAWtaK5OPKL2MmIEixL3WqzjOmsa18TETHpzf2dOygWdHq4KBAPddiWMAqpgRmR3 ydq70lu0ywMlmKyHpMvrSv53DWf8nfN6Ya3A+O2Bn3zHyOeojHJDOD+gOEsd739ZMiyDu/U2u0Yl8 Ak2tJitA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7Y-001vVK-58; 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 11/12] iomap: Convert iomap_writepages() to use for_each_writeback_folio() Date: Mon, 26 Jun 2023 18:35:20 +0100 Message-Id: <20230626173521.459345-12-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?1769788828529099547?= X-GMAIL-MSGID: =?utf-8?q?1769788828529099547?= This removes one indirect function call per folio, and adds typesafety by not casting through a void pointer. Signed-off-by: Matthew Wilcox (Oracle) --- fs/iomap/buffered-io.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index a4fa81af60d9..a4dd17abe244 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -1711,9 +1711,8 @@ iomap_writepage_map(struct iomap_writepage_ctx *wpc, * regular allocated space. */ static int iomap_do_writepage(struct folio *folio, - struct writeback_control *wbc, void *data) + struct writeback_control *wbc, struct iomap_writepage_ctx *wpc) { - struct iomap_writepage_ctx *wpc = data; struct inode *inode = folio->mapping->host; u64 end_pos, isize; @@ -1810,13 +1809,16 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc, struct iomap_writepage_ctx *wpc, const struct iomap_writeback_ops *ops) { - int ret; + struct folio *folio; + int err; wpc->ops = ops; - ret = write_cache_pages(mapping, wbc, iomap_do_writepage, wpc); + for_each_writeback_folio(mapping, wbc, folio, err) + err = iomap_do_writepage(folio, wbc, wpc); + if (!wpc->ioend) - return ret; - return iomap_submit_ioend(wpc, wpc->ioend, ret); + return err; + return iomap_submit_ioend(wpc, wpc->ioend, err); } EXPORT_SYMBOL_GPL(iomap_writepages); From patchwork Mon Jun 26 17:35:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 113077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7654665vqr; Mon, 26 Jun 2023 10:56:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ73ywOIkEHZQq84u4gmxQ3tj0yDg44c6jqp/SQgyjF1zJKcf3OOCAov00V8UO92EYOfRieW X-Received: by 2002:a17:907:3f18:b0:97d:ee91:df83 with SMTP id hq24-20020a1709073f1800b0097dee91df83mr30226353ejc.61.1687802192410; Mon, 26 Jun 2023 10:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687802192; cv=none; d=google.com; s=arc-20160816; b=JdZ1C6+k7Lj9CmdRlbNuQvLNe6MivSiuaunubMm2+ch8G1W5R9f+fHhCt46oR8tInG 5vki21fcobCX0tQCoR8xTzJd7+Kj17730B7A0fJXOlyS0Q+QR9F72dVxUF8RytMAtb+w GU1LzDSMzUQQ85LCKTs6TnD5VLoC3TwjY//QqsxIP2AHj9RaLD9eo+QYeOp9KRFeXatT fbUPcCFRZSIBkObBcQcKIJgW457IbbFauAq0xp/6i3IQr5CJkyqodMdmjfLMnnA00dkw e3wTYOTuc4aXTvermvMBtYIaVDugSviDJ51hbFuBIhZweIiQdJJ2PdnBZviEeV4TlNQ7 SxTQ== 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=ImqynQi+azeOKkPbJPWnsB36hvgJ5MojMLeTL2XpTIs=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=zIFeXnYRN3gR5iUG/Neh+lZ3xrGWbPJhPB4tIXIZ9/ixx5xwB+wTNKiTyug/c1V+p1 p3QR8iNVtfN0lka8HO7L/xMvukBoG6GOfXkhuDdszclqAS5zs0iYTIrhE4hqaVzHzZ90 XiiEgrqvYaPVKWqFffyH0vng+05kxh2b10aG7ZYfC7YIny7bwDV3Pz9w4/ahrbwxwXB3 RRTDkVQ+mtij+6l2EOaYim8wI5dkycAeIeQzFAoDAIl/OM2wxaEEJg+jyXksDPaiUvE+ wFKFLoBkk7oXFJ0O9ncK/YQRUka7KgT9000N1S8X0DV6ufFjRs5cYNsALcJdaskmaKAq 79Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=EnXvWYXx; 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 e17-20020a170906081100b009837908b5c6si3205192ejd.976.2023.06.26.10.56.08; Mon, 26 Jun 2023 10:56:32 -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=EnXvWYXx; 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 S231465AbjFZRgx (ORCPT + 99 others); Mon, 26 Jun 2023 13:36:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229621AbjFZRgC (ORCPT ); Mon, 26 Jun 2023 13:36:02 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B418295C; Mon, 26 Jun 2023 10:35:35 -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=ImqynQi+azeOKkPbJPWnsB36hvgJ5MojMLeTL2XpTIs=; b=EnXvWYXx+3E+jBbF7Z3B+1Gi/T yYgl8ytz+fZoD1bsHwC8cXajllUXh279ulAn62xGFuLds1WNXkGTXCQQEyIO2oWdLPtMZma2d/AMg 5Su9uB7fPivq5SeGFfjxhRCguvBEtuQ+YT74zwhANJ5gvelakTfU9l8U8T0yUP1L00nf5upXTXCP+ Tl1v60WsSro8t+8iDng1kThDvglAI8CetB6z50p5gO6KiKgThZkNJZBBkCDUuV1iH9gr8bU4TyNAL wyAv9pc62eib4kBG2gca6eQc6JVqDCIx0YaYqXUQ3JQrqmBSOGcIkls/+Yr7M2SL3Upaqt+O1iEA3 6Vw5OxJw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qDq7Y-001vVM-AH; 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 12/12] writeback: Remove a use of write_cache_pages() from do_writepages() Date: Mon, 26 Jun 2023 18:35:21 +0100 Message-Id: <20230626173521.459345-13-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?1769788871794280059?= X-GMAIL-MSGID: =?utf-8?q?1769788871794280059?= Use the new for_each_writeback_folio() directly instead of indirecting through a callback. Signed-off-by: Matthew Wilcox (Oracle) --- mm/page-writeback.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 245d6318dfb2..55832679af21 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2557,13 +2557,21 @@ int write_cache_pages(struct address_space *mapping, } EXPORT_SYMBOL(write_cache_pages); -static int writepage_cb(struct folio *folio, struct writeback_control *wbc, - void *data) +static int writeback_use_writepage(struct address_space *mapping, + struct writeback_control *wbc) { - struct address_space *mapping = data; - int ret = mapping->a_ops->writepage(&folio->page, wbc); - mapping_set_error(mapping, ret); - return ret; + struct blk_plug plug; + struct folio *folio; + int err; + + blk_start_plug(&plug); + for_each_writeback_folio(mapping, wbc, folio, err) { + err = mapping->a_ops->writepage(&folio->page, wbc); + mapping_set_error(mapping, err); + } + blk_finish_plug(&plug); + + return err; } int do_writepages(struct address_space *mapping, struct writeback_control *wbc) @@ -2579,12 +2587,7 @@ int do_writepages(struct address_space *mapping, struct writeback_control *wbc) if (mapping->a_ops->writepages) { ret = mapping->a_ops->writepages(mapping, wbc); } else if (mapping->a_ops->writepage) { - struct blk_plug plug; - - blk_start_plug(&plug); - ret = write_cache_pages(mapping, wbc, writepage_cb, - mapping); - blk_finish_plug(&plug); + ret = writeback_use_writepage(mapping, wbc); } else { /* deal with chardevs and other special files */ ret = 0;