bug#81616: [PATCH] tail: hash follow-by-name directory events
Pádraig Brady <[email protected]>
| Newsgroups | gmane.comp.gnu.core-utils.bugs |
|---|---|
| Message-ID | <[email protected]> |
On 13/08/2026 19:22, Iván Ezequiel Rodriguez wrote:
> Replace the O(N) scan of watched names on each directory inotify event
> with a Hash_table keyed by (parent_wd, basename), addressing the
> long-standing FIXME in tail_forever_inotify.
>
> Keep ownership consistent with wd_to_name: parent_by_name is created
> only for Follow_name and returned to the caller, so fallback paths can
> return without local hash cleanup.
>
> Matching cost for N directory events that each compare against N names
> (illustrative host timings of the scan vs hash lookup alone):
>
> N=1000: ~0.018s -> ~0.000s
> N=5000: ~0.39s -> ~0.000s
> N=10000: ~1.5s -> ~0.000s
>
> End-to-end recreate storms remain largely file-system bound on this
> host; the hash removes the quadratic name-matching CPU from that path.
> +/* Hash Follow_name watches by parent directory wd + basename so directory
> + inotify events can be matched in expected O(1) instead of scanning all
> + files. */
> +static size_t
> +parent_name_hasher (const void *entry, size_t tabsize)
> +{
> + const struct File_spec *spec = entry;
> + char const *name = spec->name + spec->basename_start;
> + size_t value = spec->parent_wd;
> + for (unsigned char c; (c = *name); name++)
> + value = value * 31 + c;
> + return value % tabsize;
As discussed recently, we could use hash_string() for that.
In general the patch looks sensible.
I'll give it a full review tomorrow hopefully.
thanks,
Padraig