All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lorenzo Stoakes <lstoakes@gmail.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Andrew Morton <akpm@linux-foundation.org>
Cc: Matthew Wilcox <willy@infradead.org>, Jan Kara <jack@suse.cz>,
	Lorenzo Stoakes <lstoakes@gmail.com>
Subject: [PATCH] mm/filemap: clarify filemap_fault() comments for not uptodate case
Date: Sun,  1 Oct 2023 00:10:29 +0100	[thread overview]
Message-ID: <20230930231029.88196-1-lstoakes@gmail.com> (raw)

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 <lstoakes@gmail.com>
---
 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


             reply	other threads:[~2023-09-30 23:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-30 23:10 Lorenzo Stoakes [this message]
2023-10-02  6:26 ` [PATCH] mm/filemap: clarify filemap_fault() comments for not uptodate case Christoph Hellwig
2023-10-02  6:39   ` Vlastimil Babka
2023-10-02  9:43     ` Joe Perches
2023-10-02  6:47   ` Lorenzo Stoakes
2023-10-02  6:50     ` Christoph Hellwig
2023-10-02  9:55 ` Jan Kara
2023-10-02 16:02 ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230930231029.88196-1-lstoakes@gmail.com \
    --to=lstoakes@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jack@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.