Re: [PATCH 0/2] bpf: htab: Reduce memory use of hash maps

From: T.J. Mercier

Date: Thu Jul 30 2026 - 21:13:20 EST


On Fri, Jul 24, 2026 at 7:35 AM Mykyta Yatsenko
<mykyta.yatsenko5@xxxxxxxxx> wrote:
>
> On 7/23/26 6:22 PM, T.J. Mercier wrote:
> > On Thu, Jul 23, 2026 at 7:11 AM Mykyta Yatsenko
> > <mykyta.yatsenko5@xxxxxxxxx> wrote:
> >>
> >> On 7/22/26 9:37 PM, T.J. Mercier wrote:
> >>> Memory is expensive and scarce these days. This series reduces the
> >>> memory use of BPF hash maps by eliminating the per-element overheads
> >>> below. This saves up to 50% of per-element memory use for standard and
> >>> PCPU hash maps. The memory use of LRU hash maps is unaffected.
> >>>
> >>
> >> I understand that these savings calculations do not account for the element
> >> value overhead of per-CPU maps, which make up most of the map memory
> >> consumption. Realistically we won't see any memory savings for per-CPU maps.
> >
> > Yes, I did not look at BPF_MAP_TYPE_PERCPU_ARRAY at all. 95% of the
> > memory used by all of our BPF maps comes from hashmaps affected by
> > these changes. We only have 7 BPF_MAP_TYPE_PERCPU_ARRAY maps and they
> > consume only about 12 KiB. (I know a few of those PCPU arrays are just
> > to avoid 128 / 256 byte BPF stack allocations.)
> >
> >
>
> BTW, did you look into BPF_MAP_TYPE_RHASH? It does not
> yield much memory savings compared to normal hashmap, but performance
> is better in some scenarios.
>
> Link: https://lore.kernel.org/all/20260605-rhash-v7-0-5b8e05f8630d@xxxxxxxx/

Thanks, I've started to take a look and asked some other coworkers to as well.