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 10176C41535 for ; Fri, 15 Dec 2023 13:26:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DD786B0103; Fri, 15 Dec 2023 08:26:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 68DF36B0129; Fri, 15 Dec 2023 08:26:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 507316B012B; Fri, 15 Dec 2023 08:26:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 01B036B0103 for ; Fri, 15 Dec 2023 08:26:44 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D7A341A0D2C for ; Fri, 15 Dec 2023 13:26:44 +0000 (UTC) X-FDA: 81569127528.05.5E58538 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf28.hostedemail.com (Postfix) with ESMTP id 445F6C001A for ; Fri, 15 Dec 2023 13:26:41 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=gNJvKAAF; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YHTHxRrf; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=gNJvKAAF; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YHTHxRrf; dmarc=none; spf=pass (imf28.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702646802; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Tq9zADGaqdljmDLOT8it4clHsoh/dCFqwv8EI9ZL3eA=; b=ELcz8eD7QAjMIAW8g34u0PirWFCB1a+KfKFS9+vaAmGDRKMK/XcrZDOHm002zmbjALHxDi 5PBxFY3HIvD/E2JOnV+T8bielJp9hV5hkT6y68eUBQUwMIYXYhVZT9L/+5W2VLG2Eoq/So m2YrboEHrjqu1h6Uv+xI4iIkySAWzRM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=gNJvKAAF; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YHTHxRrf; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=gNJvKAAF; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YHTHxRrf; dmarc=none; spf=pass (imf28.hostedemail.com: domain of jack@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702646802; a=rsa-sha256; cv=none; b=IyofQdaRQx4SU1F7f+xeXiH3gFlJ6nKXsyjUxHwjaSwh7op195De/afxyIzzbm4CVtOHbd WTutITmaK06PiK6F6qOvV65NGSOiatdTmSw1LN+xrXML4gnjRQRd8YTa3SZ1s+kdpfGf9g mnMybBENOM/VmEC10RIy5kmM129MBCg= Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B259721FA3; Fri, 15 Dec 2023 13:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1702646799; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Tq9zADGaqdljmDLOT8it4clHsoh/dCFqwv8EI9ZL3eA=; b=gNJvKAAF4tgbYx7L32FAFZXR3Y92PmR7f4QPEFf+rb3IGmc1QGAAsP6HNZa8FKvmoF6GoA nl55891gIiVDrStzsvrASU7QOr7h3cAgcMaskLoCAnV8f34CZ3m0hAC+fHrtPrlFLKcjMy Bduld3LDJna/5UU7GrRvaSilNVFRyFQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1702646799; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Tq9zADGaqdljmDLOT8it4clHsoh/dCFqwv8EI9ZL3eA=; b=YHTHxRrfky1iaCK5Tr5cnHsW7rhiZCjuluxBPt4rtHknnYMBBL9zMC3Rh8J7llRLh9tpUZ qbUr+mYfDiDE9lDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1702646799; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Tq9zADGaqdljmDLOT8it4clHsoh/dCFqwv8EI9ZL3eA=; b=gNJvKAAF4tgbYx7L32FAFZXR3Y92PmR7f4QPEFf+rb3IGmc1QGAAsP6HNZa8FKvmoF6GoA nl55891gIiVDrStzsvrASU7QOr7h3cAgcMaskLoCAnV8f34CZ3m0hAC+fHrtPrlFLKcjMy Bduld3LDJna/5UU7GrRvaSilNVFRyFQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1702646799; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Tq9zADGaqdljmDLOT8it4clHsoh/dCFqwv8EI9ZL3eA=; b=YHTHxRrfky1iaCK5Tr5cnHsW7rhiZCjuluxBPt4rtHknnYMBBL9zMC3Rh8J7llRLh9tpUZ qbUr+mYfDiDE9lDA== Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id A162813912; Fri, 15 Dec 2023 13:26:39 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id DXxgJw9UfGVkWAAAn2gu4w (envelope-from ); Fri, 15 Dec 2023 13:26:39 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 2FE5DA07E0; Fri, 15 Dec 2023 14:26:39 +0100 (CET) Date: Fri, 15 Dec 2023 14:26:39 +0100 From: Jan Kara To: Christoph Hellwig Cc: linux-mm@kvack.org, "Matthew Wilcox (Oracle)" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , David Howells Subject: Re: [PATCH 01/11] writeback: Factor out writeback_finish() Message-ID: <20231215132639.ftis3fhmcqkhrpzo@quack3> References: <20231214132544.376574-1-hch@lst.de> <20231214132544.376574-2-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231214132544.376574-2-hch@lst.de> X-Rspam-User: X-Stat-Signature: s6o8gtcymy4h31smezs3h9kadxrps1qb X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 445F6C001A X-HE-Tag: 1702646801-383571 X-HE-Meta: U2FsdGVkX1+pVRq2h1MoMg1EzvP2PawdhwumF16sVqTGi2Td2PIn7aDejC7kbhdoYd4hmeL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5Q9HT5jd3KehBVCcBC/tUAp1hfNTJa9RsWgwrUd6En31VSEpXLfkj8mPSUDaFlqQS2xDMxeST619h8iY5sWV2yofgUYvLYuftdVwZYOW9jqxiDnQI2a27pOVljOHdGG00iPuEMzJK3Xsho3gGHT3KvjnWq7GhsCxCjoJE5eI/SwJi/yvY6rEgfqOv7MeXMtBDjyNyY5cyp6z95hN6oIZfyELsVEma+TpCs5IqVA/dstlNw7CCSc6x2wEtCrxzVTpncliIhzlv8xJCqqEI+W1Eh 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: List-Subscribe: List-Unsubscribe: On Thu 14-12-23 14:25:34, Christoph Hellwig wrote: > From: "Matthew Wilcox (Oracle)" > > 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) > [hch: reorder and comment struct writeback_control] > Signed-off-by: Christoph Hellwig > --- > include/linux/writeback.h | 8 +++++ > mm/page-writeback.c | 72 +++++++++++++++++++++------------------ > 2 files changed, 46 insertions(+), 34 deletions(-) > > diff --git a/include/linux/writeback.h b/include/linux/writeback.h > index 083387c00f0c8b..05e8add4b5ae3c 100644 > --- a/include/linux/writeback.h > +++ b/include/linux/writeback.h > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > > struct bio; > > @@ -40,6 +41,7 @@ enum writeback_sync_modes { > * in a manner such that unspecified fields are set to zero. > */ > struct writeback_control { > + /* public fields that can be set and/or consumed by the caller: */ > long nr_to_write; /* Write this many pages, and decrement > this for each page written */ > long pages_skipped; /* Pages which were not written */ > @@ -77,6 +79,12 @@ struct writeback_control { > */ > struct swap_iocb **swap_plug; > > + /* internal fields used by the ->writepages implementation: */ > + struct folio_batch fbatch; > + pgoff_t done_index; > + int err; > + unsigned range_whole:1; /* entire file */ Do we really need the range_whole member here? It is trivially derived from range_start && range_end and used only in one place in writeback_finish(). > diff --git a/mm/page-writeback.c b/mm/page-writeback.c > index ee2fd6a6af4072..45309f3b8193f8 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; > +} Also I suspect we can get rid of the 'done' argument here. After all it just controls whether we cycle back to index 0 which we could just determine as: if (wbc->range_cyclic && !wbc->err && wbc->nr_to_write > 0) { WARN_ON_ONCE(wbc->sync_mode != WB_SYNC_NONE); wbc->done_index = 0; } Honza -- Jan Kara SUSE Labs, CR