[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <0719992a-c436-4746-9167-03a2be81bff9@lucifer.local>
Date: Thu, 24 Jul 2025 19:01:33 +0100
From: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
To: David Hildenbrand <david@...hat.com>
Cc: Dev Jain <dev.jain@....com>, akpm@...ux-foundation.org, ziy@...dia.com,
baolin.wang@...ux.alibaba.com, Liam.Howlett@...cle.com,
npache@...hat.com, ryan.roberts@....com, baohua@...nel.org,
linux-mm@...ck.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 2/3] khugepaged: Optimize
__collapse_huge_page_copy_succeeded() by PTE batching
On Thu, Jul 24, 2025 at 07:57:22PM +0200, David Hildenbrand wrote:
>
> > > + if (folio_test_large(src)) {
> > > + unsigned int max_nr_ptes = (end - address) >> PAGE_SHIFT;
> > > +
> > > + nr_ptes = folio_pte_batch(src, _pte, pteval, max_nr_ptes);
> > > + } else {
> > > release_pte_folio(src);
> > > + }
> > > +
> > > /*
> > > * ptl mostly unnecessary, but preempt has to
> > > * be disabled to update the per-cpu stats
> > > * inside folio_remove_rmap_pte().
> > > */
> > > spin_lock(ptl);
> > > - ptep_clear(vma->vm_mm, address, _pte);
> > > - folio_remove_rmap_pte(src, src_page, vma);
> > > + clear_ptes(vma->vm_mm, address, _pte, nr_ptes);
> > > + folio_remove_rmap_ptes(src, src_page, nr_ptes, vma);
> > > spin_unlock(ptl);
> > > - free_folio_and_swap_cache(src);
> > > + free_swap_cache(src);
> > > + folio_put_refs(src, nr_ptes);
> >
> > Hm one thing here though is the free_folio_and_swap_cache() does:
> >
> > free_swap_cache(folio);
> > if (!is_huge_zero_folio(folio))
> > folio_put(folio);
> >
> > Whereas here you unconditionally reduce the reference count. Might this
> > cause issues with the shrinker version of the huge zero folio?
> >
> > Should this be:
> >
> > if (!is_huge_zero_folio(src))
> > folio_put_refs(src, nr_ptes);
> >
> > Or do we otherwise avoid issues with this?
>
> (resending my reply)
>
> The huge zero folio is never PTE-mapped.
OK fine, as mentioned off-list I hate this kind of 'implicit' knowledge, and you
pointed out that really we should be using vm_normal_page() or equivalent in
this code. One to address at some point :)
Anyway with this concern addressed, the patch is fine, will send tag...
>
> --
> Cheers,
>
> David / dhildenb
>
Powered by blists - more mailing lists