This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH] [PR gdb/17143] Improve memory usage of major obstacks
- From: Doug Evans <xdje42 at gmail dot com>
- To: gdb-patches at sourceware dot org
- Date: Sun, 20 Sep 2015 16:04:42 -0700
- Subject: [PATCH] [PR gdb/17143] Improve memory usage of major obstacks
- Authentication-results: sourceware.org; auth=none
Hi.
The default obstack alignment on amd64-linux is 16 if one is using
glibc's obstack instead of libiberty's (glibc's includes long double
in the default alignment calculation).
This wastes 10s of megabytes when debugging large programs.
I couldn't find any case where we use long double or DOUBLEST in
either of objfile's two obstacks: objfile_obstack, per_bfd->storage_obstack,
so I'd like to propose this patch.
Regression tested on amd64-linux.
[btw, for another significant memory hit there is pr 14108.
I think(!) it's still an issue.]
2015-09-20 Doug Evans <xdje42@gmail.com>
PR gdb/17143
* gdb_obstack.c (gdb_obstack_init): New function.
* gdb_obstack.h (gdb_obstack_init): Declare.
* objfiles.c (get_objfile_bfd_data): Call it.
(allocate_objfile): Ditto.
diff --git a/gdb/gdb_obstack.c b/gdb/gdb_obstack.c
index d8d03df..4cff52e 100644
--- a/gdb/gdb_obstack.c
+++ b/gdb/gdb_obstack.c
@@ -18,8 +18,30 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
+#include <stddef.h>
#include "gdb_obstack.h"
+/* See gdb_obstack.h. */
+
+void
+gdb_obstack_init (struct obstack *obstack)
+{
+ struct find_alignment
+ {
+ char c;
+ union
+ {
+ ULONGEST i;
+ void *p;
+ } u;
+ };
+ int needed_alignment = offsetof (struct find_alignment, u);
+
+ obstack_specify_allocation (obstack, 0, needed_alignment,
+ /* Note: These are macros in gdb_obstack.h. */
+ obstack_chunk_alloc, obstack_chunk_free);
+}
+
/* Concatenate NULL terminated variable argument list of `const char *'
strings; return the new string. Space is found in the OBSTACKP.
Argument list must be terminated by a sentinel expression `(char *)
diff --git a/gdb/gdb_obstack.h b/gdb/gdb_obstack.h
index 3272721..518a593 100644
--- a/gdb/gdb_obstack.h
+++ b/gdb/gdb_obstack.h
@@ -22,6 +22,13 @@
#include "obstack.h"
+/* Initialize an obstack for gdb's use.
+ N.B. The alignment of the obstack is set for pointers and LONGEST,
+ but not long double. This saves 10s of megabytes when debugging large
+ programs. */
+
+extern void gdb_obstack_init (struct obstack *);
+
/* Utility macros - wrap obstack alloc into something more robust. */
#define OBSTACK_ZALLOC(OBSTACK,TYPE) \
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index f6be91e..4364247 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -147,7 +147,7 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd)
if (abfd != NULL)
storage->gdbarch = gdbarch_from_bfd (abfd);
- obstack_init (&storage->storage_obstack);
+ gdb_obstack_init (&storage->storage_obstack);
storage->filename_cache = bcache_xmalloc (NULL, NULL);
storage->macro_cache = bcache_xmalloc (NULL, NULL);
storage->language_of_main = language_unknown;
@@ -375,9 +375,7 @@ allocate_objfile (bfd *abfd, const char *name, int flags)
objfile = XCNEW (struct objfile);
objfile->psymbol_cache = psymbol_bcache_init ();
- /* We could use obstack_specify_allocation here instead, but
- gdb_obstack.h specifies the alloc/dealloc functions. */
- obstack_init (&objfile->objfile_obstack);
+ gdb_obstack_init (&objfile->objfile_obstack);
objfile_alloc_data (objfile);