Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RFA: lazily allocate bcache obstack
@ 2008-08-05 20:32 Tom Tromey
  2008-08-05 20:35 ` Daniel Jacobowitz
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2008-08-05 20:32 UTC (permalink / raw)
  To: gdb-patches

Today I was looking at 'maint print statistics' for a large program
(openoffice, with 162 shared libraries).

In the output I noticed that in many cases there was an empty bcache
of some kind, each taking around 4k.

This patch changes bcache to lazily initialize its obstack.  According
to 'maint space 1', this saved 2355200 bytes on the openoffice test
case.

Built and regtested on x86-64 (compile farm).
Ok?

Tom

b/gdb/ChangeLog:
2008-08-05  Tom Tromey  <tromey@redhat.com>

	* bcache.c (deprecated_bcache_added): Initialize obstack.
	(bcache_xmalloc): Don't initialize obstack.
	(bcache_xfree): Conditionally free obstack.

diff --git a/gdb/bcache.c b/gdb/bcache.c
index 9f7a915..6235df5 100644
--- a/gdb/bcache.c
+++ b/gdb/bcache.c
@@ -231,6 +231,16 @@ deprecated_bcache_added (const void *addr, int length, struct bcache *bcache,
   if (added)
     *added = 0;
 
+  /* Lazily initialize the obstack.  This can save quite a bit of
+     memory in some cases.  */
+  if (bcache->total_count == 0)
+    {
+      /* We could use obstack_specify_allocation here instead, but
+	 gdb_obstack.h specifies the allocation/deallocation
+	 functions.  */
+      obstack_init (&bcache->cache);
+    }
+
   /* If our average chain length is too high, expand the hash table.  */
   if (bcache->unique_count >= bcache->num_buckets * CHAIN_LENGTH_THRESHOLD)
     expand_hash_table (bcache);
@@ -285,10 +295,6 @@ bcache_xmalloc (void)
 {
   /* Allocate the bcache pre-zeroed.  */
   struct bcache *b = XCALLOC (1, struct bcache);
-  /* We could use obstack_specify_allocation here instead, but
-     gdb_obstack.h specifies the allocation/deallocation
-     functions.  */
-  obstack_init (&b->cache);
   return b;
 }
 
@@ -298,7 +304,9 @@ bcache_xfree (struct bcache *bcache)
 {
   if (bcache == NULL)
     return;
-  obstack_free (&bcache->cache, 0);
+  /* Only free the obstack if we actually initialized it.  */
+  if (bcache->total_count > 0)
+    obstack_free (&bcache->cache, 0);
   xfree (bcache->bucket);
   xfree (bcache);
 }
@@ -457,5 +465,7 @@ print_bcache_statistics (struct bcache *c, char *type)
 int
 bcache_memory_used (struct bcache *bcache)
 {
+  if (bcache->total_count == 0)
+    return 0;
   return obstack_memory_used (&bcache->cache);
 }


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

* Re: RFA: lazily allocate bcache obstack
  2008-08-05 20:32 RFA: lazily allocate bcache obstack Tom Tromey
@ 2008-08-05 20:35 ` Daniel Jacobowitz
  2008-08-05 20:44   ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Jacobowitz @ 2008-08-05 20:35 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On Tue, Aug 05, 2008 at 02:24:26PM -0600, Tom Tromey wrote:
> 2008-08-05  Tom Tromey  <tromey@redhat.com>
> 
> 	* bcache.c (deprecated_bcache_added): Initialize obstack.
> 	(bcache_xmalloc): Don't initialize obstack.
> 	(bcache_xfree): Conditionally free obstack.

OK.

-- 
Daniel Jacobowitz
CodeSourcery


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

* Re: RFA: lazily allocate bcache obstack
  2008-08-05 20:35 ` Daniel Jacobowitz
@ 2008-08-05 20:44   ` Tom Tromey
  0 siblings, 0 replies; 3+ messages in thread
From: Tom Tromey @ 2008-08-05 20:44 UTC (permalink / raw)
  To: gdb-patches

>>>>> "Daniel" == Daniel Jacobowitz <drow@false.org> writes:

>> * bcache.c (deprecated_bcache_added): Initialize obstack.
>> (bcache_xmalloc): Don't initialize obstack.
>> (bcache_xfree): Conditionally free obstack.

Daniel> OK.

Just FYI, I missed a ChangeLog entry for bcache_memory_used here, so I
added one before committing.

Tom


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

end of thread, other threads:[~2008-08-05 20:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-05 20:32 RFA: lazily allocate bcache obstack Tom Tromey
2008-08-05 20:35 ` Daniel Jacobowitz
2008-08-05 20:44   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox