fstat(2) penalized by using newfstatat(6, "", buf, AT_EMPTY_PATH)

Linus Torvalds torvalds@linux-foundation.org
Tue Sep 5 17:29:42 GMT 2023


On Tue, 5 Sept 2023 at 06:14, Mateusz Guzik <mjguzik@gmail.com> wrote:
>
> I completely agree this is a problem going way past fstat.

Realistically, fstatat() is likely the only case that matters from any
performance angle because it's the only one likely to be used a lot in
real loads.

Sure, there are other "at" system calls, but they just aren't
important from a performance angle.

I don't think we've ever seen 'fchown/fchmod()' be a major performance
issue, and if it was, the cost is elsewhere (ie the writeback of the
changed inode), so if glibc were to translate it to
'fchownat/fchmodat()' with AT_EMPTY_PATH, it really wouldn't matter.

In contrast, there are tons of loads where 'fstat()' is a noticeable
part of the load, because the "open+fstat" pattern is simply
fundamental Unix code. So converting it to 'fstatat()' is simply
*bad*.

Right now the kernel does even more than it needs to do (ie it does
the whole pathname handling, because I certainly didn't expect
AT_EMPTY_PATH to be a *hot* path), but as Mateusz says, even with that
all short-circuited (we have a trivial patch to do just that), just
the cost of checking "is it actually empty" is noticeable because of
the security boundary issue.

              Linus


More information about the Libc-alpha mailing list