From patchwork Mon Dec 18 15:35:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 180502 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1329186dyi; Mon, 18 Dec 2023 07:41:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0P+E4gNsWNZQwgl07bAJuxk8RO7qMMpxpLl10V4+ibMz/0oWR7dR3JECqzuDUZpl/nbWq X-Received: by 2002:ac8:59d3:0:b0:425:8882:32f9 with SMTP id f19-20020ac859d3000000b00425888232f9mr22122063qtf.22.1702914066264; Mon, 18 Dec 2023 07:41:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702914066; cv=none; d=google.com; s=arc-20160816; b=OPyzchsHyzDNkVPMdN3mn9C5z7B67o86eNFSo1bXWSim1MFcaP4kEDaj/nKFDCCjJ4 sHADapYBoFB/F3O/Ev405ezg2EDWfo4yD+Kuf4sKMrj5PZwcxFQ53I5+TRTIwq/D/21b UB1CF+xU7dGrqT2icLbm3c5cTXO83mhx36ssC6luGDvpkBmn7peXeJadEHdrVYMWf/h1 zJxLWc+n+TsKvjPeG5JX8wy3+PAKvudrgniUUrSFSb1HmEER6YBgyCtqNFfSTm/lKBTo w+yLw6OF3RfvpnVRhFnxc3NrWWGEdW2KVWWQsT+KNytLb0+4jspegpqTZ8g/QYC3JVaA TFuw== 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=11fJOeLJtEu+HLcWStjNzVEg8D8E0pgLFFPvW65M4Co=; fh=m0HBXuwgOCKat7wyuY7vstPypqMqxNmINnjBv5+EUjU=; b=R2UluY8fpXzONLnicTOd4t9luUvu2Zz/jrw/EKK13b6ilkYqcWz02xhWplTjuqapG1 gPUzyoZ9L/7N1rDGHcCIE1PHi/HFq+vUwOd81b44d8Qqk7oiGwVKARKdvMntAjGZKIzu gCd2G88z1aJLh4M7eJYquT/EhiETCW0gXdKp8AvyMMRbMDmoca15MxgtPJk9QJBSfkQe +jbRlg6yuT7aO4nsPwW27BndaO86CkFE5My0k1DDR0e57cn5yq2GAnNPwf4C3IaJXiqn n6VFqfr9jzWj88ARAU8ABTM2aXTAeeWbMYSX1ay4jUoXBDjIiyS3Y2Ngih6+KN+Mq7zi YscA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=MXOOyyiG; spf=pass (google.com: domain of linux-kernel+bounces-3955-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3955-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fa15-20020a05622a4ccf00b004257ad3977dsi26367953qtb.521.2023.12.18.07.41.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 07:41:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-3955-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=MXOOyyiG; spf=pass (google.com: domain of linux-kernel+bounces-3955-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-3955-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A88111C25007 for ; Mon, 18 Dec 2023 15:40:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6593C7347A; Mon, 18 Dec 2023 15:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="MXOOyyiG" 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 5D4917204D; Mon, 18 Dec 2023 15:36:33 +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=11fJOeLJtEu+HLcWStjNzVEg8D8E0pgLFFPvW65M4Co=; b=MXOOyyiG08iR+isoX6KD7RrhRt 0QmbZm+seKCas0S98o9hhqfjQr+vlWEOPT/rhVKpCa/ug/D/NkXWj7C1tgZXQeIQVkVhCIs//zQHy t3gNoGV16ux4RaT1JuRzdxFP47V9wmEuzUaBUuWpBMIWmvjTHcVrRKP+iRpnx2k+O0LglLWfTgCiC p3ZhIyUOhbchYAy4iRYYUIw38YozNgK4QODvPde8KbAfKrK0yLwBCx3tJ63AZ+x815DPNLbVSczvb H5oQ+NezuCm0IvG56bFh5739uRp0nWlfpeCgsFIiZRsfEL8M9gbUEyjA6HfZ7Y7yfgWBJfb13/aN4 WwKzKFCg==; 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 1rFFfS-00BEVg-0O; Mon, 18 Dec 2023 15:36:30 +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 Subject: [PATCH 12/17] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Mon, 18 Dec 2023 16:35:48 +0100 Message-Id: <20231218153553.807799-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231218153553.807799-1-hch@lst.de> References: <20231218153553.807799-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: 1785634819690134427 X-GMAIL-MSGID: 1785634819690134427 From: "Matthew Wilcox (Oracle)" 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) Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara --- mm/page-writeback.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 70f42fd9a95b5d..efcfffa800884d 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2442,6 +2442,22 @@ 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 */ + else + wbc->index = wbc->range_start >> PAGE_SHIFT; + + if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) + tag_pages_for_writeback(mapping, wbc->index, wbc_end(wbc)); + + wbc->err = 0; + folio_batch_init(&wbc->fbatch); + 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 @@ -2477,29 +2493,14 @@ int write_cache_pages(struct address_space *mapping, struct writeback_control *wbc, writepage_t writepage, void *data) { + struct folio *folio; int error; - pgoff_t end; /* Inclusive */ - if (wbc->range_cyclic) { - wbc->index = mapping->writeback_index; /* prev offset */ - end = -1; - } else { - 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, wbc->index, end); - - folio_batch_init(&wbc->fbatch); - wbc->err = 0; - - for (;;) { - struct folio *folio = writeback_get_next(mapping, wbc); + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_next(mapping, wbc)) { unsigned long nr; - if (!folio) - break; - folio_lock(folio); if (!should_writeback_folio(mapping, wbc, folio)) { folio_unlock(folio);