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 47A4EC48BC3 for ; Tue, 20 Feb 2024 13:39:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A150E6B0075; Tue, 20 Feb 2024 08:39:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C4D96B0078; Tue, 20 Feb 2024 08:39:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 865506B007B; Tue, 20 Feb 2024 08:39:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 778596B0075 for ; Tue, 20 Feb 2024 08:39:00 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3B64E40643 for ; Tue, 20 Feb 2024 13:39:00 +0000 (UTC) X-FDA: 81812288040.04.F613DC8 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf24.hostedemail.com (Postfix) with ESMTP id D447318002C for ; Tue, 20 Feb 2024 13:38:57 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ejFrD49l; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=aIqfdUJ3; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=nNp+6yuA; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=1DWPUx8X; dmarc=none; spf=pass (imf24.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=1708436338; a=rsa-sha256; cv=none; b=odchxPGXh8NdrZlBAH4kJBAevWrxg6qyeS/3aA0aSrQgYBuFeBtsSfugVMvOA1NLEAfFSp DVCG5LvMNJL7LorLDXfot9rQjjAXC8W3z5OHJXm6/5Rz+ie4r+0oawGwxR3ux8euVs+JrF q1/SRSQzpc4aLVXwinyZuQ3QCCNfiT4= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ejFrD49l; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=aIqfdUJ3; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=nNp+6yuA; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=1DWPUx8X; dmarc=none; spf=pass (imf24.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=1708436338; 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=4gc6aG0QdzGRR3SUNO2U5+jwFcTZv8KeajxmLh7FrD0=; b=ByyFQ0kLIUZQLJjlleNUlTz75Lq00ZLn71kAdJFF4x+JEB9dGNLvmDrS01yc3yI009Sloy uZHYEXELcCz44q9rSh15qjEAApWwgrQPWUocdvSqAFVKLUipG7/RR0QfQMBs1t9vwikGfg 9XMJ4m1X+Pd499REBa3EK4c306pJ014= 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 0471121F35; Tue, 20 Feb 2024 13:38:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1708436336; 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=4gc6aG0QdzGRR3SUNO2U5+jwFcTZv8KeajxmLh7FrD0=; b=ejFrD49l2Zjrl8m0RIaICznGQhgOwkrgWBxJ8nf50ceVLQLkONglOo+mprwoVM8SHxHFHy B7Za25hHot8tJhQ90kGt6XwGm99kfOOmCh/W+Kq1WoUUhDpLIahdCqCCkxzj/htTGgt3hq +w0DhXx15543J47YOXk1y7X1Br7vpug= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1708436336; 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=4gc6aG0QdzGRR3SUNO2U5+jwFcTZv8KeajxmLh7FrD0=; b=aIqfdUJ3fWT8QPt8H8QdhPgrHAQLcVufliPIPEyiq/vH0nmBmgZ/DxRKb7bkh9KGoWX+J+ UR23e0qP/YztuWBA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1708436335; 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=4gc6aG0QdzGRR3SUNO2U5+jwFcTZv8KeajxmLh7FrD0=; b=nNp+6yuAQGQSvTgSNWV69Pltbi31l8oyGWPC8jyjWCdRA9xnVr0TvMSbG5RYw/cOM2d6Rd uzKay6y3EuG+1q65IoBLq2iJS9iFIr9NX5Ex0g+drR7nO6Z3m0f5NQOFeHub9D9rhfEjnq 6wmVboHNvwsu00Hdk4B1rkPpIaWP1IY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1708436335; 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=4gc6aG0QdzGRR3SUNO2U5+jwFcTZv8KeajxmLh7FrD0=; b=1DWPUx8XvFEqzkm3CCXQ3aLfPF+vY/tUZ9UTxP3UbOpwBzaMPxJKok1p4NrBDmYdExysl8 WJ7jDhVbkGnjKuDg== 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 EA164139EF; Tue, 20 Feb 2024 13:38:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id qGjiOG6r1GXlIwAAn2gu4w (envelope-from ); Tue, 20 Feb 2024 13:38:54 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 8E3B4A0807; Tue, 20 Feb 2024 14:38:54 +0100 (CET) Date: Tue, 20 Feb 2024 14:38:54 +0100 From: Jan Kara To: Matthew Wilcox Cc: Linus Torvalds , Andrew Morton , Jens Axboe , Jan Kara , Linux-MM , Vishal Moola Subject: Re: [patch 041/178] mm: provide filemap_range_needs_writeback() helper Message-ID: <20240220133854.5qy5yiifek4cyc4d@quack3> References: <20210429225251.02b6386d21b69255b4f6c163@linux-foundation.org> <20210430055518.KCtlWixJr%akpm@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D447318002C X-Stat-Signature: 9mbfjitnzr5zxncbawfqtpmf9ydfc7sm X-HE-Tag: 1708436337-709103 X-HE-Meta: U2FsdGVkX1+smAmPkV8UjIt9RUL11SmKq/pU7vTu9LMoWfSF4YWxbcZCEUiy0NagIjL55TATiBS39e3Wr4w8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9QATK3bPaKPimAiic5VyZbTq/+MEGGj9ycfr726Q/3Z/p6PnB1pm9nUCorKGswKi13IMdEnvWGpfcvVVROX3tlmsLEOPz/IyF7U8dY5tXcgEQeeXlwbmCDbn9MeZd7aNWatvrQ1WLznDm7vV1g2IlEGi8DdfDvIujmfHsmg0+IjxnpTtzTgzJ1siO8rnAZE3QwANNkfiB7T9rRL1m5rzzKHRA4RUi+iMmw2hjxfHTIUENU7qXr/gbIECcTXivNgmM3xWyoo5jhjLB9yHGX/z1A/Rxh6QsIIhSkrfN2N0w7g= 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 19-02-24 21:59:44, Matthew Wilcox wrote: > On Sun, May 09, 2021 at 08:40:25PM +0100, Matthew Wilcox wrote: > > On Fri, Apr 30, 2021 at 09:50:29AM -0700, Linus Torvalds wrote: > > > On Thu, Apr 29, 2021 at 10:55 PM Andrew Morton > > > wrote: > > > > + rcu_read_lock(); > > > > + xas_for_each(&xas, page, max) { > > > > + if (xas_retry(&xas, page)) > > > > + continue; > > > > + if (xa_is_value(page)) > > > > + continue; > > > > + if (PageDirty(page) || PageLocked(page) || PageWriteback(page)) > > > > + break; > > > > + } > > > > + rcu_read_unlock(); > > > > > > Whee. This looks very very expensive indeed. > > > > > > Why is is going to each page, why does it care about locked when the > > > simple early cases did not? > > > > I was hoping Jens would answer this, but I guess he missed it so far. > > I don't know why it now cares about whether the page is locked or not. > > I presume it's not even the slightest bit slow for Jens because the > > common case is that there are no pages in the range, and so we never > > check any pages. > > Looking at this again, since the change to operate on folios, we're now > living dangerously as we don't have a reference on the folio, so it can > now be freed, turned into a tail page and trigger the VM_BUG_ON_PGFLAGS() > in folio_flags(). > > Rather than take a refcount on the folio to prevent that from happening, > we can just examine the pagecache flags in the XArray. like this. > Assuming there really isn't a need to check the locked flag (which for > obvious reasons we don't mirror into the xarray marks). > > Jens, WDYT? > > diff --git a/mm/filemap.c b/mm/filemap.c > index 750e779c23db..09f3851157f9 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -640,10 +640,8 @@ bool filemap_range_has_writeback(struct address_space *mapping, > xas_for_each(&xas, folio, max) { > if (xas_retry(&xas, folio)) > continue; > - if (xa_is_value(folio)) > - continue; > - if (folio_test_dirty(folio) || folio_test_locked(folio) || > - folio_test_writeback(folio)) > + if (xas_get_mark(&xas, PAGECACHE_TAG_DIRTY) || > + xas_get_mark(&xas, PAGECACHE_TAG_WRITEBACK)) > break; > } > rcu_read_unlock(); This looks good but it relies on a subtle detail in our writeback handling that we set the PAGECACHE_TAG_WRITEBACK tag in __folio_start_writeback() and only after that clear the PAGECACHE_TAG_DIRTY there (although we've cleared the page dirty bit much earlier in clear_page_dirty_for_io()). So please add a comment to filemap_range_has_writeback() and to __folio_start_writeback() about this to at least somewhat reduce the chances somebody is going to change the code and break this... Thanks! Honza > -- Jan Kara SUSE Labs, CR