This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Minor O_CLOEXEC optimization, "regression" fix


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);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]