[PATCH kvmtool] arm64: THPs for systems with pages bigger than 4K
Vincent Donnefort
vdonnefort at google.com
Thu Nov 26 12:35:01 PST 2026
On Thu, Nov 26, 2026 at 04:08:51PM +0000, Will Deacon wrote:
> On Mon, Oct 19, 2026 at 03:59:49PM +0100, Vincent Donnefort wrote:
> > The THP support imposes an alignment of the memslot userspace address to
> > the size of a THP (PMD_SIZE). To do so, kvmtool overallocates the RAM
> > size and aligns it. However it assumes PMD_SIZE is 2MiB, which is only
> > true on 4KiB page systems.
> >
> > Use a huge-page size, based on the system page size. This value can be
> > massive for a 64KiB page system, so skip the alignment if we couldn't
> > even install one THP.
> >
> > Signed-off-by: Vincent Donnefort <vdonnefort at google.com>
> >
> > diff --git a/arm64/kvm.c b/arm64/kvm.c
> > index 36b3284e4a92..2c01dc32fa9a 100644
> > --- a/arm64/kvm.c
> > +++ b/arm64/kvm.c
> > @@ -18,6 +18,8 @@
> >
> > #include <asm/image.h>
> >
> > +#define HUGEPAGE_SIZE (PAGE_SIZE * (PAGE_SIZE / 8UL))
>
> Does this invoke sysconf() twice per invocation?
>
> Will
It does.
How about I use for PAGE_SIZE a memoized version of the existing
host_page_size() function?
kvm/util.h:
unsigned long host_page_size(void);
#define PAGE_SIZE host_page_size()
util.c:
unsigned long host_page_size(void)
{
static unsigned long page_size;
if (!page_size)
page_size = sysconf(_SC_PAGE_SIZE);
return page_size;
}
--
Vincent
More information about the linux-arm-kernel
mailing list