Re: [PATCH v4] fs: add predicts based on nd->depth

From: Al Viro

Date: Mon Nov 10 2025 - 22:34:24 EST


On Mon, Nov 10, 2025 at 05:59:01PM +0100, Mateusz Guzik wrote:

> Given these results:
> 1. terminate_walk() is called towards the end of the lookup. I failed
> run into a case where it has any depth to clean up. For now predict
> it does not.

Easy - just have an error while resolving a nested symlink in the middle
of pathname. On success it will have zero nd->depth, of course.

> 2. legitimize_links() is also called towards the end of lookup and most
> of the time there s 0 depth. Patch consumers to avoid calling into it
> in that case.

On transition from lazy to non-lazy mode on cache miss, ->d_revalidate()
saying "dunno, try in non-lazy mode", etc.

That can happen inside a nested symlink as well as on the top level, but
the latter is more common on most of the loads.

> 3. walk_component() is typically called with WALK_MORE and zero depth,
> checked in that order. Check depth first and predict it is 0.

Does it give a measurable effect?

> 4. link_path_walk() predicts not dealing with a symlink, but the other
> part of symlink handling fails to make the same predict. Add it.

Unconvincing, that - one is "we have a component; what are the odds of that
component being a symlink?", another - "we have reached the end of pathname
or the end of nested symlink; what are the odds of the latter being the case?"

I can believe that answers to both questions are fairly low, but they are
not the same. I'd expect the latter to be considerably higher than the
former.

> - if (unlikely(!legitimize_links(nd)))
> + if (unlikely(nd->depth && !legitimize_links(nd)))

I suspect that
if (unlikely(nd->depth) && !legitimize_links(nd))
might be better...

> - if (unlikely(!legitimize_links(nd)))
> + if (unlikely(nd->depth && !legitimize_links(nd)))
> goto out2;

Ditto.