public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mateusz Guzik <mjguzik@gmail.com>,
	Andreas Schwab <schwab@suse.de>, Rich Felker <dalias@libc.org>,
	Mateusz Guzik via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: fstat(2) penalized by using newfstatat(6, "", buf, AT_EMPTY_PATH)
Date: Tue, 5 Sep 2023 15:22:46 -0300	[thread overview]
Message-ID: <387426d5-17c8-cf3e-83a1-88b55c9d22a1@linaro.org> (raw)
In-Reply-To: <CAHk-=wgkKHn9_aG8wTz8BkxtC2g=+93vN29HNVnC_s+cPCOteA@mail.gmail.com>



On 05/09/23 14:45, Linus Torvalds wrote:
> On Tue, 5 Sept 2023 at 10:28, Adhemerval Zanella Netto
> <adhemerval.zanella@linaro.org> wrote:
>>
>> I think we can still make it in a generic way, stat family would use more
>> syscall (which some filters might complain) but it should be ok:
> 
> Ugh. That patch of yours certainly seems to avoid the kernel overhead
> (where that "fetch a byte from user space just to check it is '\0'" is
> much more expensive than it is in user space), but why does glibc do
> that whole "turn fstat() into fstatat(), and then turn it back again"?
> 
> It seems just stupid. If the user asked for 'fstat()', just give the
> user 'fstat()'.
> 
> Your patch literally adds *complexity*, rather than take it away.
> 
> Is this all just because glibc did its own 'struct stat'
> implementation way back when, and you want to have just one place
> where the stat conversion is done?
> 
> Can't you just special case *that* case instead? It's long been
> irrelevant. Afaik, on 32-bit x86, you just want to use the 'stat64'
> system call family, and on 64-bit x86 you just use the regular 'stat'
> family (yes, called 'newfstatat' for that one system call for internal
> historial reasons), and there is no conversion needed.
> 
> IOW, all those wrappers just for 'struct stat' conversion are pure
> overhead and silly garbage. Why do they exist? And if there is still
> some other reason for them to exist, can't you make that be a
> 'sysdeps' file of its own, and not penalize all the sane cases with
> 'copy stat structures around'?

The old glibc stat code was a complete mess that was added prior symbol
versioning, with multiple implementations, along with a static linkage
that defines the current version (there is no need to describe it
further). The consolidation also provide a much simpler way to support
y2038.

On x86_64 and some other 64 bits ABIs where glibc exported struct stat 
is  the same as the kernel, there is no conversion whatsoever.  It is 
only required on some ABI where due historical mistakes the exported 
user struct does not match kernel (sparc64, mips64) and on 32 bits 
where the no-LFS support is just routed to LFS interface to simplify
things.

So the fstat to fstatat approach is a way to simplify the code and put 
all the required syscall logic only at fstatat implementation.  By adding 
the 'special' case back on fstat.c it would require to replicate all this
logic plus when to use statx instead (FSTATAT_USE_STATX), which is far 
from ideal. It is doable, but not really simpler...

  reply	other threads:[~2023-09-05 18:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-04  9:55 Mateusz Guzik
2023-09-04 10:08 ` Andreas Schwab
2023-09-04 10:11   ` Mateusz Guzik
2023-09-05 13:01     ` Adhemerval Zanella Netto
2023-09-05 13:14       ` Mateusz Guzik
2023-09-05 17:28         ` Adhemerval Zanella Netto
2023-09-05 17:45           ` Linus Torvalds
2023-09-05 18:22             ` Adhemerval Zanella Netto [this message]
2023-09-05 19:16               ` Adhemerval Zanella Netto
2023-09-05 19:21                 ` Linus Torvalds
2023-09-05 21:42             ` Rich Felker
2023-09-05 21:46               ` Mateusz Guzik
2023-09-05 17:29         ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=387426d5-17c8-cf3e-83a1-88b55c9d22a1@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=dalias@libc.org \
    --cc=libc-alpha@sourceware.org \
    --cc=mjguzik@gmail.com \
    --cc=schwab@suse.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).