Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp6703236rdb; Fri, 15 Dec 2023 06:16:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfXayMF5h41Of7buZzjlxrQGTgdGIJr4RnRG3xXZKun/jf6nZrpNt66YMI5jNKgkbC+WAO X-Received: by 2002:a05:6a20:8e07:b0:190:2973:512f with SMTP id y7-20020a056a208e0700b001902973512fmr7865473pzj.111.1702649811326; Fri, 15 Dec 2023 06:16:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702649811; cv=none; d=google.com; s=arc-20160816; b=wLJCgJ2oig6sAwlVS06mwP/gxf2pajTf+N1c94ps/T++BFo/+GEI1KxrcSHAwJpGV8 h8aVEWeq7rBnfaa1Rzd6nMOSDEb81CIjhOwSCoKwdOJCZmhuKE0qMx9lPiR+9cJU/oR/ Xxmf0nL0AEJgWbsbbpW13X/7wGrLZbFn+gHegr8WIGFgem6tn42CWGafByXyMsG+iF+Y y6jRWzQFsoItEg4PC4OIBAXHeLTfW4sY41exbtlUfxXbiVUgW/EZjXMX1+T1tUtLJXf3 EgRuNl7MtzVQ8/5VCs5LWsmL8iJjg6TaQ/haZ+jPjAp9YzR75RSyhJXfHeiyKBmNfwdx NY4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=WyTCFcaBhr8n3TgugW3kFxWX67Uddaa/DXLnxQwKgFw=; fh=/w0dc2O7V6smQOgU7WkICsW4zuan5V76Fq7j5x7mZ4o=; b=K/kbWEndg8YLhyCS+QdVj1xbfiAXF+LGhMrA+bNxx8ljqW00nUF8rT3Hd61ngzPLZ+ sXlcY1EAcVe0H21Y8qWSxJBWEUOcugcNp1ByVpqoOLonMkX3KdqxUsZBK7xp/zLnccXd PxGPhRFBq7wRIjEI8k6AF/ss6tOSFPAitQyrJO5U5BIxVYt4ImqntgJTh3VMyKROYmUu GP3GzcLP7lPissjUgRayUU1rfKxjCuD1M3nW7vWzaTITEJVa+4acjmo0mTB0UpoS6gNE iNJ4VAs5ASW54ieO5upY8u7HSitcvyw3qTf9fL0vHxovnO3V4RfgGawDsRqc5tbKj6BZ Jk1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=a0mcWyis; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=RZQHWaS2; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=a0mcWyis; dkim=neutral (no key) header.i=@suse.cz header.b=RZQHWaS2; spf=pass (google.com: domain of linux-kernel+bounces-1096-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1096-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 11-20020a63154b000000b005bd641c3614si13018703pgv.769.2023.12.15.06.16.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 06:16:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1096-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=a0mcWyis; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=RZQHWaS2; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=a0mcWyis; dkim=neutral (no key) header.i=@suse.cz header.b=RZQHWaS2; spf=pass (google.com: domain of linux-kernel+bounces-1096-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1096-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id F2104B228AD for ; Fri, 15 Dec 2023 14:16:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E93F3033C; Fri, 15 Dec 2023 14:16:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="a0mcWyis"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="RZQHWaS2"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="a0mcWyis"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="RZQHWaS2" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87BC830331; Fri, 15 Dec 2023 14:16:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231214132544.376574-4-hch@lst.de> X-Spam-Level: X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-2.81 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.cz:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_SEVEN(0.00)[7]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] Authentication-Results: smtp-out2.suse.de; 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 X-Spam-Score: -2.81 X-Rspamd-Queue-Id: 869A51F837 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