From patchwork Sun Sep 20 23:04:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 8812 Received: (qmail 117896 invoked by alias); 20 Sep 2015 23:05:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 117882 invoked by uid 89); 20 Sep 2015 23:05:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL, BAYES_20, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f54.google.com Received: from mail-pa0-f54.google.com (HELO mail-pa0-f54.google.com) (209.85.220.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 20 Sep 2015 23:05:55 +0000 Received: by pacfv12 with SMTP id fv12so100885217pac.2 for ; Sun, 20 Sep 2015 16:05:53 -0700 (PDT) X-Received: by 10.68.190.135 with SMTP id gq7mr13018267pbc.152.1442790353484; Sun, 20 Sep 2015 16:05:53 -0700 (PDT) Received: from sspiff.org (173-13-178-53-sfba.hfc.comcastbusiness.net. [173.13.178.53]) by smtp.gmail.com with ESMTPSA id gj10sm1717712pbc.68.2015.09.20.16.05.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Sep 2015 16:05:53 -0700 (PDT) Received: by sspiff.org (sSMTP sendmail emulation); Sun, 20 Sep 2015 16:04:42 -0700 From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH] [PR gdb/17143] Improve memory usage of major obstacks Date: Sun, 20 Sep 2015 16:04:42 -0700 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes 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 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 . */ #include "defs.h" +#include #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);