public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [PR gdb/17143] Improve memory usage of major obstacks
@ 2015-09-20 23:05 Doug Evans
  2015-09-29 11:40 ` Pedro Alves
  0 siblings, 1 reply; 2+ messages in thread
From: Doug Evans @ 2015-09-20 23:05 UTC (permalink / raw)
  To: gdb-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] [PR gdb/17143] Improve memory usage of major obstacks
  2015-09-20 23:05 [PATCH] [PR gdb/17143] Improve memory usage of major obstacks Doug Evans
@ 2015-09-29 11:40 ` Pedro Alves
  0 siblings, 0 replies; 2+ messages in thread
From: Pedro Alves @ 2015-09-29 11:40 UTC (permalink / raw)
  To: Doug Evans, gdb-patches

On 09/21/2015 12:04 AM, Doug Evans wrote:
> 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.
> 

How about putting a gdb_static_assert in OBSTACK_ZALLOC, etc. that
ensures the alignment of the type is <= 10 ?  We could restrict that
to gcc/clang and use __alignof__.  (gnulib/import/stddef.in.h conditions
the __alignof__ usage on #ifdef __GNUC__, which both define.).

Thanks,
Pedro Alves

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-09-29 11:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-20 23:05 [PATCH] [PR gdb/17143] Improve memory usage of major obstacks Doug Evans
2015-09-29 11:40 ` Pedro Alves

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