RE: [PATCH v2 2/2] kfence: allow change number of object by early parameter

From: yuanlinyu

Date: Thu Dec 18 2025 - 23:36:10 EST


> From: Marco Elver <elver@xxxxxxxxxx>
> Sent: Thursday, December 18, 2025 6:24 PM
> To: yuanlinyu <yuanlinyu@xxxxxxxxx>
> Cc: Alexander Potapenko <glider@xxxxxxxxxx>; Dmitry Vyukov
> <dvyukov@xxxxxxxxxx>; Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>;
> Huacai Chen <chenhuacai@xxxxxxxxxx>; WANG Xuerui <kernel@xxxxxxxxxx>;
> kasan-dev@xxxxxxxxxxxxxxxx; linux-mm@xxxxxxxxx; loongarch@xxxxxxxxxxxxxxx;
> linux-kernel@xxxxxxxxxxxxxxx
> Subject: Re: [PATCH v2 2/2] kfence: allow change number of object by early
> parameter
>
> On Thu, 18 Dec 2025 at 11:18, yuanlinyu <yuanlinyu@xxxxxxxxx> wrote:
> >
> > > From: Marco Elver <elver@xxxxxxxxxx>
> > Do you mean performance critical by access global data ?
> > It already access __kfence_pool global data.
> > Add one more global data acceptable here ?
> >
> > Other place may access global data indeed ?
>
> is_kfence_address() is used in the slub fast path, and another load is
> one more instruction in the fast path. We have avoided this thus far
> for this reason.
>
> > I don't know if all linux release like ubuntu enable kfence or not.
> > I only know it turn on default on android device.
>
> This is irrelevant.
>
> > > While I think the change itself would be useful to have eventually, a
> > > better design might be needed. It's unclear to me what the perf impact
> >
> > Could you share the better design idea ?
>
> Hot-patchable constants, similar to static branches/jump labels. This
> had been discussed in the past (can't find the link now), but it's not
> trivial to implement unfortunately.

is it possible add tag to kfence address and only check address itself ?

>
> An option that would enable/disable the command-line changeable number
> of objects, i.e one version that avoids the load in the fast path and
> one version that enables all the bits that you added here. But I'd
> rather avoid this if possible.

Yes, it should avoid, the purpose is without compile the kernel.

>
> As such, please do benchmark and analyze the generated code in the
> allocator fast path (you should see a load to the new global you
> added). llvm-mca [1] might help you with analysis.
>
> [1] https://llvm.org/docs/CommandGuide/llvm-mca.html

Thanks, will learn it