Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5980614rdb; Thu, 14 Dec 2023 05:26:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IHX7OopBTXLWPH++fXGZZeHyBXS/aWvNUpBfm+I4359/eGtb43SArwI0Zo7VhwObQ5lFYNP X-Received: by 2002:a05:6a21:818f:b0:18f:e944:3d71 with SMTP id pd15-20020a056a21818f00b0018fe9443d71mr9272397pzb.23.1702560370049; Thu, 14 Dec 2023 05:26:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702560370; cv=none; d=google.com; s=arc-20160816; b=iI6Q3++Q6XONrIDf/M95yVk31xXDu2iHZTkwSWphh1wX3RBp26tFefK/l+9a9t2HiG FH/jocEoETSmlQ+TOlG5JVnsfq6hEQ8qZMYjYH49l/iNzJ0QEQx+3WOvmK+Wy4icnz/Z VJz6zeQMYhnKSI+LCl2M6f2CTl37aynt+McuChTYuEVR4HHA9wnHIbuGHSUFNMkS1vxJ XO0q4MmIvkuXAR3Mh8JEathrRKsNF4Br3lnERU3k1r7ZyHmGM5009nke861Ua9lzf7Bm WFTLFywqKyXXKZtUdSk9wYoLOngnnOwDzyxpn0nbLlyqfhc8snjsXmE131V1ANBa7iT5 iCNw== 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=gFAfQ8RI4NZqa/9LCD+jS3TStiD980ne3/Qcf1aEZzA=; fh=s6qbYcpKmY0AEsK/gKDpT3qiaGyyaU+hQ5h16uVwDEk=; b=ZvtivZxNRCjfwkry73qIhD6eVPxPbLI6ATh17QR/GU1P/jGFTqquwnTpd8gyZzvNvg yHqsG/iLwYxcV2uEqLQT+z5JWV1c+yo1hKwX5C/6LFdLAvYhvJmUAl89VIESaz2pO/vs LARTcp3tBlE1bbbxC0OM2yX3etcclNNJE2fl95NhD8YCHwpcPQmaI8U9ZaqCLkqvHQW3 rqIbhRgWi6T53pWdO4kTVNusTs7FK2jjDsT77EwB/5jx98lbvQ4+giJDCD/mt6CYLeEg X/VWDqCadxhOhiDe0r0I0NOxbFvdAFLbtgzJkhYQRiJdNhXhyWALTMGL3peqDZo4IGZ1 u3xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=iaO3zrW7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id v13-20020a17090abb8d00b0028b07999015si1188836pjr.30.2023.12.14.05.26.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 05:26:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=iaO3zrW7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9CBC58025825; Thu, 14 Dec 2023 05:26:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbjLNNZ4 (ORCPT + 99 others); Thu, 14 Dec 2023 08:25:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573258AbjLNNZz (ORCPT ); Thu, 14 Dec 2023 08:25:55 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 810D6114; Thu, 14 Dec 2023 05:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=gFAfQ8RI4NZqa/9LCD+jS3TStiD980ne3/Qcf1aEZzA=; b=iaO3zrW79MSicmR2sZYKfRcxiH i6dP0SWuEvOwauQFGQNX6drc20R0mQporbqJK9Ae/EpSzZ2URWntRpkaHP0xigV0iDY5QuSJHIiCQ Mo7Rto/vqm0//OV5Akxwqp+GKF4VnjeKJIRrzyZvhXp1nfFHZo6clA6Ms2vyByRzAuCo5P769hI0E uuu0EStnwmU0hmRpVyXiiEKSAQSDbPs5OhXxok9vD7vVpTfFx0OyvSabAZzyGs9vLoBYXlH08ZvZw 9amAcoVDpwtwFO+Pq43XGabNC9cEhu43saMRnC8Zp09eKvIPBlEOZtG6iQCulLeEvzO1jHG5Xn8O+ yftaE4YA==; Received: from [88.128.88.27] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rDlix-000N1N-1b; Thu, 14 Dec 2023 13:25:59 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: [PATCH 02/11] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Thu, 14 Dec 2023 14:25:35 +0100 Message-Id: <20231214132544.376574-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231214132544.376574-1-hch@lst.de> References: <20231214132544.376574-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 14 Dec 2023 05:26:08 -0800 (PST) From: "Matthew Wilcox (Oracle)" 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) Signed-off-by: Christoph Hellwig --- 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 05e8add4b5ae3c..be960f92ad9dbd 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -81,6 +81,8 @@ struct writeback_control { /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; + pgoff_t index; + pgoff_t end; /* inclusive */ pgoff_t done_index; int err; unsigned range_whole:1; /* entire file */ diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 45309f3b8193f8..5d33e7b468e2cc 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]; unsigned long nr; @@ -2526,8 +2533,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); -- 2.39.2