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 B6B6DC41535 for ; Fri, 15 Dec 2023 14:16:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CF046B0726; Fri, 15 Dec 2023 09:16:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 357216B0727; Fri, 15 Dec 2023 09:16:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1AA096B0728; Fri, 15 Dec 2023 09:16:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0464B6B0726 for ; Fri, 15 Dec 2023 09:16:36 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C14EF160D6F for ; Fri, 15 Dec 2023 14:16:35 +0000 (UTC) X-FDA: 81569253150.09.82D2088 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf16.hostedemail.com (Postfix) with ESMTP id 64225180024 for ; Fri, 15 Dec 2023 14:16:33 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=a0mcWyis; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RZQHWaS2; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=a0mcWyis; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RZQHWaS2; dmarc=none; spf=pass (imf16.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=1702649793; 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=WyTCFcaBhr8n3TgugW3kFxWX67Uddaa/DXLnxQwKgFw=; b=4RU5mFL8BzBuC4q7i5HJq5o8R3fTQM9xU40k1zeWgqzwVyIQnODgLn7eh3TCIYSlQquOnK 0bD5y0alaPVtATKXhFVws/Pv3o6HOy6iUjeioCqtGlIg/+xYD1HF8XpzwPLGqdTmt+bqRs chwiHVvN+AWb/fbrpfs52XyifNjF4x8= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=a0mcWyis; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RZQHWaS2; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=a0mcWyis; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RZQHWaS2; dmarc=none; spf=pass (imf16.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=1702649793; a=rsa-sha256; cv=none; b=ls06mTZ8gxhEOqhjWplFKXwmzGcsavUrSySulvj7S2IEKmMWdF9Vj1xW7sFAbo6/1G1pnC U79O604PU31WYzFZsJs76jrip93vS9yKPoSlgdg8Lpw+LtFirAwCW4j9mXn32QoDiDFl0O sFMHpANCYjVntiB7uT41puPjn2xUCC4= 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-out2.suse.de (Postfix) with ESMTPS id 869A51F837; Fri, 15 Dec 2023 14:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1702649791; 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=WyTCFcaBhr8n3TgugW3kFxWX67Uddaa/DXLnxQwKgFw=; b=a0mcWyisO6oSDqgiEYEN99ZUt2djbMmRTgp2mB2ypjTWYxyUWstA9KdRAi18LcXGtDEvfd 3XN74BayKsu7MMLf1848JRe2hdaoowSenY08l8ZIY0IKHmaXSG4ZAP7RHQKpPB3dtWkXJh +kLsWMZpFtfMRJah8UpJvLSkp1iz8oI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1702649791; 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=WyTCFcaBhr8n3TgugW3kFxWX67Uddaa/DXLnxQwKgFw=; b=RZQHWaS2UNz88Bo5fCF0D/vj1Cv6VObgJ4HWkOz2fdROGvaea1VdZcofzfNs5PZ9zBuiyM /jOYiGmrUKB7hKDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1702649791; 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=WyTCFcaBhr8n3TgugW3kFxWX67Uddaa/DXLnxQwKgFw=; b=a0mcWyisO6oSDqgiEYEN99ZUt2djbMmRTgp2mB2ypjTWYxyUWstA9KdRAi18LcXGtDEvfd 3XN74BayKsu7MMLf1848JRe2hdaoowSenY08l8ZIY0IKHmaXSG4ZAP7RHQKpPB3dtWkXJh +kLsWMZpFtfMRJah8UpJvLSkp1iz8oI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1702649791; 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=WyTCFcaBhr8n3TgugW3kFxWX67Uddaa/DXLnxQwKgFw=; b=RZQHWaS2UNz88Bo5fCF0D/vj1Cv6VObgJ4HWkOz2fdROGvaea1VdZcofzfNs5PZ9zBuiyM /jOYiGmrUKB7hKDQ== 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 7832213A08; Fri, 15 Dec 2023 14:16:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id oSxYHb9ffGXsaAAAn2gu4w (envelope-from ); Fri, 15 Dec 2023 14:16:31 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 1EBCEA07E0; Fri, 15 Dec 2023 15:16:31 +0100 (CET) Date: Fri, 15 Dec 2023 15:16:31 +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 03/11] writeback: Factor should_writeback_folio() out of write_cache_pages() Message-ID: <20231215141631.aooan5rby6fwfdof@quack3> References: <20231214132544.376574-1-hch@lst.de> <20231214132544.376574-4-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231214132544.376574-4-hch@lst.de> X-Rspam-User: X-Stat-Signature: z7pkh581q5tdrttz5yubfexhi3pkpzio X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 64225180024 X-HE-Tag: 1702649793-51505 X-HE-Meta: U2FsdGVkX19R/+ZaDobJT3/GkVR0HqOdUeOyJ7XqfHUZqJkyBJ91r5086bDLr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/OPKJyhIV1o+07wyt9zFsuwSuzqpVvydZzUgA6u5Nwe1qxmITNd4wxAu65bFqvzgrikCVwPto8fbAHiqVstIa9nFmmDLcLpsSJ2x6YUbE5mj/nSvcB7wqEi/+eQHrFwkgpPC50ki33PN5D6rCr/+oc9sXFGSi5RFmuQjH15LGJV19pqHssNyttt+NEcJ0jz0eUNH+PL7iYWGRG6PG1Y166/EeVFaOlLztbrrn2o1Zl9Pr 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:36, Christoph Hellwig wrote: > From: "Matthew Wilcox (Oracle)" > > Reduce write_cache_pages() by about 30 lines; much of it is commentary, > but it all bundles nicely into an obvious function. > > Signed-off-by: Matthew Wilcox (Oracle) > Signed-off-by: Christoph Hellwig I like this! Feel free to add: Reviewed-by: Jan Kara Honza > --- > mm/page-writeback.c | 59 ++++++++++++++++++++++++--------------------- > 1 file changed, 32 insertions(+), 27 deletions(-) > > diff --git a/mm/page-writeback.c b/mm/page-writeback.c > index 5d33e7b468e2cc..5a3df8665ff4f9 100644 > --- a/mm/page-writeback.c > +++ b/mm/page-writeback.c > @@ -2394,6 +2394,36 @@ static void writeback_get_batch(struct address_space *mapping, > &wbc->fbatch); > } > > +static bool should_writeback_folio(struct address_space *mapping, > + struct writeback_control *wbc, struct folio *folio) > +{ > + /* > + * Folio truncated or invalidated. We can freely skip it then, > + * even for data integrity operations: the folio has disappeared > + * concurrently, so there could be no real expectation of this > + * data integrity operation even if there is now a new, dirty > + * folio at the same pagecache index. > + */ > + if (unlikely(folio->mapping != mapping)) > + return false; > + > + /* Did somebody write it for us? */ > + if (!folio_test_dirty(folio)) > + return false; > + > + if (folio_test_writeback(folio)) { > + if (wbc->sync_mode == WB_SYNC_NONE) > + return false; > + folio_wait_writeback(folio); > + } > + > + BUG_ON(folio_test_writeback(folio)); > + if (!folio_clear_dirty_for_io(folio)) > + return false; > + > + return true; > +} > + > /** > * 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 > @@ -2462,38 +2492,13 @@ int write_cache_pages(struct address_space *mapping, > wbc->done_index = folio->index; > > folio_lock(folio); > - > - /* > - * Page truncated or invalidated. We can freely skip it > - * then, even for data integrity operations: the page > - * has disappeared concurrently, so there could be no > - * real expectation of this data integrity operation > - * even if there is now a new, dirty page at the same > - * pagecache address. > - */ > - if (unlikely(folio->mapping != mapping)) { > -continue_unlock: > + if (!should_writeback_folio(mapping, wbc, folio)) { > folio_unlock(folio); > continue; > } > > - if (!folio_test_dirty(folio)) { > - /* someone wrote it for us */ > - goto continue_unlock; > - } > - > - if (folio_test_writeback(folio)) { > - if (wbc->sync_mode != WB_SYNC_NONE) > - folio_wait_writeback(folio); > - else > - goto continue_unlock; > - } > - > - BUG_ON(folio_test_writeback(folio)); > - if (!folio_clear_dirty_for_io(folio)) > - goto continue_unlock; > - > trace_wbc_writepage(wbc, inode_to_bdi(mapping->host)); > + > error = writepage(folio, wbc, data); > nr = folio_nr_pages(folio); > if (unlikely(error)) { > -- > 2.39.2 > -- Jan Kara SUSE Labs, CR