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

Commit808b319

Browse files
committed
Modify aset.c to track the next intended block allocation size explicitly.
The former coding relied on the actual allocated size of the last block,which made it behave strangely if the first allocation in a context waslarger than ALLOC_CHUNK_LIMIT: subsequent allocations would be referencedto that and not to the intended series of block sizes. Noted whilestudying a memory wastage gripe from Tatsuo.
1 parentfc5eb3f commit808b319

File tree

1 file changed

+15
-27
lines changed

1 file changed

+15
-27
lines changed

‎src/backend/utils/mmgr/aset.c

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1994, Regents of the University of California
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.68 2006/10/04 00:30:04 momjian Exp $
14+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.69 2006/11/08 19:27:24 tgl Exp $
1515
*
1616
* NOTE:
1717
*This is a new (Feb. 05, 1999) implementation of the allocation set
@@ -140,6 +140,7 @@ typedef struct AllocSetContext
140140
/* Allocation parameters for this context: */
141141
SizeinitBlockSize;/* initial block size */
142142
SizemaxBlockSize;/* maximum block size */
143+
SizenextBlockSize;/* next block size to allocate */
143144
AllocBlockkeeper;/* if not NULL, keep this block over resets */
144145
}AllocSetContext;
145146

@@ -325,6 +326,7 @@ AllocSetContextCreate(MemoryContext parent,
325326
maxBlockSize=initBlockSize;
326327
context->initBlockSize=initBlockSize;
327328
context->maxBlockSize=maxBlockSize;
329+
context->nextBlockSize=initBlockSize;
328330

329331
/*
330332
* Grab always-allocated space, if requested
@@ -443,6 +445,9 @@ AllocSetReset(MemoryContext context)
443445
block=next;
444446
}
445447

448+
/* Reset block size allocation sequence, too */
449+
set->nextBlockSize=set->initBlockSize;
450+
446451
set->isReset= true;
447452
}
448453

@@ -665,28 +670,14 @@ AllocSetAlloc(MemoryContext context, Size size)
665670
{
666671
Sizerequired_size;
667672

668-
if (set->blocks==NULL)
669-
{
670-
/* First block of the alloc set, use initBlockSize */
671-
blksize=set->initBlockSize;
672-
}
673-
else
674-
{
675-
/*
676-
* Use first power of 2 that is larger than previous block, but
677-
* not more than the allowed limit. (We don't simply double the
678-
* prior block size, because in some cases this could be a funny
679-
* size, eg if very first allocation was for an odd-sized large
680-
* chunk.)
681-
*/
682-
Sizepblksize=set->blocks->endptr- ((char*)set->blocks);
683-
684-
blksize=set->initBlockSize;
685-
while (blksize <=pblksize)
686-
blksize <<=1;
687-
if (blksize>set->maxBlockSize)
688-
blksize=set->maxBlockSize;
689-
}
673+
/*
674+
* The first such block has size initBlockSize, and we double the
675+
* space in each succeeding block, but not more than maxBlockSize.
676+
*/
677+
blksize=set->nextBlockSize;
678+
set->nextBlockSize <<=1;
679+
if (set->nextBlockSize>set->maxBlockSize)
680+
set->nextBlockSize=set->maxBlockSize;
690681

691682
/*
692683
* If initBlockSize is less than ALLOC_CHUNK_LIMIT, we could need more
@@ -734,11 +725,8 @@ AllocSetAlloc(MemoryContext context, Size size)
734725
* never need any space. Don't mark an oversize block as a keeper,
735726
* however.
736727
*/
737-
if (set->blocks==NULL&&blksize==set->initBlockSize)
738-
{
739-
Assert(set->keeper==NULL);
728+
if (set->keeper==NULL&&blksize==set->initBlockSize)
740729
set->keeper=block;
741-
}
742730

743731
block->next=set->blocks;
744732
set->blocks=block;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp