diff mbox series

[v1,1/2] KVM: arm64: Do not transfer page refcount for THP adjustment

Message ID 20230926181932.1650692-2-vdonnefort@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: Use folio for THP support | expand

Commit Message

Vincent Donnefort Sept. 26, 2023, 6:19 p.m. UTC
With folios, GUP affects a refcount common to all pages forming the THP.
There is therefore no need to move the refcount from the tail to the
head page. Under the hood it decrements and increments
the same counter.

Signed-off-by: Vincent Donnefort <vdonnefort@google.com>

Comments

Matthew Wilcox (Oracle) Sept. 27, 2023, 7 a.m. UTC | #1
On Tue, Sep 26, 2023 at 07:19:31PM +0100, Vincent Donnefort wrote:
> With folios, GUP affects a refcount common to all pages forming the THP.
> There is therefore no need to move the refcount from the tail to the
> head page. Under the hood it decrements and increments
> the same counter.

FYI, this isn't new to folios.  get_page() has _always_ operated on the
head page of a compound page.  Here's how it worked in 2.6.12-rc2:

+static inline void get_page(struct page *page)
+{
+       if (unlikely(PageCompound(page)))
+               page = (struct page *)page->private;
+       atomic_inc(&page->_count);
+}

I can't be bothered to switch over to the linux-fullhistory tree and
show how it evolved, because i think this sufficiently makes the point --
you can backport this patch as far as you like.

Folios just make it obvious that this is what's going on.  And that's a
good thing!  Making the MM less inscrutable is a win for everybody.
Vincent Donnefort Sept. 27, 2023, 12:40 p.m. UTC | #2
On Wed, Sep 27, 2023 at 08:00:28AM +0100, Matthew Wilcox wrote:
> On Tue, Sep 26, 2023 at 07:19:31PM +0100, Vincent Donnefort wrote:
> > With folios, GUP affects a refcount common to all pages forming the THP.
> > There is therefore no need to move the refcount from the tail to the
> > head page. Under the hood it decrements and increments
> > the same counter.
> 
> FYI, this isn't new to folios.  get_page() has _always_ operated on the
> head page of a compound page.  Here's how it worked in 2.6.12-rc2:
> 
> +static inline void get_page(struct page *page)
> +{
> +       if (unlikely(PageCompound(page)))
> +               page = (struct page *)page->private;
> +       atomic_inc(&page->_count);
> +}
> 
> I can't be bothered to switch over to the linux-fullhistory tree and
> show how it evolved, because i think this sufficiently makes the point --
> you can backport this patch as far as you like.

Thanks for having a look!

I'll refine that description in the next version.

> 
> Folios just make it obvious that this is what's going on.  And that's a
> good thing!  Making the MM less inscrutable is a win for everybody.
diff mbox series

Patch

diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index 587a104f66c3..de5e5148ef5d 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1295,28 +1295,8 @@  transparent_hugepage_adjust(struct kvm *kvm, struct kvm_memory_slot *memslot,
 		if (sz < PMD_SIZE)
 			return PAGE_SIZE;
 
-		/*
-		 * The address we faulted on is backed by a transparent huge
-		 * page.  However, because we map the compound huge page and
-		 * not the individual tail page, we need to transfer the
-		 * refcount to the head page.  We have to be careful that the
-		 * THP doesn't start to split while we are adjusting the
-		 * refcounts.
-		 *
-		 * We are sure this doesn't happen, because mmu_invalidate_retry
-		 * was successful and we are holding the mmu_lock, so if this
-		 * THP is trying to split, it will be blocked in the mmu
-		 * notifier before touching any of the pages, specifically
-		 * before being able to call __split_huge_page_refcount().
-		 *
-		 * We can therefore safely transfer the refcount from PG_tail
-		 * to PG_head and switch the pfn from a tail page to the head
-		 * page accordingly.
-		 */
 		*ipap &= PMD_MASK;
-		kvm_release_pfn_clean(pfn);
 		pfn &= ~(PTRS_PER_PMD - 1);
-		get_page(pfn_to_page(pfn));
 		*pfnp = pfn;
 
 		return PMD_SIZE;