Re: [PATCH v2] lib/assoc_array: fix stale nr_leaves_on_tree after gc

From: David Howells

Date: Thu Mar 19 2026 - 10:18:35 EST


Josh Law <objecting@xxxxxxxxxxxxx> wrote:

> In assoc_array_gc(), assoc_array_apply_edit() publishes the new tree
> root before nr_leaves_on_tree is updated, creating a window where the
> tree is visible with a stale leaf count. Move the nr_leaves_on_tree
> assignment before assoc_array_apply_edit() so the count is consistent
> when the new root becomes visible.

This just moves the window. The count is then inconsistent before the new
root becomes visible.

Note that there's no guarantee that nr_leaves_on_tree is stable if you're not
locking against modification. Further, if you look in:

Documentation/core-api/assoc_array.rst

there's no mention of nr_leaves_on_tree being part of the API. Unfortunately,
C doesn't allow me to put in a private: marker as C++ does.

Note that neither assoc_array_iterate() nor assoc_array_find() make reference
to the value.

Are you actually seeing a problem stemming from this?

David