public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jim Meyering <jim@meyering.net>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: linux-kernel@vger.kernel.org, torvalds@osdl.org, bug-coreutils@gnu.org
Subject: another reason to add openat in the kernel: efficiency
Date: Sun, 27 Nov 2005 23:06:38 +0100	[thread overview]
Message-ID: <87acfpn3td.fsf@rho.meyering.net> (raw)
In-Reply-To: <E1EZx6Q-0002zw-00@dorka.pomaz.szeredi.hu>

Miklos Szeredi wrote:
> What's wrong with using '/proc/self/fd/N' to implement [openat et al]?

It's great that we can emulate openat and related fd-relative
functions using /proc/self/fd/N/FILE, but that is markedly less
efficient than a native implementation.

Here's some real data for comparison.
The problem: remove a just-created hierarchy named
/t/z/z/.../z (1,000,000 levels deep) residing on a tmpfs file system.

Using GNU rm -rf (from coreutils-5.93[1]), that takes about 14s wall clock
time on an otherwise idle system running 2.6.14.  The 5.93 implementation
uses open, fchdir, fstat, opendir/readdir, unlink, etc. to do its job:
i.e., no openat-related functions.

Compare that with GNU rm from the latest CVS sources[2], now f?chdir-free,
using /proc-based openat emulation (including emulation of fdopendir[3],
fstatat, and unlinkat).  Here, the time required about 35 seconds:
more than double.  Even after rewriting the emulation code not to use
snprintf, the resulting times were still about 30s.

Contrast that with Solaris 9 (with kernel-provided openat, fstatat,
fdopendir, etc.), where the openat-based implementation takes
20% *less* time than the 5.93 implementation.

Sure, there may well be other factors that explain some of the difference,
but it'd be nice to avoid the added time and space(stack) overhead of
encoding and decoding each /proc-relative file name.  Of course,
syscall-based interfaces also have the advantage of working even if
/proc is not accessible.


Jim

[1] ftp://ftp.gnu.org/gnu/coreutils/coreutils-5.93.tar.bz2
[2] http://savannah.gnu.org/projects/coreutils/
[3] It's a shame to have to emulate fdopendir via `opendir ("/proc/...',
but that's only temporary, while we wait for glibc-with-fdopendir
to become more mainstream.

  parent reply	other threads:[~2005-11-27 22:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-09 19:14 openat() Ulrich Drepper
2005-11-09 21:03 ` openat() Miklos Szeredi
2005-11-09 21:27   ` openat() Ulrich Drepper
2005-11-27 22:06   ` Jim Meyering [this message]
2005-11-09 21:42 ` openat() dean gaudet
2005-11-09 21:55   ` openat() Nicholas Miell
2005-11-10  7:40   ` openat() Jeff Garzik
2005-11-10  7:48     ` openat() Ulrich Drepper
2005-11-10 10:01     ` openat() Jeff Garzik

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=87acfpn3td.fsf@rho.meyering.net \
    --to=jim@meyering.net \
    --cc=bug-coreutils@gnu.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=torvalds@osdl.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