Re: [PATCH 12/15] stackdepot: add refcount for records

From: Marco Elver
Date: Mon Sep 04 2023 - 14:56:26 EST


On Mon, 4 Sept 2023 at 20:46, Andrey Konovalov <andreyknvl@xxxxxxxxx> wrote:
>
> On Wed, Aug 30, 2023 at 11:33 AM Marco Elver <elver@xxxxxxxxxx> wrote:
> >
> > If someone doesn't use stack_depot_evict(), and the refcount eventually
> > overflows, it'll do a WARN (per refcount_warn_saturate()).
> >
> > I think the interface needs to be different:
> >
> > stack_depot_get(): increments refcount (could be inline if just
> > wrapper around refcount_inc())
> >
> > stack_depot_put(): what stack_depot_evict() currently does
> >
> > Then it's clear that if someone uses either stack_depot_get() or _put()
> > that these need to be balanced. Not using either will result in the old
> > behaviour of never evicting an entry.
>
> So you mean the exported interface needs to be different? And the
> users will need to call both stack_depot_save+stack_depot_get for
> saving? Hm, this seems odd.
>
> WDYT about adding a new flavor of stack_depot_save called
> stack_depot_save_get that would increment the refcount? And renaming
> stack_depot_evict to stack_depot_put.

If there are no other uses of stack_depot_get(), which seems likely,
just stack_depot_save_get() seems ok.

> I'm not sure though if the overflow is actually an issue. Hitting that
> would require calling stack_depot_save INT_MAX times.

With a long-running kernel it's possible.