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 54146C35274 for ; Thu, 21 Dec 2023 11:24:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D631B6B007E; Thu, 21 Dec 2023 06:24:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CEAED8D0005; Thu, 21 Dec 2023 06:24:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B62C08D0001; Thu, 21 Dec 2023 06:24:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A64BB6B007E for ; Thu, 21 Dec 2023 06:24:58 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6EFE9140356 for ; Thu, 21 Dec 2023 11:24:58 +0000 (UTC) X-FDA: 81590593476.02.155C949 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf05.hostedemail.com (Postfix) with ESMTP id DC16510001F for ; Thu, 21 Dec 2023 11:24:55 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BTe4KvlF; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=nyqi6SfY; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BTe4KvlF; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=nyqi6SfY; dmarc=none; spf=pass (imf05.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 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=1703157896; 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=gpLOwhQDWouiGcVDXpIifh6pZTYZjbA5NrwZ5EtKOwU=; b=TNVNr1S2ZNRIxSZ3DXJXiuMn2eA8WNHy9gR9FKl+NNlby9XXue7LT0B4lN+rOC4ULVihwg ZxeD9V3e11kEI5yUANhf6PvCG/thPZn+DULbo0fJRNi6KkvQpta9wlVzGZEGt6Mx2WlEQU ToWeX5TmUaBtOOTInYc5i5FzuvTBUKc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BTe4KvlF; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=nyqi6SfY; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BTe4KvlF; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=nyqi6SfY; dmarc=none; spf=pass (imf05.hostedemail.com: domain of jack@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703157896; a=rsa-sha256; cv=none; b=FMFlLX7rs3Qq0a/BkZnpjp5KBTDd3t7j9F4dZZ19TTuMsfE9dsFNFIb8VlddiKsQHaA056 J4sjvBXNBllsX2WlPWi5QxVSt5bxGMRgI+4U1JlPqzfHx85hYkiEHUIJCBfaJhiMGi29jl GIg1j1q4ZV9BXCuDXGF4yZgf8w0PXoo= 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 36D911FB42; Thu, 21 Dec 2023 11:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1703157894; 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=gpLOwhQDWouiGcVDXpIifh6pZTYZjbA5NrwZ5EtKOwU=; b=BTe4KvlFeMKXD4GzKy6tugrUnZv+8GzxU8Pl0LlKXOQ8e1voM9n0fr4cv+0IC0ZpEedEV7 1QYzLhM6wXotz9D48H4nwucDCrJdEjXQyg/jhvF6IFr+C1Mf015IAL5D7OpPL/Y+GrUF0R HLAEoehPBvcnIQu73kjH5HYmqp9eOCY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1703157894; 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=gpLOwhQDWouiGcVDXpIifh6pZTYZjbA5NrwZ5EtKOwU=; b=nyqi6SfYR/+bfXNK4QMDxTcneXkkOuV59UF9iRYKAfmZVx7KGCkj8RRbxSGBYW0jgY8ZjO TCwKp/mJyF2cm7Dg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1703157894; 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=gpLOwhQDWouiGcVDXpIifh6pZTYZjbA5NrwZ5EtKOwU=; b=BTe4KvlFeMKXD4GzKy6tugrUnZv+8GzxU8Pl0LlKXOQ8e1voM9n0fr4cv+0IC0ZpEedEV7 1QYzLhM6wXotz9D48H4nwucDCrJdEjXQyg/jhvF6IFr+C1Mf015IAL5D7OpPL/Y+GrUF0R HLAEoehPBvcnIQu73kjH5HYmqp9eOCY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1703157894; 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=gpLOwhQDWouiGcVDXpIifh6pZTYZjbA5NrwZ5EtKOwU=; b=nyqi6SfYR/+bfXNK4QMDxTcneXkkOuV59UF9iRYKAfmZVx7KGCkj8RRbxSGBYW0jgY8ZjO TCwKp/mJyF2cm7Dg== 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 27C1B13725; Thu, 21 Dec 2023 11:24:54 +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 8VZvCYYghGVCWgAAD6G6ig (envelope-from ); Thu, 21 Dec 2023 11:24:54 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id AC402A07E3; Thu, 21 Dec 2023 12:24:53 +0100 (CET) Date: Thu, 21 Dec 2023 12:24:53 +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 09/17] writeback: Simplify the loops in write_cache_pages() Message-ID: <20231221112453.4gggfki67lxwtor7@quack3> References: <20231218153553.807799-1-hch@lst.de> <20231218153553.807799-10-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231218153553.807799-10-hch@lst.de> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: DC16510001F X-Stat-Signature: 7e1hg4r7jrfwfj93h487jz5d4nkx6h3x X-HE-Tag: 1703157895-133181 X-HE-Meta: U2FsdGVkX18x8CTMPAOmk47XbcvON5g4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msLb33EtmqHaxJBOO3FMYEnlrOxehOJj2ZCFWYzyYP0FsEc4ngDYEHGyVV1P/+oXlH30jhJNeQAszm9sP5mL1NJDO+1FFjcJ5bRw45Gs+JKnB0crFdAtRWwXx7NsBmTO1Wrwh1YDBa5+sW5tQEWedQtNmknAZUKNcOPAI6VOYAqBfcnazYmh33R2YOe1BVcIAra4ELbpfw+a6oGpuAeL1EqFBhExTW+vDXrrazbEKuchX6Ujkq8lOs9rIpNfLNwnN 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:45, Christoph Hellwig wrote: > From: "Matthew Wilcox (Oracle)" > > Collapse the two nested loops into one. This is needed as a step > towards turning this into an iterator. > > Note that this drops the "index <= end" check in the previous outer loop > and just relies on filemap_get_folios_tag() to return 0 entries when > index > end. This actually has a subtle implication when end == -1 > because then the returned index will be -1 as well and thus if there is > page present on index -1, we could be looping indefinitely. But as the > comment in filemap_get_folios_tag documents this as already broken anyway > we should not worry about it here either. The fix for that would > probably a change to the filemap_get_folios_tag() calling convention. > > Signed-off-by: Matthew Wilcox (Oracle) > [hch: updated the commit log based on feedback from Jan Kara] > Signed-off-by: Christoph Hellwig Looks good. Feel free to add: Reviewed-by: Jan Kara Honza > --- > mm/page-writeback.c | 94 ++++++++++++++++++++++----------------------- > 1 file changed, 46 insertions(+), 48 deletions(-) > > diff --git a/mm/page-writeback.c b/mm/page-writeback.c > index 2a004c0b9bdfbf..c7983ea3040be4 100644 > --- a/mm/page-writeback.c > +++ b/mm/page-writeback.c > @@ -2473,6 +2473,7 @@ int write_cache_pages(struct address_space *mapping, > { > int error; > pgoff_t end; /* Inclusive */ > + int i = 0; > > if (wbc->range_cyclic) { > wbc->index = mapping->writeback_index; /* prev offset */ > @@ -2487,63 +2488,60 @@ int write_cache_pages(struct address_space *mapping, > folio_batch_init(&wbc->fbatch); > wbc->err = 0; > > - while (wbc->index <= end) { > - int i; > - > - writeback_get_batch(mapping, wbc); > + for (;;) { > + struct folio *folio; > + unsigned long nr; > > + if (i == wbc->fbatch.nr) { > + writeback_get_batch(mapping, wbc); > + i = 0; > + } > if (wbc->fbatch.nr == 0) > break; > > - for (i = 0; i < wbc->fbatch.nr; i++) { > - struct folio *folio = wbc->fbatch.folios[i]; > - unsigned long nr; > + folio = wbc->fbatch.folios[i++]; > > - folio_lock(folio); > - if (!should_writeback_folio(mapping, wbc, folio)) { > - folio_unlock(folio); > - continue; > - } > + folio_lock(folio); > + if (!should_writeback_folio(mapping, wbc, folio)) { > + folio_unlock(folio); > + continue; > + } > > - trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); > + trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); > > - error = writepage(folio, wbc, data); > - nr = folio_nr_pages(folio); > - wbc->nr_to_write -= nr; > + error = writepage(folio, wbc, data); > + nr = folio_nr_pages(folio); > + wbc->nr_to_write -= nr; > > - /* > - * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return > - * value. Eventually all instances should just unlock > - * the folio themselves and return 0; > - */ > - if (error == AOP_WRITEPAGE_ACTIVATE) { > - folio_unlock(folio); > - error = 0; > - } > - > - if (error && !wbc->err) > - wbc->err = error; > + /* > + * Handle the legacy AOP_WRITEPAGE_ACTIVATE magic return value. > + * Eventually all instances should just unlock the folio > + * themselves and return 0; > + */ > + if (error == AOP_WRITEPAGE_ACTIVATE) { > + folio_unlock(folio); > + error = 0; > + } > > - /* > - * For integrity sync we have to keep going until we > - * have written all the folios we tagged for writeback > - * prior to entering this loop, even if we run past > - * wbc->nr_to_write or encounter errors. This is > - * because the file system may still have state to clear > - * for each folio. We'll eventually return the first > - * error encountered. > - * > - * For background writeback just push done_index past > - * this folio so that we can just restart where we left > - * off and media errors won't choke writeout for the > - * entire file. > - */ > - if (wbc->sync_mode == WB_SYNC_NONE && > - (wbc->err || wbc->nr_to_write <= 0)) { > - writeback_finish(mapping, wbc, > - folio->index + nr); > - return error; > - } > + if (error && !wbc->err) > + wbc->err = error; > + > + /* > + * For integrity sync we have to keep going until we have > + * written all the folios we tagged for writeback prior to > + * entering this loop, even if we run past wbc->nr_to_write or > + * encounter errors. This is because the file system may still > + * have state to clear for each folio. We'll eventually return > + * the first error encountered. > + * > + * For background writeback just push done_index past this folio > + * so that we can just restart where we left off and media > + * errors won't choke writeout for the entire file. > + */ > + if (wbc->sync_mode == WB_SYNC_NONE && > + (wbc->err || wbc->nr_to_write <= 0)) { > + writeback_finish(mapping, wbc, folio->index + nr); > + return error; > } > } > > -- > 2.39.2 > -- Jan Kara SUSE Labs, CR