linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/filemap: set folio->mapping to NULL before xas_store()
@ 2024-03-22 21:04 Soma Nakata
  2024-03-26 21:05 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Soma Nakata @ 2024-03-22 21:04 UTC (permalink / raw)
  To: linux-mm
  Cc: soma.nakata01, Matthew Wilcox (Oracle), Andrew Morton,
	linux-fsdevel, linux-kernel

Functions such as __filemap_get_folio() check the truncation of
folios based on the mapping field. Therefore setting this field to NULL
earlier prevents unnecessary operations on already removed folios.

Signed-off-by: Soma Nakata <soma.nakata01@gmail.com>
---
 mm/filemap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/filemap.c b/mm/filemap.c
index 2723104cc06a..79bac7c00084 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -139,11 +139,12 @@ static void page_cache_delete(struct address_space *mapping,
 
 	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
 
+	folio->mapping = NULL;
+	/* Leave page->index set: truncation lookup relies upon it */
+
 	xas_store(&xas, shadow);
 	xas_init_marks(&xas);
 
-	folio->mapping = NULL;
-	/* Leave page->index set: truncation lookup relies upon it */
 	mapping->nrpages -= nr;
 }
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/filemap: set folio->mapping to NULL before xas_store()
  2024-03-22 21:04 [PATCH] mm/filemap: set folio->mapping to NULL before xas_store() Soma Nakata
@ 2024-03-26 21:05 ` Andrew Morton
  2024-03-26 22:50   ` Matthew Wilcox
  2024-03-26 22:52   ` Soma
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Morton @ 2024-03-26 21:05 UTC (permalink / raw)
  To: Soma Nakata
  Cc: linux-mm, Matthew Wilcox (Oracle), linux-fsdevel, linux-kernel

On Sat, 23 Mar 2024 06:04:54 +0900 Soma Nakata <soma.nakata01@gmail.com> wrote:

> Functions such as __filemap_get_folio() check the truncation of
> folios based on the mapping field. Therefore setting this field to NULL
> earlier prevents unnecessary operations on already removed folios.
> 
> ...
>
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -139,11 +139,12 @@ static void page_cache_delete(struct address_space *mapping,
>  
>  	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
>  
> +	folio->mapping = NULL;
> +	/* Leave page->index set: truncation lookup relies upon it */
> +
>  	xas_store(&xas, shadow);
>  	xas_init_marks(&xas);
>  
> -	folio->mapping = NULL;
> -	/* Leave page->index set: truncation lookup relies upon it */
>  	mapping->nrpages -= nr;
>  }

Seems at least harmless, but I wonder if it can really make any
difference.  Don't readers of folio->mapping lock the folio first?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/filemap: set folio->mapping to NULL before xas_store()
  2024-03-26 21:05 ` Andrew Morton
@ 2024-03-26 22:50   ` Matthew Wilcox
  2024-03-26 22:52   ` Soma
  1 sibling, 0 replies; 4+ messages in thread
From: Matthew Wilcox @ 2024-03-26 22:50 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Soma Nakata, linux-mm, linux-fsdevel, linux-kernel

On Tue, Mar 26, 2024 at 02:05:33PM -0700, Andrew Morton wrote:
> On Sat, 23 Mar 2024 06:04:54 +0900 Soma Nakata <soma.nakata01@gmail.com> wrote:
> > Functions such as __filemap_get_folio() check the truncation of
> > folios based on the mapping field. Therefore setting this field to NULL
> > earlier prevents unnecessary operations on already removed folios.
> > 
> > ...
> >
> > --- a/mm/filemap.c
> > +++ b/mm/filemap.c
> > @@ -139,11 +139,12 @@ static void page_cache_delete(struct address_space *mapping,
> >  
> >  	VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
> >  
> > +	folio->mapping = NULL;
> > +	/* Leave page->index set: truncation lookup relies upon it */
> > +
> >  	xas_store(&xas, shadow);
> >  	xas_init_marks(&xas);
> >  
> > -	folio->mapping = NULL;
> > -	/* Leave page->index set: truncation lookup relies upon it */
> >  	mapping->nrpages -= nr;
> >  }
> 
> Seems at least harmless, but I wonder if it can really make any
> difference.  Don't readers of folio->mapping lock the folio first?

I can't think of anywhere that doesn't ... most of the places that check
folio->mapping have "goto unlock" as the very next line.  I don't think
this patch accomplishes anything.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm/filemap: set folio->mapping to NULL before xas_store()
  2024-03-26 21:05 ` Andrew Morton
  2024-03-26 22:50   ` Matthew Wilcox
@ 2024-03-26 22:52   ` Soma
  1 sibling, 0 replies; 4+ messages in thread
From: Soma @ 2024-03-26 22:52 UTC (permalink / raw)
  To: Andrew Morton
  Cc: linux-mm, Matthew Wilcox (Oracle), linux-fsdevel, linux-kernel

On Wed, Mar 27, 2024 at 6:05 AM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Sat, 23 Mar 2024 06:04:54 +0900 Soma Nakata <soma.nakata01@gmail.com> wrote:
>
> > Functions such as __filemap_get_folio() check the truncation of
> > folios based on the mapping field. Therefore setting this field to NULL
> > earlier prevents unnecessary operations on already removed folios.
> >
> > ...
> >
> > --- a/mm/filemap.c
> > +++ b/mm/filemap.c
> > @@ -139,11 +139,12 @@ static void page_cache_delete(struct address_space *mapping,
> >
> >       VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio);
> >
> > +     folio->mapping = NULL;
> > +     /* Leave page->index set: truncation lookup relies upon it */
> > +
> >       xas_store(&xas, shadow);
> >       xas_init_marks(&xas);
> >
> > -     folio->mapping = NULL;
> > -     /* Leave page->index set: truncation lookup relies upon it */
> >       mapping->nrpages -= nr;
> >  }
>
> Seems at least harmless, but I wonder if it can really make any
> difference.  Don't readers of folio->mapping lock the folio first?

Yes, the reader locks the folio.
Only __filemap_remove_folio() calls page_cache_delete(),
and it says the caller has to lock the folio or make sure
that usage is safe. In the latter case, this patch improves
efficiency a little bit.
However, I found that there is not any latter case actually,
so discard it or apply, also to make the order of operations in
page_cache_delete() and page_cache_delete_batch() the same
for a cleanup.
Thanks,


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-26 22:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-22 21:04 [PATCH] mm/filemap: set folio->mapping to NULL before xas_store() Soma Nakata
2024-03-26 21:05 ` Andrew Morton
2024-03-26 22:50   ` Matthew Wilcox
2024-03-26 22:52   ` Soma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).