Re: [PATCH v4 bpf 0/4] vmalloc: bpf: introduce VM_ALLOW_HUGE_VMAP

Mike Rapoport
2022-04-18T10:06:50Z

Hi,

On Sat, Apr 16, 2022 at 10:26:08PM +0000, Song Liu wrote:
> > On Apr 16, 2022, at 1:30 PM, Linus Torvalds <torvalds@linux-foundation.org> wrote:
> >
> > Maybe I am missing something, but I really don't think this is ready
> > for prime-time. We should effectively disable it all, and have people
> > think through it a lot more.
>
> This has been discussed on lwn.net: https://lwn.net/Articles/883454/.
> AFAICT, the biggest concern is whether reserving minimal 2MB for BPF
> programs is a good trade-off for memory usage. This is again my fault
> not to state the motivation clearly: the primary gain comes from less
> page table fragmentation and thus better iTLB efficiency.

Reserving 2MB pages for BPF programs will indeed reduce the fragmentation,
but OTOH it will reduce memory utilization. If for large systems this may
not be an issue, on smaller machines trading off memory for iTLB
performance may be not that obvious.

> Other folks (in recent thread on this topic and offline in other
> discussions) also showed strong interests in using similar technical
> for text of kernel modules. So I would really like to learn your
> opinion on this. There are many details we can optimize, but I guess
> the general mechanism has to be something like:
> - allocate a huge page, make it safe, and set it as executable;
> - as users (BPF, kernel module, etc.) request memory for text, give
> a chunk of the huge page to the user.
> - use some mechanism to update the chunk of memory safely.

There are use-cases that require 4K pages with non-default permissions in
the direct map and the pages not necessarily should be executable. There
were several suggestions to implement caches of 4K pages backed by 2M
pages.

I believe that "allocate huge page and split it to basic pages to hand out
to users" concept should be implemented at page allocator level and I
posted and RFC for this a while ago:

https://lore.kernel.org/all/20220127085608.306306-1-rppt@kernel.org/

--
Sincerely yours,
Mike.