From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E94DEB64D7 for ; Mon, 26 Jun 2023 17:35:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4EE198D0002; Mon, 26 Jun 2023 13:35:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A9418D0007; Mon, 26 Jun 2023 13:35:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 061198D0002; Mon, 26 Jun 2023 13:35:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D4CFB8D0006 for ; Mon, 26 Jun 2023 13:35:31 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5D458160809 for ; Mon, 26 Jun 2023 17:35:31 +0000 (UTC) X-FDA: 80945600862.14.59BD8C8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id A1331C0012 for ; Mon, 26 Jun 2023 17:35:29 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dHEryiCM; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687800929; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=X5nRO0yDxZXWnd7LdLo4tOM7JIHXSxr3v1Ba4laEERQ=; b=PYY4jClbJRxweJm6tQegrB6VVqREHKzJSeTHS5elIMGnO+swy3DSNDd5Idy5E0s1f7dNgQ dkxDNm0nRpIOnUBgkhqaVg8Pf+KGtSRdyzip8pJB8hsdbmCJKri23ulIAn/f6ALLf42IC9 /ZhCfshWBCFilBPEnVNLnq6Z2OKDPHQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687800929; a=rsa-sha256; cv=none; b=F7vbAbGla7QJtmAQ2fSEPZTD9cURLu/sUBzDkPVSFM7p+EXVAlgjPz4Q+b7sVY0QxyMt68 d35O/13M6QuISwlE1ZzzPSkb1JAT2AxJNU8jxBNvE8+a/V1CSC1M5KiZT42OrJ6gXdT7M4 hyaoyWFpJKf5QFhF0UllFHctQVkpI9g= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dHEryiCM; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: A1331C0012 X-Rspam-User: X-Stat-Signature: 7o4apgjnzuupwytxd5fr7r48cwn775we X-Rspamd-Server: rspam03 X-HE-Tag: 1687800929-336128 X-HE-Meta: U2FsdGVkX18vsAlXVQqzx1DcsfLwSw4uXP4YQA5w2IVgPIMSg7H2AKn4E13qLGHVf6qowcB+Pq+JNCNzpuwO0NYmOa9Yi7Eql1dSCHbKI2uBIxAxGhINYXRKX9z3EVjAk205HweLVG+EIPE/yEHSE1Q+v1HuWafWdT2LamvJ6gjEEQ2FGgxZ+6qqnDpT17B45Nke3MjOCVthKshCp0EC0ZToHF4UBK1k69+ym/+RaC30h3R+tcPDV9HDYEWsAmsXGiDMJgRkN5c2pApeaNox45/iUFJf34pqbagKhrnCAunoGPcGRwTxAlf/DavWkXf6rIhori0h5lVzyWd/+i9E27S0j+g8x7BJ/X29zjot89Kpgh4b82imZzqd+EVA+aSpt6aa3zRArKqvZNxTw0D1A1LmJ/gvq4xlXIQKETWPbues0lIDtj9osMuvexuG1JR8V834dRnCoJqOurE4AEohvagDfLf+iMKz9kH9ehoDu7ZBcN4eJvO0RILHbPWlxxn1PC1+I96io7wkT5MbrdJLqqKwRRrREZPYcA4ZINAV9sGJV3P6sQWpqYOAHzrL09O+517Kj3HUfWSR3lrpBG0mFXINh5qA53N/P6LdCQucAn0/z9ewpgHMj6T/7SylRYzUl8q2XNpk9YDk62Bf9ADq06Md9qQhsZjReWDCEMZIkixic4BDZExET4k7rtizmcB39oFZYqLrR+P1YEALhhaKdGWLdwRpNhHJkW/CJT55SC7R0yNnv8pLe4wjVELZ3B8bGwtbtFPuUIvY7sBdF9l3qrCNkxcQuPajZ9g7wWwRYQch/c3oYK1nxmJpqwTvGVMUBV6yTK0kG7WfUhU+0d/oIhf9rRHWzkFL4rEeOZxnal7P1ni/bQ6NX1Zhhg/tSb498OZ1NvZDmkY/J8r0zmmMWczsre69I/4TeNkTCnMEZVlvQB/DHHi7ROpzsxuMqzScH7AmKPxfQThPJVxRYSo JwjLUgUJ qGzpWlxhwlP5p9YWuliJjfKEfFCwqxBkX9O/H4ZKeTtQ8v3lXI8qugxczZ+3K1pIF5hr3vPiYrUf3OvtvGprVGZAWm7KEymQq2Gi+dKX0NC+xNJQkxDy56TYJaFKJ7t5YYlKzACSZmC9dBbjB3Gx/tf0WZIB4p+R6esSE6ZnfnykJPVG+Ic6N7f2yiaqS9lTB9VdsZBLMFyLxSDgm+UNOcgslOtVG3AZsc1/c X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); -- 2.39.2