From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12317 invoked by alias); 5 Aug 2008 20:32:49 -0000 Received: (qmail 12308 invoked by uid 22791); 5 Aug 2008 20:32:48 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 05 Aug 2008 20:32:14 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m75KOVr8011180 for ; Tue, 5 Aug 2008 16:25:01 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m75KOTg3004244; Tue, 5 Aug 2008 16:24:29 -0400 Received: from opsy.redhat.com (vpn-10-102.bos.redhat.com [10.16.10.102]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m75KOReN003095; Tue, 5 Aug 2008 16:24:27 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 59838378157; Tue, 5 Aug 2008 14:24:27 -0600 (MDT) To: gdb-patches@sourceware.org Subject: RFA: lazily allocate bcache obstack From: Tom Tromey Reply-To: tromey@redhat.com X-Attribution: Tom Date: Tue, 05 Aug 2008 20:32:00 -0000 Message-ID: User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-08/txt/msg00088.txt.bz2 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 * 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); }