Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1660801rdb; Thu, 25 Jan 2024 02:20:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IHbGIzubG65cNKb6KFu77cMGZL47M+4hQi1ZDaWC90hIBJ1NG/JKoL44MAB5XaJ8v3+popU X-Received: by 2002:a05:6214:2a87:b0:680:f9a3:ce50 with SMTP id jr7-20020a0562142a8700b00680f9a3ce50mr604272qvb.111.1706178014089; Thu, 25 Jan 2024 02:20:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706178014; cv=pass; d=google.com; s=arc-20160816; b=uL5UJkwjNQ2PAx6bVyA+jn9Bow6gTwX8vfGyIXG3qZUvwavIdshYGGwS1RCEsMILob TSnzYHIk82d7JVtQCM1aV34bNA508O8pNHWz/1cl4CR/Zylrkupx11Zxt30zbjP40Wpv wVtYCAFA1Bj8BmENd7INfaTvwZ74TH2pmF8OThkz2eLFdjn1IEOPhsvV12cgVue2qqx3 rmmy+zzCr8jQKhlawYN6q4vRU1vYFkazVzBlBuOpOBGN6XsuoRzmKM3VmQreu7bxP/mR LiBpKyZGfROkJLF+rFbXaGRBnFYQS14DXjVJXpQaEOMMQz9X225q6jRhAtoMfV4N8hUA CiWg== ARC-Message-Signature: i=2; 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=btL3AciRr+h+xXxfR+Yq/41M1ZAR/B4m6dVFwBdRQv0=; fh=4n+2OJvAjB92nIDNIVn6PB+TJURVaRmLWxWqLJknBpc=; b=ID3s8e9djzQR0hahWW6yz44s6iage3puUSgalmMnon7hl7sFo0JfZumn6Th8EBbHma ygM+th0DWAObELrLW+LvB+CkVGQfV5QHkDo9kWa/6qkcRMXR7O2QfZQwWFF/5p8HXEsC wz/R++m2KdpoWMhAm0BGwPvwQmqMTlDrWGK0HenXoBumJxkJvaGIVnOdn1icPMPvCHXP ws27xNBM9O8fexwQXTiSApb2Uml6HcvktZ3wlTXCOQX/Y7oMwp+Geq99XAD16Hhq5RrO jRUSoO7K+yjfq0qCuouOOlok4qTsnlvzckW1IIKCn28XN9TI6Yt6nUPfV7djrV7JyHqr sO4g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=r5e1XEM8; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-38212-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38212-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x27-20020a0cb21b000000b006818433b30csi12418438qvd.600.2024.01.25.02.20.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 02:20:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38212-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=r5e1XEM8; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-38212-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38212-linux.lists.archive=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 432761C2784C for ; Thu, 25 Jan 2024 09:02:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07CBA2030A; Thu, 25 Jan 2024 08:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="r5e1XEM8" 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 E322D1D556; Thu, 25 Jan 2024 08:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706173135; cv=none; b=F4s4ijW7hzwUCavDx7Vs4uM10zo8UqIbh63LpQ/icMG086gQzJR5Y4+LgVzfWmjb/aLs10PnBcyc0j0U+6mChWDDquWOWiv9tOGT1aeejS9T0lG4nQ0t4LYymi/6aKMJA5H5FeV4O4q2BF+MVwmVXhovounPQq/LwWYjLqxpVEs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706173135; c=relaxed/simple; bh=qwBX7ZnPhqRoZ+e2l0nUI4Td9WPa5eC1nxDyNy0cFtY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pSZKoec+AP7WC5H9WWynSpmnffyPA86uJn7aIwwoa34X8XnzQrc+9mCs04v5csrHrxmjdNkh5VyHoNRM9wPYNaiGf4E5tMG6sZXZDlVZF/TIOQ138j5NBjh4/iD13pOrojPKVKKDEPIuvhnOVnZVBODCBPuAx7c9k4qpzOQNwiI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=r5e1XEM8; arc=none smtp.client-ip=198.137.202.133 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=btL3AciRr+h+xXxfR+Yq/41M1ZAR/B4m6dVFwBdRQv0=; b=r5e1XEM8S9gQh8rBNXuD00dQSt nekiXLsV/Vk7BZw/6syGHv6F3sB9VECwP2G0QgBhGJeOnzfwy/mI92WsKGhst2tCM+Wi3az+xbmxJ gZldsll43mBMkAMXLPMaby4NPM0MwucidYZvYToaJikMi+1+p5W8ln2WpHXKffi82sEhTQL+PyRIO pO9/dx0INBNTIOEi5ebmi9UV+Yt1GOMFQJnURTXviErty+7hbRM4BtU+fUFe1923PB5lYFBpAy0j8 iwtnO4feBgof8IrJ8Sy8flg8sIbHfcVGuX/zP/ZWCe8ajPAAkpzPcFr8i2L62RcfwSsy1r6CWYetm NBUCsxaw==; 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 1rSvZR-007QQO-0Q; Thu, 25 Jan 2024 08:58:49 +0000 From: Christoph Hellwig To: linux-mm@kvack.org Cc: Matthew Wilcox , Jan Kara , David Howells , Brian Foster , Christian Brauner , "Darrick J. Wong" , linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Dave Chinner Subject: [PATCH 12/19] writeback: Factor writeback_iter_init() out of write_cache_pages() Date: Thu, 25 Jan 2024 09:57:51 +0100 Message-Id: <20240125085758.2393327-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240125085758.2393327-1-hch@lst.de> References: <20240125085758.2393327-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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 Acked-by: Dave Chinner --- 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 432bb42d0829d1..ae9f659e6796ac 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -2446,6 +2446,22 @@ static struct folio *writeback_get_folio(struct address_space *mapping, return folio; } +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_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 @@ -2481,29 +2497,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_folio(mapping, wbc); + for (folio = writeback_iter_init(mapping, wbc); + folio; + folio = writeback_get_folio(mapping, wbc)) { unsigned long nr; - if (!folio) - break; - folio_lock(folio); if (!folio_prepare_writeback(mapping, wbc, folio)) { folio_unlock(folio); -- 2.39.2