Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc7cb8f

Browse files
committed
Allocate local buffers in a context of their own, rather than dumping them
into TopMemoryContext. This makes no functional difference, but makes iteasier 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.
1 parente275d16 commitbc7cb8f

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

‎src/backend/storage/buffer/localbuf.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.90 2010/08/13 20:10:52 rhaas Exp $
12+
* $PostgreSQL: pgsql/src/backend/storage/buffer/localbuf.c,v 1.91 2010/08/19 16:16:20 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -399,6 +399,7 @@ GetLocalBufferStorage(void)
399399
staticintnext_buf_in_block=0;
400400
staticintnum_bufs_in_block=0;
401401
staticinttotal_bufs_allocated=0;
402+
staticMemoryContextLocalBufferContext=NULL;
402403

403404
char*this_buf;
404405

@@ -409,15 +410,27 @@ GetLocalBufferStorage(void)
409410
/* Need to make a new request to memmgr */
410411
intnum_bufs;
411412

413+
/*
414+
* We allocate local buffers in a context of their own, so that the
415+
* space eaten for them is easily recognizable in MemoryContextStats
416+
* output. Create the context on first use.
417+
*/
418+
if (LocalBufferContext==NULL)
419+
LocalBufferContext=
420+
AllocSetContextCreate(TopMemoryContext,
421+
"LocalBufferContext",
422+
ALLOCSET_DEFAULT_MINSIZE,
423+
ALLOCSET_DEFAULT_INITSIZE,
424+
ALLOCSET_DEFAULT_MAXSIZE);
425+
412426
/* Start with a 16-buffer request; subsequent ones double each time */
413427
num_bufs=Max(num_bufs_in_block*2,16);
414428
/* But not more than what we need for all remaining local bufs */
415429
num_bufs=Min(num_bufs,NLocBuffer-total_bufs_allocated);
416430
/* And don't overflow MaxAllocSize, either */
417431
num_bufs=Min(num_bufs,MaxAllocSize /BLCKSZ);
418432

419-
/* Allocate space from TopMemoryContext so it never goes away */
420-
cur_block= (char*)MemoryContextAlloc(TopMemoryContext,
433+
cur_block= (char*)MemoryContextAlloc(LocalBufferContext,
421434
num_bufs*BLCKSZ);
422435
next_buf_in_block=0;
423436
num_bufs_in_block=num_bufs;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp