lkml.org 
[lkml]   [2024]   [Feb]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
SubjectRe: [PATCH 1/1] mm/madvise: enhance lazyfreeing with mTHP in madvise_free
Date
Hey Fengwei,

Thanks for taking time to review!

> On Mon, Feb 26, 2024 at 10:38 AM Yin Fengwei <fengwei.yin@intel.com> wrote:
> > On Sun, Feb 25, 2024 at 8:32 PM Lance Yang <ioworker0@gmail.com> wrote:
[...]
> > --- a/mm/madvise.c
> > +++ b/mm/madvise.c
> > @@ -676,11 +676,43 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
> > */
> > if (folio_test_large(folio)) {
> > int err;
> > + unsigned long next_addr, align;
> >
> > - if (folio_estimated_sharers(folio) != 1)
> > - break;
> > - if (!folio_trylock(folio))
> > - break;
> > + if (folio_estimated_sharers(folio) != 1 ||
> > + !folio_trylock(folio))
> > + goto skip_large_folio;
> > +
> > + align = folio_nr_pages(folio) * PAGE_SIZE;
> > + next_addr = ALIGN_DOWN(addr + align, align);
> There is a possible corner case:
> If there is a cow folio associated with this folio and the cow folio
> has smaller size than this folio for whatever reason, this change can't
> handle it correctly.

Thanks for pointing that out; it's very helpful to me!
I made some changes. Could you please check if this corner case is now resolved?

As a diff against this patch.

diff --git a/mm/madvise.c b/mm/madvise.c
index bcbf56595a2e..c7aacc9f9536 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -686,10 +686,12 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
next_addr = ALIGN_DOWN(addr + align, align);

/*
- * If we mark only the subpages as lazyfree,
- * split the large folio.
+ * If we mark only the subpages as lazyfree, or
+ * if there is a cow folio associated with this folio,
+ * then split the large folio.
*/
- if (next_addr > end || next_addr - addr != align)
+ if (next_addr > end || next_addr - addr != align ||
+ folio_total_mapcount(folio) != folio_nr_pages(folio))
goto split_large_folio;

/*
---
Thanks again for your time!

Best,
Lance

\
 
 \ /
  Last update: 2024-05-27 15:21    [W:1.060 / U:0.212 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site