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 25AAEE784B0 for ; Mon, 2 Oct 2023 09:55:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E4E38D0015; Mon, 2 Oct 2023 05:55:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 695028D0001; Mon, 2 Oct 2023 05:55:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55C708D0015; Mon, 2 Oct 2023 05:55:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 442448D0001 for ; Mon, 2 Oct 2023 05:55:28 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 113CF1601CE for ; Mon, 2 Oct 2023 09:55:28 +0000 (UTC) X-FDA: 81300063936.17.1ED8EF2 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf06.hostedemail.com (Postfix) with ESMTP id EA60618000D for ; Mon, 2 Oct 2023 09:55:25 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BwyfoNRW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="FPv/6jZ7"; dmarc=none; spf=pass (imf06.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 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=1696240526; 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=a5qSHb2HY4O8xrSTCIffNnESicw2f6a/GZiMI+Le440=; b=ow2Af4yrBkxGBypFs2XLuhD4141CIXCOC9jzfvnjp+f4GokvinGfloFOYdd7HF0FG/n5Qk AdpyFQt0Mx9p620IARIvCHBBK/aaZ+c/8NZvKcG7nFgvVvdyLWbyHarf68WD5VRoYpB6e3 Gdkq9pIxobiMlAf3cU+X9KSyO68pNtM= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=BwyfoNRW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b="FPv/6jZ7"; dmarc=none; spf=pass (imf06.hostedemail.com: domain of jack@suse.cz designates 195.135.220.28 as permitted sender) smtp.mailfrom=jack@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696240526; a=rsa-sha256; cv=none; b=VtXQyqTI+SQGXX9d/cTwWxsf5nAH27j4173IT1uPiRjzqXBq0FqjobIQuZRJNfQZePJcvu RAJieW6sJ4L4HDB3rld6RLRXmYPlD47HjTFxNjSKUTWQPB866LjawLKDDCqKJuMz6KHOrf 7TvdrnYf8AgeZeGt51C5+UTZQYqwTcs= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B90F82185A; Mon, 2 Oct 2023 09:55:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1696240523; 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=a5qSHb2HY4O8xrSTCIffNnESicw2f6a/GZiMI+Le440=; b=BwyfoNRWkaue7UlzJq8yzWf5se6SWP9HRooAzqRkIdEmCRyV+PDH5v/Y3Gxib+XuSJzGwt N8qAAlg6ZvoYeec2zurYZzNcsY0tY4K6NeG4jsWXkGSGcWDAVXi8L77it3P2fyq+xsvqPA mI+cvpcEbLP3Ktx8QLSOUmW0zNfPqK0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1696240523; 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=a5qSHb2HY4O8xrSTCIffNnESicw2f6a/GZiMI+Le440=; b=FPv/6jZ7LK9Jbe325/Ith2a3jrIj4f1jDpacojNccVHQKwc5wQBlJPuQYC+hRPZ5wO72Wt kHZ2Q9GLb48tCkBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id ABF5813434; Mon, 2 Oct 2023 09:55:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ZJPoKYuTGmUXUgAAMHmgww (envelope-from ); Mon, 02 Oct 2023 09:55:23 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 48D3FA07C9; Mon, 2 Oct 2023 11:55:23 +0200 (CEST) Date: Mon, 2 Oct 2023 11:55:23 +0200 From: Jan Kara To: Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Matthew Wilcox , Jan Kara Subject: Re: [PATCH] mm/filemap: clarify filemap_fault() comments for not uptodate case Message-ID: <20231002095523.6gttx365tvfaeexb@quack3> References: <20230930231029.88196-1-lstoakes@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230930231029.88196-1-lstoakes@gmail.com> X-Rspamd-Queue-Id: EA60618000D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: aq6cex7u6mbn3j8iz3mb1sipcrepe9tx X-HE-Tag: 1696240525-956978 X-HE-Meta: U2FsdGVkX18JgWQ4sZtq5WXN3KetpMpT/5frRXREXkTeUEoa1wzohW/XCXlshJZeusSAt6XmrxKx1U1cW416jUhuAH+4zvc+nnb+5kx0DgnCJ71P+z3MhZzx6Smqt5NZ8o1SMyloEcC2545t+lY307KSrI+mm2s6gkyEp/1rwzhykwFcJSISuzUMe25cvY9GUf7LDokwZYjwPobGlbGZQcp8uaw/VTELaAZ83o4vhpRGPze/9vNh88Bw6421cY2zRFi8MqrHfD0w3EUAcV0twunJSoeaDExtHfUxFbw/KB3krfRINzhXyn4V9Moy81W1Cku1+mtEXZcy1wjMY3+j9UpFSCJSYh94UASHMvnHk4utYpTQjIzrW3DdypKy3F4L6n2o/dgfbaA6OUg9g1CCIeNRq6H6QF4NzZDqc/78WeZSzfEE+09YVbbCUsHvh6v0E7DDERSMYn3zhK387Cne9NQsGsrMeJmULMvIxh3snLXvhqPuRHihA6yPcXjiZfTVGLRivkt4tfR5h9TJEaiF/uPsk+Hgn84mJa5TRfxaJ9d/70ZvRkqvHUYc4WtflPMoaaVLbC8uu5NoT5vGH2HIIVjXZYqC3nPZSQALYtyawD55Op4MyzW8ZFDMHrePAGBfuRxu1DhSJlY5iF6md5BErROwbjLq47YW3ALofo9Mq1x6frHGX0cSxv9CBrphi8wxk9P6xurcoDT3pM6Eh7Cwwgl+eAGXOZVC84q8N7BldJeIpG0r8bEje4H1/R6wx07VPp0+z0CkKnvP5GJoFSV7YYkahKqAl1GFEj1TM+PWTyOFjaPcsJmF4trEwHQCwGdq+GhH8+QwPB4PStgmvd9wH0eo17Iwr6RaSalSVactlNLK4Dp8m9F7m0cqzZt24NO0xsVrtndE+XlrjVE1MaQwpJCWarNgUOdupFKm2sOggsJUbZDnx/sJCra07SeY3E/RzFPrwQZMg0VGUiSueLu 4jNKYr87 8OsUCddT0ysHhsbOaWZ0PT+Pf0UkZMBtPb+UvoU4Q1+FM3F9sAxAQuuUhn3sMOfzjmG4e7IMZ6IzqLLwuuTcXRGNowldBVvyJXzsYovt+yRNXlsn0tKbEXA/ax+b9FCa7SLi8kvi/5rGRd67pOJMsvAwNmBg2i8PSTt6Jxmqdoi1fBCxmcmeL/BwtzhJGy2o9KxV5i+HU/Z+ixX7W2M9OkGU4Ug6aWoxg6f4truVw88CGtClMnCQ0VCoN9buyf/NLWpnP3UN07iTRlqT5gHytdwrpQc8DXxldbINBbDEI9csNQfqs/sQmdoHM9WJqhtJoULya 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: On Sun 01-10-23 00:10:29, Lorenzo Stoakes wrote: > The existing comments in filemap_fault() suggest that, after either a minor > fault has occurred and filemap_get_folio() found a folio in the page cache, > or a major fault arose and __filemap_get_folio(FGP_CREATE...) did the job > (having relied on do_sync_mmap_readahead() or filemap_read_folio() to read > in the folio), the only possible reason it could not be uptodate is because > of an error. > > This is not so, as if, for instance, the fault occurred within a VMA which > had the VM_RAND_READ flag set (via madvise() with the MADV_RANDOM flag > specified), this would cause even synchronous readahead to fail to read in > the folio. > > I confirmed this by dropping page caches and faulting in memory madvise()'d > this way, observing that this code path was reached on each occasion. > > Clarify the comments to include this case, and additionally update the > comment recently added around the invalidate lock logic to make it clear > the comment explicitly refers to the minor fault case. > > In addition, while we're here, refer to folios rather than pages. > > Signed-off-by: Lorenzo Stoakes After the alignment fixup the patch looks good to me. Feel free to add: Reviewed-by: Jan Kara Honza > --- > mm/filemap.c | 19 +++++++++++++------ > 1 file changed, 13 insertions(+), 6 deletions(-) > > diff --git a/mm/filemap.c b/mm/filemap.c > index d285ec5f9162..959694a2ade7 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -3308,21 +3308,28 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) > VM_BUG_ON_FOLIO(!folio_contains(folio, index), folio); > > /* > - * We have a locked page in the page cache, now we need to check > - * that it's up-to-date. If not, it is going to be due to an error. > + * We have a locked folio in the page cache, now we need to check > + * that it's up-to-date. If not, it is going to be due to an error, > + * or because readahead was otherwise unable to retrieve it. > */ > if (unlikely(!folio_test_uptodate(folio))) { > /* > - * The page was in cache and uptodate and now it is not. > - * Strange but possible since we didn't hold the page lock all > - * the time. Let's drop everything get the invalidate lock and > - * try again. > + * If the invalidate lock is not held, the folio was in cache and > + * uptodate and now it is not. Strange but possible since we > + * didn't hold the page lock all the time. Let's drop everything, > + * get the invalidate lock and try again. > */ > if (!mapping_locked) { > folio_unlock(folio); > folio_put(folio); > goto retry_find; > } > + > + /* > + * OK, the folio is really not uptodate. This can be because the > + * VMA has the VM_RAND_READ flag set, or because an error > + * arose. Let's read it in directly. > + */ > goto page_not_uptodate; > } > > -- > 2.42.0 > -- Jan Kara SUSE Labs, CR