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 CB7A1C35274 for ; Thu, 21 Dec 2023 11:09:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31B216B0078; Thu, 21 Dec 2023 06:09:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A3B26B007B; Thu, 21 Dec 2023 06:09:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 11D6C6B007D; Thu, 21 Dec 2023 06:09:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F09AD6B0078 for ; Thu, 21 Dec 2023 06:09:20 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C045C140D45 for ; Thu, 21 Dec 2023 11:09:20 +0000 (UTC) X-FDA: 81590554080.22.2FF961F Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf20.hostedemail.com (Postfix) with ESMTP id 447291C002B for ; Thu, 21 Dec 2023 11:09:17 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=obs2lYdW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=5L7BcSKB; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=obs2lYdW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=5L7BcSKB; spf=pass (imf20.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703156958; 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=CGCpOt7yvJg/Baj+l7YgN3+pIt5pBMerQ6avhaamLRk=; b=rTRomYufwwYxNsS2W6WUpG6UpRIk0FuHIJKe79sWxHDYO168wr3sGlczF8C7XQOCnaFSLG sXf29vHzW1a5TqhDw9i0hTR7CMIyQMD96ugtBnlyyVAauhgxUcHguHUvZP0cvXwCryZGuv cHNTjYPq7GQ9hZnqF/Kss/vvVxMC610= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=obs2lYdW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=5L7BcSKB; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=obs2lYdW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=5L7BcSKB; spf=pass (imf20.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703156958; a=rsa-sha256; cv=none; b=bafNMNfblr1VCmQ9tkKWxn3qMJVpbcdvDPLcC26J2k9svoCduoM5VAZvxp1kDLL6S45Xav zdqmrF4zobQv5Xg5b7MWWfivNm9xQbswwUWO2l6foDVwas9le9/kT0/hH7jUjhShKPkEBX bI61TclHPlwA/V/CtVf+V+TX6QvMF40= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (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-out2.suse.de (Postfix) with ESMTPS id 5A5D21FB42; Thu, 21 Dec 2023 11:09:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1703156956; 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=CGCpOt7yvJg/Baj+l7YgN3+pIt5pBMerQ6avhaamLRk=; b=obs2lYdW0IeMmDnRh6+mcqyBv/dpPm3iKtRwHtHPDd36hOxZ25aiXvp8oPyqWdQVxmxD7x 81hr71UhhdB8zKPAZCe9/+RlKWYEht6DCQuInTI/VbnwLbnHr46ITW2Q3J9auW/TfQhaiq IJGbNhP3BvQyvZ3OJP+o3PSdnO4KC2Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1703156956; 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=CGCpOt7yvJg/Baj+l7YgN3+pIt5pBMerQ6avhaamLRk=; b=5L7BcSKBF7aiALiaurswhJ1TzRUjwbgqVCWEhJmBQAaJyoDHG25mK/Af88nyVWAdKB7Fgh bNdjy+joWa5X5aDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1703156956; 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=CGCpOt7yvJg/Baj+l7YgN3+pIt5pBMerQ6avhaamLRk=; b=obs2lYdW0IeMmDnRh6+mcqyBv/dpPm3iKtRwHtHPDd36hOxZ25aiXvp8oPyqWdQVxmxD7x 81hr71UhhdB8zKPAZCe9/+RlKWYEht6DCQuInTI/VbnwLbnHr46ITW2Q3J9auW/TfQhaiq IJGbNhP3BvQyvZ3OJP+o3PSdnO4KC2Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1703156956; 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=CGCpOt7yvJg/Baj+l7YgN3+pIt5pBMerQ6avhaamLRk=; b=5L7BcSKBF7aiALiaurswhJ1TzRUjwbgqVCWEhJmBQAaJyoDHG25mK/Af88nyVWAdKB7Fgh bNdjy+joWa5X5aDA== Received: from imap1.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3E02313725; Thu, 21 Dec 2023 11:09:16 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id vT7BDtwchGWwVAAAD6G6ig (envelope-from ); Thu, 21 Dec 2023 11:09:16 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id A1706A07E3; Thu, 21 Dec 2023 12:09:15 +0100 (CET) Date: Thu, 21 Dec 2023 12:09:15 +0100 From: Jan Kara To: Christoph Hellwig Cc: linux-mm@kvack.org, "Matthew Wilcox (Oracle)" , Jan Kara , David Howells , Brian Foster , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 06/17] writeback: Factor out writeback_finish() Message-ID: <20231221110915.kl2c45mepzzcqnbj@quack3> References: <20231218153553.807799-1-hch@lst.de> <20231218153553.807799-7-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231218153553.807799-7-hch@lst.de> X-Rspamd-Queue-Id: 447291C002B X-Rspam-User: X-Stat-Signature: acpgy4p35qdsj4rjahrh33tobbjy47st X-Rspamd-Server: rspam01 X-HE-Tag: 1703156957-610925 X-HE-Meta: U2FsdGVkX19yOLuLn4YT7Xy2bsn807bSjAK7zxdC59C/+D+RcXcgKWDMyVsPoR9L0S0vG/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ruuz8MVCnzBOjFNZEh09W2iidYZ4EuhIYA45swC9k+QLM8STAVBmc2bvf1vSkNvwTxtsGTY8qAQek5eQrSGBycwrgQG7NThLmq4vEnNIq36yj1VUrDjCw2IGYZHGEiAWV7NwwA0iMwRzsWYvbMVvGQRLVp2YDiB0WW3GcBZ3sWnAuX5CxFiXTCHl6teI+hPdsDtlyuih5+2zc/EbPL2b82rAwIeQQA65ImTrD4d8l/vSoURC6CEzjky397ehweyw== 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 Mon 18-12-23 16:35:42, 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: heavily rebased, reordered and commented struct writeback_control] > Signed-off-by: Christoph Hellwig Looks good. Feel free to add: Reviewed-by: Jan Kara Honza > --- > include/linux/writeback.h | 6 +++ > mm/page-writeback.c | 79 ++++++++++++++++++++------------------- > 2 files changed, 47 insertions(+), 38 deletions(-) > > diff --git a/include/linux/writeback.h b/include/linux/writeback.h > index 833ec38fc3e0c9..390f2dd03cf27e 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,10 @@ struct writeback_control { > */ > struct swap_iocb **swap_plug; > > + /* internal fields used by the ->writepages implementation: */ > + struct folio_batch fbatch; > + int err; > + > #ifdef CONFIG_CGROUP_WRITEBACK > struct bdi_writeback *wb; /* wb this writeback is issued under */ > struct inode *inode; /* inode being written out */ > diff --git a/mm/page-writeback.c b/mm/page-writeback.c > index c798c0d6d0abb4..564d5faf562ba7 100644 > --- a/mm/page-writeback.c > +++ b/mm/page-writeback.c > @@ -2360,6 +2360,29 @@ void tag_pages_for_writeback(struct address_space *mapping, > } > EXPORT_SYMBOL(tag_pages_for_writeback); > > +static void writeback_finish(struct address_space *mapping, > + struct writeback_control *wbc, pgoff_t done_index) > +{ > + folio_batch_release(&wbc->fbatch); > + > + /* > + * For range cyclic writeback we need to remember where we stopped so > + * that we can continue there next time we are called. If we hit the > + * last page and there is more work to be done, wrap back to the start > + * of the file. > + * > + * For non-cyclic writeback we always start looking up at the beginning > + * of the file if we are called again, which can only happen due to > + * -ENOMEM from the file system. > + */ > + if (wbc->range_cyclic) { > + if (wbc->err || wbc->nr_to_write <= 0) > + mapping->writeback_index = done_index; > + else > + mapping->writeback_index = 0; > + } > +} > + > /** > * 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 > @@ -2395,17 +2418,12 @@ int write_cache_pages(struct address_space *mapping, > struct writeback_control *wbc, writepage_t writepage, > void *data) > { > - int ret = 0; > - int done = 0; > int error; > - struct folio_batch fbatch; > int nr_folios; > pgoff_t index; > pgoff_t end; /* Inclusive */ > - pgoff_t done_index; > xa_mark_t tag; > > - folio_batch_init(&fbatch); > if (wbc->range_cyclic) { > index = mapping->writeback_index; /* prev offset */ > end = -1; > @@ -2419,22 +2437,23 @@ int write_cache_pages(struct address_space *mapping, > } else { > tag = PAGECACHE_TAG_DIRTY; > } > - done_index = index; > - while (!done && (index <= end)) { > + > + folio_batch_init(&wbc->fbatch); > + wbc->err = 0; > + > + while (index <= end) { > int i; > > nr_folios = filemap_get_folios_tag(mapping, &index, end, > - tag, &fbatch); > + tag, &wbc->fbatch); > > if (nr_folios == 0) > break; > > for (i = 0; i < nr_folios; i++) { > - struct folio *folio = fbatch.folios[i]; > + struct folio *folio = wbc->fbatch.folios[i]; > unsigned long nr; > > - done_index = folio->index; > - > folio_lock(folio); > > /* > @@ -2481,6 +2500,9 @@ int write_cache_pages(struct address_space *mapping, > folio_unlock(folio); > error = 0; > } > + > + if (error && !wbc->err) > + wbc->err = error; > > /* > * For integrity sync we have to keep going until we > @@ -2496,38 +2518,19 @@ int write_cache_pages(struct address_space *mapping, > * off and media errors won't choke writeout for the > * entire file. > */ > - if (error && !ret) > - ret = error; > - if (wbc->sync_mode == WB_SYNC_NONE) { > - if (ret || wbc->nr_to_write <= 0) { > - done_index = folio->index + nr; > - done = 1; > - break; > - } > + if (wbc->sync_mode == WB_SYNC_NONE && > + (wbc->err || wbc->nr_to_write <= 0)) { > + writeback_finish(mapping, wbc, > + folio->index + nr); > + return error; > } > } > - folio_batch_release(&fbatch); > + folio_batch_release(&wbc->fbatch); > cond_resched(); > } > > - /* > - * For range cyclic writeback we need to remember where we stopped so > - * that we can continue there next time we are called. If we hit the > - * last page and there is more work to be done, wrap back to the start > - * of the file. > - * > - * For non-cyclic writeback we always start looking up at the beginning > - * of the file if we are called again, which can only happen due to > - * -ENOMEM from the file system. > - */ > - if (wbc->range_cyclic) { > - if (done) > - mapping->writeback_index = done_index; > - else > - mapping->writeback_index = 0; > - } > - > - return ret; > + writeback_finish(mapping, wbc, 0); > + return 0; > } > EXPORT_SYMBOL(write_cache_pages); > > -- > 2.39.2 > -- Jan Kara SUSE Labs, CR