On Tue, Jan 31, 2023 at 8:00 PM Andrey Konovalov <andreyknvl@xxxxxxxxx> wrote: > > On Tue, Jan 31, 2023 at 10:30 AM Alexander Potapenko <glider@xxxxxxxxxx> wrote: > > > > Wait, I think there's a problem here. > > > > > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > > > index 79e894cf8406..0eed9bbcf23e 100644 > > > --- a/lib/stackdepot.c > > > +++ b/lib/stackdepot.c > > > @@ -105,12 +105,13 @@ static bool init_stack_slab(void **prealloc) > > > if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) { > > If we get to this branch, but the condition is false, this means that: > > - next_slab_inited == 0 > > - depot_index == STACK_ALLOC_MAX_SLABS+1 > > - stack_slabs[depot_index] != NULL. > > > > So stack_slabs[] is at full capacity, but upon leaving > > init_stack_slab() we'll always keep next_slab_inited==0. > > > > Now every time __stack_depot_save() is called for a known stack trace, > > it will preallocate 1<<STACK_ALLOC_ORDER pages (because > > next_slab_inited==0), then find the stack trace id in the hash, then > > pass the preallocated pages to init_stack_slab(), which will not > > change the value of next_slab_inited. > > Then the preallocated pages will be freed, and next time > > __stack_depot_save() is called they'll be allocated again. > > Ah, right, missed that. > > What do you think about renaming next_slab_inited to > next_slab_required and inverting the used values (0/1 -> 1/0)? This > would make this part of code less confusing. "Required" as in "requires a preallocated buffer, but does not have one yet"? Yes, that's probably better. (In any case we'll need to add a comment to that variable explaining the circumstances under which one or another value is possible).