Re: [PATCH v3 13/20] mm: Copy-on-Write (COW) reuse support for PTE-mapped THP

Kairui Song
2025-04-22T02:52:38Z

On Sun, Apr 20, 2025 at 12:35 AM Kairui Song <ryncsn@gmail.com> wrote:
>
> On Sun, Apr 20, 2025 at 12:32 AM David Hildenbrand <david@redhat.com> wrote:
> >
> > On 19.04.25 18:25, David Hildenbrand wrote:
> >
> > Oh, re-reading the condition 3 times, I realize that the sanity check is wrong ...
> >
> > diff --git a/mm/memory.c b/mm/memory.c
> > index 037b6ce211f1f..a17eeef3f1f89 100644
> > --- a/mm/memory.c
> > +++ b/mm/memory.c
> > @@ -3789,7 +3789,7 @@ static bool __wp_can_reuse_large_anon_folio(struct folio *folio,
> >
> > /* Stabilize the mapcount vs. refcount and recheck. */
> > folio_lock_large_mapcount(folio);
> > - VM_WARN_ON_ONCE(folio_large_mapcount(folio) < folio_ref_count(folio));
> > + VM_WARN_ON_ONCE(folio_large_mapcount(folio) > folio_ref_count(folio));
>
> Ah, now it makes sense to me now :)
>
> Thanks for the quick response.
>
> >
> > if (folio_test_large_maybe_mapped_shared(folio))
> > goto unlock;
> >
> > Our refcount must be at least the mapcount, that's what we want to assert.
> >
> > Can you test and send a fix patch if that makes it fly for you?
>
> Sure I'll keep the testing, I think it will just fix it, I have a few
> WARN_ON_FOLIO reports all reporting mapcount is smaller than refcount.

Hi David,

I'm no longer seeing any warning after this, it fixed the problem well.