Message ID | 20230930231029.88196-1-lstoakes@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp633881vqb; Sat, 30 Sep 2023 17:22:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6D0VyVeqHfhGWrV/pZYq1lAnqd8IqfelAHtueVLiibDRAG++MMwj0PHJVzzgszehFe0IM X-Received: by 2002:a05:6808:1594:b0:3ae:52f3:ba05 with SMTP id t20-20020a056808159400b003ae52f3ba05mr9934079oiw.28.1696119762419; Sat, 30 Sep 2023 17:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696119762; cv=none; d=google.com; s=arc-20160816; b=b7QihQZEsQzHtGIPiQI8OpfCMWfKggfdAWN/v1YZZvoQ00QSanraZGU0CBu7yFvOOu gAuFSZSXJgp2ERN2M7avtqGtYpU8l3qkUwf4mfIN54nvZzKsFxmoq4RXH5ADYEDu2WS0 Ngw75Xl3Mrh14hSqMKG3xwC63Kl+Z6qOW9w4sHg7HQPXyQ5V3ARWx+ifDcLvMuM5Piuf l1zHXy8b2cbU9T9uFrlgQFPfkoWYe4QcsMcJoC4S8QZsVj1obgZLLpBp7BhWpMdotWKd 90yiqLq13Y01jgmNHs3H8d2Fmem048UnZlfWgRR96HaVmUEeoOUgI31FJAsJwseXBEyN bd7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=LZlRJtWn09ugbDVFoE3uxLCWlbXzvShTBhbpPLHoziU=; fh=5VEU13LevITnmyDg4ILD8Oit1Rj2vevVge48q/O4940=; b=x25ZPU/LbUe7bXmC/8omfMPd9S5x7DFscLXs2scd1lj+DUyJ7Lga3AcCpA4iFKxmC6 OahRy0lz7n8ZlqbSb9+t1uasMFUwmf9vj4x5EHs71/bDlnhnDEW1AHdmEyUSjN36thmf OIbwnJNK5og2o8jyOfZNi0M35HCg0DDynqi1lFJ1DAnECoqK5bEY9BZmXIGVfmHD8b2Q 3444kceZZBgmSUkHtmppiZAeHmRnlNG/LUA+b+t9rhbnXffFNzDsiZmwrHj73/kyOK+r F1pCgJ3f9APCxjA571MXmr6fyjwFFDCtzA9zi7cCkmzx01tl07GeICIk7mjmCUQUl7rf VI4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=J09rjg8r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id az1-20020a056a02004100b00573fe49ad3esi24705438pgb.672.2023.09.30.17.22.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 17:22:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=J09rjg8r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id F04DD8271415; Sat, 30 Sep 2023 16:10:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231745AbjI3XKi (ORCPT <rfc822;chrisfriedt@gmail.com> + 20 others); Sat, 30 Sep 2023 19:10:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbjI3XKh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 30 Sep 2023 19:10:37 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30C98DD for <linux-kernel@vger.kernel.org>; Sat, 30 Sep 2023 16:10:35 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-3226cc3e324so14071500f8f.3 for <linux-kernel@vger.kernel.org>; Sat, 30 Sep 2023 16:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696115433; x=1696720233; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LZlRJtWn09ugbDVFoE3uxLCWlbXzvShTBhbpPLHoziU=; b=J09rjg8rj54O8mZO/mjmBZ+TbXgOMVm1R/EI17OQRSpPXKjS92Llhki4Q0ZVOR4F0b /YVLtsagT9ZcawtmBuaXMUdVu+thQgN0i7Ab1h1cwpp7brNAd0gmwkLliIUM1YljxE8u 71G+0SUBspgfTlEoP1iUZoG9S5VGEVDq8vecT9N+VJFEvurPp76uKUseuO3FnT7pTD5m ZtmOOh2ngolU3aa6OYxEkDTf5Z3pIjVatcwNA32UViiqo8w7cuvMIDxZgmN9WPewcSSL h6gYEsAdnZawcRlbVSbA7FNuHpEJla/45mdvDPTM8yYzqZkzzoX+iF8FtjGB1IbppTzh HuBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696115433; x=1696720233; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LZlRJtWn09ugbDVFoE3uxLCWlbXzvShTBhbpPLHoziU=; b=wKq/jjsKjo0vRpXYPJavjK9Yn4cuXfbLrb/SW4P54kNxyfMf9H4YnCufynj6gEO/Jx r26n1bCIkPvn/XVWB6VOAFJoGayE2ztz+vy88/TeI2WJKsCVjhXqGLQ74NLXDiGoWXPC kRZoUOzNBneJguo0BHgFOjvEI8KhWCHfZrD1wKRDgxS+Wfan+RG5FK9Fk5T/0HTM2W6T GhuU6WBv5+TuinNhxPSBQRJR5+oOg/+cF2BbpqJKxUGa+vIs8NZazCAKjZjsFfAnRBT3 4ETdO2MN6FRJ1SFQosnFAu1ZwMHjAQI2ZhsqtnOOBx0dZuVRzS8bF2+nMfHErChmRZnO +yQA== X-Gm-Message-State: AOJu0YwM/b4Is592ARLKTwT+tDhL3PR0r2bF7qMxVRkO+YPW1eKoVpms SoKdGJyrsynPrLO+b2dj+Io= X-Received: by 2002:adf:ee48:0:b0:311:1dba:ca65 with SMTP id w8-20020adfee48000000b003111dbaca65mr7040323wro.51.1696115433225; Sat, 30 Sep 2023 16:10:33 -0700 (PDT) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id c10-20020a5d4f0a000000b0031f3ad17b2csm24524471wru.52.2023.09.30.16.10.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Sep 2023 16:10:32 -0700 (PDT) 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 Message-ID: <20230930231029.88196-1-lstoakes@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sat, 30 Sep 2023 16:10:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778510475719421282 X-GMAIL-MSGID: 1778510475719421282 |
Series |
mm/filemap: clarify filemap_fault() comments for not uptodate case
|
|
Commit Message
Lorenzo Stoakes
Sept. 30, 2023, 11:10 p.m. UTC
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(-)
Comments
> + * If the invalidate lock is not held, the folio was in cache and > + * uptodate and now it is not. Strange but possible since we Please don't spill block comments ôver the 80 charater limit, that makes them impossible to read nicely.
On 10/2/23 08:26, Christoph Hellwig wrote: >> + * If the invalidate lock is not held, the folio was in cache and >> + * uptodate and now it is not. Strange but possible since we > > Please don't spill block comments ôver the 80 charater limit, that makes > them impossible to read nicely. Joe, can we revert the default to 80 to avoid everyone having to alias --max-line-length=80 locally?
On Sun, Oct 01, 2023 at 11:26:18PM -0700, Christoph Hellwig wrote: > > + * If the invalidate lock is not held, the folio was in cache and > > + * uptodate and now it is not. Strange but possible since we > > Please don't spill block comments ôver the 80 charater limit, that makes > them impossible to read nicely. > Yup this was because checkpatch ok'd it, I've aliased the strict 80 char param so it won't happen again. Fix patch enclosed ----8<---- From 3abb740abb67505b6f83d7602f7b4a8dcd29977f Mon Sep 17 00:00:00 2001 From: Lorenzo Stoakes <lstoakes@gmail.com> Date: Mon, 2 Oct 2023 07:37:24 +0100 Subject: [PATCH] mm/filemap: clarify filemap_fault() comments for not uptodate case Correct identation as per Christopher's feedback. Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com> --- mm/filemap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm/filemap.c b/mm/filemap.c index 959694a2ade7..951709089f38 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3314,10 +3314,10 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) */ if (unlikely(!folio_test_uptodate(folio))) { /* - * 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 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); -- 2.42.0
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
On Mon, 2023-10-02 at 08:39 +0200, Vlastimil Babka wrote: > On 10/2/23 08:26, Christoph Hellwig wrote: > > > + * If the invalidate lock is not held, the folio was in cache and > > > + * uptodate and now it is not. Strange but possible since we > > > > Please don't spill block comments ôver the 80 charater limit, that makes > > them impossible to read nicely. > > Joe, can we revert the default to 80 to avoid everyone having to alias > --max-line-length=80 locally? Given the current --max-line-length default is 100, and that was Linus' preference, I think not. https://lore.kernel.org/lkml/CAHk-=wj3iGQqjpvc+gf6+C29Jo4COj6OQQFzdY0h5qvYKTdCow@mail.gmail.com/ and https://lore.kernel.org/lkml/CAHk-=wjR0H3+2ba0UUWwoYzYBH0GX9yTf5dj2MZyo0xvyzvJnA@mail.gmail.com/
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 <lstoakes@gmail.com> After the alignment fixup the patch looks good to me. Feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> 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 >
On Sun, Oct 01, 2023 at 12:10:29AM +0100, 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. I do appreciate the comment being made accurate, but I wonder if we shouldn't change the code to match the comment. We're got two "should"s pointing in different directions -- we "should" not use readahead if readahead is disabled, and we "should" always use readahead first, using read_folio() only if readahead doesn't succeed. The code isn't ideally structured for this, but I'm going to play with it a bit and see what I can create.
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; }