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

Commitb70d4a6

Browse files
committed
Remove an "optimization" I installed in 2001, to make repalloc() attempt to
enlarge the memory chunk in-place when it was feasible to do so. This turnsout to not work well at all for scenarios involving repeated cycles ofpalloc/repalloc/pfree: the eventually freed chunks go into the wrong freelistfor the next initial palloc request, and so we consume memory indefinitely.While that could be defended against, the number of cases where theoptimization can still be applied drops significantly, and adjusting theinitial sizes of StringInfo buffers makes it drop to almost nothing.Seems better to just remove the extra complexity.Per recent discussion and testing.
1 parent70868c0 commitb70d4a6

File tree

1 file changed

+10
-49
lines changed

1 file changed

+10
-49
lines changed

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

Lines changed: 10 additions & 49 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.73 2007/08/07 06:25:14neilc Exp $
14+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/aset.c,v 1.74 2007/08/12 20:39:14tgl Exp $
1515
*
1616
* NOTE:
1717
*This is a new (Feb. 05, 1999) implementation of the allocation set
@@ -932,57 +932,18 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size)
932932
else
933933
{
934934
/*
935-
* Small-chunk case. If the chunk is the last one in its block, there
936-
* might be enough free space after it that we can just enlarge the
937-
* chunk in-place.It's relatively painful to find the containing
938-
* block in the general case, but we can detect last-ness quite
939-
* cheaply for the typical case where the chunk is in the active
940-
* (topmost) allocation block.(At least with the regression tests
941-
* and code as of 1/2001, realloc'ing the last chunk of a non-topmost
942-
* block hardly ever happens, so it's not worth scanning the block
943-
* list to catch that case.)
944-
*
945-
* NOTE: must be careful not to create a chunk of a size that
946-
* AllocSetAlloc would not create, else we'll get confused later.
935+
* Small-chunk case. We just do this by brute force, ie, allocate a
936+
* new chunk and copy the data. Since we know the existing data isn't
937+
* huge, this won't involve any great memcpy expense, so it's not
938+
* worth being smarter. (At one time we tried to avoid memcpy when
939+
* it was possible to enlarge the chunk in-place, but that turns out
940+
* to misbehave unpleasantly for repeated cycles of
941+
* palloc/repalloc/pfree: the eventually freed chunks go into the
942+
* wrong freelist for the next initial palloc request, and so we leak
943+
* memory indefinitely. See pgsql-hackers archives for 2007-08-11.)
947944
*/
948945
AllocPointernewPointer;
949946

950-
if (size <=set->allocChunkLimit)
951-
{
952-
AllocBlockblock=set->blocks;
953-
char*chunk_end;
954-
955-
chunk_end= (char*)chunk+ (oldsize+ALLOC_CHUNKHDRSZ);
956-
if (chunk_end==block->freeptr)
957-
{
958-
/* OK, it's last in block ... is there room? */
959-
Sizefreespace=block->endptr-block->freeptr;
960-
intfidx;
961-
Sizenewsize;
962-
Sizedelta;
963-
964-
fidx=AllocSetFreeIndex(size);
965-
newsize=1 << (fidx+ALLOC_MINBITS);
966-
Assert(newsize >=oldsize);
967-
delta=newsize-oldsize;
968-
if (freespace >=delta)
969-
{
970-
/* Yes, so just enlarge the chunk. */
971-
block->freeptr+=delta;
972-
chunk->size+=delta;
973-
#ifdefMEMORY_CONTEXT_CHECKING
974-
chunk->requested_size=size;
975-
/* set mark to catch clobber of "unused" space */
976-
if (size<chunk->size)
977-
((char*)pointer)[size]=0x7E;
978-
#endif
979-
returnpointer;
980-
}
981-
}
982-
}
983-
984-
/* Normal small-chunk case: just do it by brute force. */
985-
986947
/* allocate new chunk */
987948
newPointer=AllocSetAlloc((MemoryContext)set,size);
988949

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp