The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Pratyush Yadav <pratyush@kernel.org>
Cc: Chris Down <chris@chrisdown.name>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	Alexander Graf <graf@amazon.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Tarun Sahu <tarunsahu@google.com>,
	David Matlack <dmatlack@google.com>,
	Samiullah Khawaja <skhawaja@google.com>,
	kexec@lists.infradead.org, linux-mm@kvack.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [RFC PATCH 0/5] KHO map
Date: Sun, 29 Nov 2026 13:49:08 +0200	[thread overview]
Message-ID: <awwRNLVKfMLywZUW@kernel.org> (raw)
In-Reply-To: <2vxz1p8jhcpx.fsf@kernel.org>

On Tue, Nov 17, 2026 at 01:19:38PM +0100, Pratyush Yadav wrote:
> Hi Chris,
> 
> On Tue, Nov 17 2026, Chris Down wrote:
> 
> > Hi Pratyush,
> >
> > Pratyush Yadav writes:
> >>The main user of the map is memfd. Currently memfd uses a vmalloc buffer
> >>that has a pair of {index,pfn} to track the folios in the file. That
> >>uses 16 bytes per page. The KHO map uses only 8 bytes per page with some
> >>overhead. So for a 1 GiB memfd, it uses roughly half the memory.
> >
> > That only holds for order-0 folios though. A leaf covers 512 indices, so
> > a populated memfd needs one leaf page for every 2M of file whatever the
> > folio size, while the array needs 16 bytes per folio. Per 2M of file,
> > that works out as:
> >
> >     folio size   array    map     map/array
> >     4K (o0)      8K       4K      0.5x
> >     8K (o1)      4K       4K      1x
> >     16K (o2)     2K       4K      2x
> >     64K (o4)     512      4K      8x
> >     2M (o9)      16       4K      256x
> 
> Right.
> 
> >
> >>- Multi-index entry support: currently, while the map is very efficient
> >>  with 4k folios, it is horribly inefficient with 2M folios. Each folio
> >>  in the memfd takes up a full page to track. Multi-index entry support
> >>  can fix this by tracking entries that cover a whole page in the
> >>  previous level, similar to page tables.
> >
> > Since patch 5 makes things worse for memfds with large folios, I agree
> > with Pasha that this needs fixing before memfd switches over. Storing
> 
> Right, I agree as well.
> 
> > PMD-sized entries at L1 fixes the 2M case, but mTHP sizes between 4K and
> > 2M would still take a full leaf for every 2M of file. Do you expect
> > mTHP-backed memfds to be preserved? If so, it's probably worth handling
> > them in the format before it becomes ABI.
> 
> mTHP will still work, it will just be less space efficient than 2M THPs.
> Even then, the overhead is around 2M for every 1G, which is roughly
> 0.2%. Even then, I don't think that is too bad. If you want to be more
> space efficient, use 2M THPs, or hugetlb[*]. I think that is a fair
> tradeoff. Using larger page sizes also makes KHO more efficient.
> 
> We _can_ make mTHPs fairly efficient, but that comes at the cost of a
> more complicated ABI. For example, we can have a per-order KHO map in
> the memfd, and shift the keys by the order. That should improve the
> density. We could also do some other tricks like the shifted key
> encoding scheme that KHO preserved memory map uses (see
> kho_encode_radix_key()) to improve density.
> 
> So unless someone can explain why mTHP memfds are important to optimize
> for, I'd say mTHP users can either take the 0.2% preservation overhead,
> or use 2M THPs.

In general mm moves to managing memory in larger chunks and mTHP is one of
the means for that and sometime in the future mTHP is going to be
"mainstream".

So the question is "when" rather than "why" ;-)

And I believe we should consider how much complexity it will add later too,
including the handling of compatibility.

E.g. a per-order KHO map does not sound that complex if we add it now, but
extending ABI to support that along with the current proposal could add
some pain.

> -- 
> Regards,
> Pratyush Yadav

-- 
Sincerely yours,
Mike.

      reply	other threads:[~2026-11-29 11:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 13:40 [RFC PATCH 0/5] KHO map Pratyush Yadav
2026-11-16 13:40 ` [RFC PATCH 1/5] kho: add KHOSER_CLEAR_PTR() Pratyush Yadav
2026-11-16 13:40 ` [RFC PATCH 2/5] kho: build KHO objects into a single kho.o Pratyush Yadav
2026-11-16 20:13   ` Pasha Tatashin
2026-11-17 10:41     ` Pratyush Yadav
2026-11-16 13:40 ` [RFC PATCH 3/5] kho: add KHO map Pratyush Yadav
2026-11-16 13:40 ` [RFC PATCH 4/5] kho: test: add KHO map test Pratyush Yadav
2026-11-16 13:40 ` [RFC PATCH 5/5] mm/memfd_luo: use KHO map for tracking folios Pratyush Yadav
2026-11-16 22:45 ` [RFC PATCH 0/5] KHO map Pasha Tatashin
2026-11-17 12:26   ` Pratyush Yadav
2026-11-17 15:35     ` Pratyush Yadav
2026-11-17 16:05       ` Pasha Tatashin
2026-11-17 10:10 ` Chris Down
2026-11-17 12:19   ` Pratyush Yadav
2026-11-29 11:49     ` Mike Rapoport [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awwRNLVKfMLywZUW@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=chris@chrisdown.name \
    --cc=corbet@lwn.net \
    --cc=dmatlack@google.com \
    --cc=graf@amazon.com \
    --cc=kexec@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pasha.tatashin@soleen.com \
    --cc=pratyush@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=skhawaja@google.com \
    --cc=tarunsahu@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox