aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-08-19 16:16:20 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-08-19 16:16:20 +0000
commitbc7cb8f42cc607f1fcd2aca0a7b007fc8e9930d0 (patch)
tree0cc077b9082f0b915878f92117b3144f0c879796
parente275d16a54de5595ed70cafd99c801af2fbdbc8b (diff)
downloadpostgresql-bc7cb8f42cc607f1fcd2aca0a7b007fc8e9930d0.tar.gz
postgresql-bc7cb8f42cc607f1fcd2aca0a7b007fc8e9930d0.zip
Allocate local buffers in a context of their own, rather than dumping them
into TopMemoryContext. This makes no functional difference, but makes it easier to see what the space is being used for in MemoryContextStats dumps. Per a recent example in which I was surprised by the size of TopMemoryContext.
-rw-r--r--src/backend/storage/buffer/localbuf.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/backend/storage/buffer/localbuf.c b/src/backend/storage/buffer/localbuf.c
index dd067737c99..6572917f834 100644
--- a/src/backend/storage/buffer/localbuf.c
+++ b/src/backend/storage/buffer/localbuf.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.90 2010/08/13 20:10:52 rhaas Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.91 2010/08/19 16:16:20 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -399,6 +399,7 @@ GetLocalBufferStorage(void)
static int next_buf_in_block = 0;
static int num_bufs_in_block = 0;
static int total_bufs_allocated = 0;
+ static MemoryContext LocalBufferContext = NULL;
char *this_buf;
@@ -409,6 +410,19 @@ GetLocalBufferStorage(void)
/* Need to make a new request to memmgr */
int num_bufs;
+ /*
+ * We allocate local buffers in a context of their own, so that the
+ * space eaten for them is easily recognizable in MemoryContextStats
+ * output. Create the context on first use.
+ */
+ if (LocalBufferContext == NULL)
+ LocalBufferContext =
+ AllocSetContextCreate(TopMemoryContext,
+ "LocalBufferContext",
+ ALLOCSET_DEFAULT_MINSIZE,
+ ALLOCSET_DEFAULT_INITSIZE,
+ ALLOCSET_DEFAULT_MAXSIZE);
+
/* Start with a 16-buffer request; subsequent ones double each time */
num_bufs = Max(num_bufs_in_block * 2, 16);
/* But not more than what we need for all remaining local bufs */
@@ -416,8 +430,7 @@ GetLocalBufferStorage(void)
/* And don't overflow MaxAllocSize, either */
num_bufs = Min(num_bufs, MaxAllocSize / BLCKSZ);
- /* Allocate space from TopMemoryContext so it never goes away */
- cur_block = (char *) MemoryContextAlloc(TopMemoryContext,
+ cur_block = (char *) MemoryContextAlloc(LocalBufferContext,
num_bufs * BLCKSZ);
next_buf_in_block = 0;
num_bufs_in_block = num_bufs;