From patchwork Fri Dec 22 15:08:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 182696 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp1127928dyi; Fri, 22 Dec 2023 07:13:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3fJ3TNqoG9Joa0m4jqbtkupJ7jmHs6l0S+PHrz489BBN+gwfzoYc5k+tBRSFka4D3jxRB X-Received: by 2002:a50:9558:0:b0:553:55e8:98eb with SMTP id v24-20020a509558000000b0055355e898ebmr765126eda.34.1703258000334; Fri, 22 Dec 2023 07:13:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703258000; cv=none; d=google.com; s=arc-20160816; b=eD1yJ+DnXT5eD3L/hvOHumAQbvm20PfYsV/tOHPaOe+yMfD3VFyGfCiB1bIRScEJ7g zTDTgWamrxEQazS3cBd+b7pSDBFL9l2SE4UiPOWI3Pb9kvyadJIRBsCu9l8iTUxW+bik tvaYYfKBn8ycppcpKZSdSvS8252o5ROwPeB6rufw87l/GrjDTzDdFpF0xOmEOB1gSPxd 2ifallmcd3OxIvS7qZDbvTxQdNwS5LdgqXiJyD3FhZwO/H3jMOPVfKB5gJXb9l10QdS0 h96sM5uvaMnOTb+bFymakbUIgYrPO6+OiqrqFFjC0i8b4cqrG0dUWh7JPiNZxVKhPilE +KQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dcSwdTVvCQUQwEHV9ZU6DKJi2JGMjLPwvaIvkNqY5Tg=; fh=hzpEVxJ05G9gyZL9WVyKgOEGxITvmFSuTcKyr2ByStg=; b=F1PtAwOaGLyXrD/nNrXMoH+SlheVbAww6nljujRQPDydTHDAdir+iuzlUCdPVjMF9u JfKN87Lv8IMy4OEE1tYdUvm3X8GafrvnObnzXEwzuf8z/5jWq+o5z5F1CNZD4Y0jGHML YeTm+fAsIYQU+Tne6yrrgiWeM3AMcMN2xZiFykEmfs/6W6fLjXnAGn7LVYOfPDimXnok N3s/W7AqFx1RDoFj+jJz1MRuz/z3HuPqU0UzRFGNfbXX01BHpwGs4gODLnsx6AqG9ibr O41vf5flEkz/7NWMXOghs3YZJgKq4yWoY0+kw2pzUWlfiMN0B9EXJU3FU2hXSEyUHOMc j1BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=A1L3KGi7; spf=pass (google.com: domain of linux-kernel+bounces-9822-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9822-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t4-20020a056402524400b005547482a0efsi148626edd.158.2023.12.22.07.13.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 07:13:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9822-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=A1L3KGi7; spf=pass (google.com: domain of linux-kernel+bounces-9822-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9822-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D63381F26F13 for ; Fri, 22 Dec 2023 15:12:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 29E172E3FF; Fri, 22 Dec 2023 15:08:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="A1L3KGi7" X-Original-To: linux-kernel@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 104E92C855; Fri, 22 Dec 2023 15:08:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org 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=dcSwdTVvCQUQwEHV9ZU6DKJi2JGMjLPwvaIvkNqY5Tg=; b=A1L3KGi7p22WmVHYwn8JAqK2do OXUFMCP8LJGy0Us0BB+qtD7uRWeU14L7juYdVzyoo741jIvkCVavCFPr7vn49oJnwBeb31GwyhyCL XMkYwmZAir6Q8gmHFK6Gky8PEmPyGgyC/KQTwjJI/mv6W+LjQtY/VI5pXzlj9BZdnNVpCESlp38Vu jDKhsTX0+/J0c5ijdwDmuwZyFecpwZm4RDeHS0BP2noVcUDK4cFWRWT1GMfPdyriBSS6BSTLFTFv6 PXWgGoOYcEAcl640qINBEZZbXhmFnZy7yHZ5tKGTOCGoGVoGeI9mHWUXUgs3+Q2npwJgqbpQmtJd7 K5IukuVA==; Received: from 2a02-8389-2341-5b80-39d3-4735-9a3c-88d8.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:39d3:4735:9a3c:88d8] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rGh8m-006BQI-21; Fri, 22 Dec 2023 15:08:44 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 07/17] writeback: Factor writeback_get_batch() out of write_cache_pages() Date: Fri, 22 Dec 2023 16:08:17 +0100 Message-Id: <20231222150827.1329938-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231222150827.1329938-1-hch@lst.de> References: <20231222150827.1329938-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785995460775316427 X-GMAIL-MSGID: 1785995460775316427 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) [hch: heavily rebased, add helpers to get the tag and end index, don't keep the end index in struct writeback_control] Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Acked-by: Dave Chinner --- include/linux/writeback.h | 1 + mm/page-writeback.c | 49 +++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 390f2dd03cf27e..195393981ccb5c 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -81,6 +81,7 @@ struct writeback_control { /* internal fields used by the ->writepages implementation: */ struct folio_batch fbatch; + pgoff_t index; int err; #ifdef CONFIG_CGROUP_WRITEBACK diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 564d5faf562ba7..798e5264dc0353 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2383,6 +2383,29 @@ static void writeback_finish(struct address_space *mapping, } } +static xa_mark_t wbc_to_tag(struct writeback_control *wbc) +{ + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + return PAGECACHE_TAG_TOWRITE; + return PAGECACHE_TAG_DIRTY; +} + +static pgoff_t wbc_end(struct writeback_control *wbc) +{ + if (wbc->range_cyclic) + return -1; + return wbc->range_end >> PAGE_SHIFT; +} + +static void writeback_get_batch(struct address_space *mapping, + struct writeback_control *wbc) +{ + folio_batch_release(&wbc->fbatch); + cond_resched(); + filemap_get_folios_tag(mapping, &wbc->index, wbc_end(wbc), + wbc_to_tag(wbc), &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 @@ -2419,38 +2442,30 @@ 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 */ + wbc->index = mapping->writeback_index; /* prev offset */ end = -1; } else { - index = wbc->range_start >> PAGE_SHIFT; + wbc->index = wbc->range_start >> PAGE_SHIFT; end = wbc->range_end >> PAGE_SHIFT; } - 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, end); folio_batch_init(&wbc->fbatch); wbc->err = 0; - while (index <= end) { + while (wbc->index <= 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; @@ -2525,8 +2540,6 @@ int write_cache_pages(struct address_space *mapping, return error; } } - folio_batch_release(&wbc->fbatch); - cond_resched(); } writeback_finish(mapping, wbc, 0);