From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [patch] Minor O_CLOEXEC optimization, "regression" fix
Date: Tue, 08 Oct 2013 18:32:00 -0000 [thread overview]
Message-ID: <20131008183214.GB27355@host2.jankratochvil.net> (raw)
Hi Tom,
I just noticed GDB does many needless double-opens with ENOENT like:
open("/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY) = -1 ENOENT (No such file or directory)
The fix is simple, it saved 30 syscalls on a small example (3076->3046) like:
open("/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
-open("/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/debug/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
-open("/usr/lib/debug/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/gdb/auto-load/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
-open("/usr/share/gdb/auto-load/usr/lib64/libc-2.18.90.so-gdb.gdb", O_RDONLY) = -1 ENOENT (No such file or directory)
No regressions on {x86_64,x86_64-m32,i686}-fedora21pre-linux-gnu.
Jan
gdb/
2013-10-08 Jan Kratochvil <jan.kratochvil@redhat.com>
Minor performance optimization of opening non-existing files.
* common/filestuff.c (gdb_fopen_cloexec): New variable
fopen_e_ever_succeeded, use it.
diff --git a/gdb/common/filestuff.c b/gdb/common/filestuff.c
index d3b13e8..e10a013 100644
--- a/gdb/common/filestuff.c
+++ b/gdb/common/filestuff.c
@@ -319,6 +319,10 @@ gdb_fopen_cloexec (const char *filename, const char *opentype)
supported. */
static int fopen_e_ever_failed = O_CLOEXEC == 0;
+ /* If we know the operating system supports "e" do not retry the open
+ without "e". The file for example just does not exist. */
+ static int fopen_e_ever_succeeded;
+
if (!fopen_e_ever_failed)
{
char *copy;
@@ -331,7 +335,9 @@ gdb_fopen_cloexec (const char *filename, const char *opentype)
result = fopen (filename, copy);
}
- if (result == NULL)
+ if (result != NULL)
+ fopen_e_ever_succeeded = 1;
+ else if (!fopen_e_ever_succeeded)
{
/* Fallback. */
result = fopen (filename, opentype);
next reply other threads:[~2013-10-08 18:32 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-08 18:32 Jan Kratochvil [this message]
2013-10-08 19:44 ` Tom Tromey
2013-10-09 13:10 ` Jan Kratochvil
2013-10-09 13:34 ` Kai Tietz
2013-10-09 14:41 ` [patchv2] " Jan Kratochvil
2013-10-09 15:48 ` Tom Tromey
2013-10-09 16:01 ` [commit] " Jan Kratochvil
2013-10-09 17:07 ` [patch] " Eli Zaretskii
2013-10-09 17:02 ` Eli Zaretskii
2013-10-09 17:08 ` Tom Tromey
2013-10-09 17:29 ` Eli Zaretskii
2013-10-09 17:41 ` Jan Kratochvil
2013-10-09 17:58 ` Eli Zaretskii
2013-10-09 18:37 ` Jan Kratochvil
2013-10-09 19:08 ` Eli Zaretskii
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=20131008183214.GB27355@host2.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.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