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

Commitf2369bc

Browse files
committed
Use Size instead of int64 to track allocated memory
Commit5dd7fc1 added block-level memory accounting, but used int64 variable totrack the amount of allocated memory. That is incorrect, because we have Size forexactly these purposes, but it was mostly harmless untilc477f3e which changedhow we handle with repalloc() when downsizing the chunk. Previously we've ignoredthese cases and just kept using the original chunk, but now we need to update theaccounting, and the code was doing this: context->mem_allocated += blksize - oldblksize;Both blksize and oldblksize are Size (so unsigned) which means the subtractionunderflows, producing a very high positive value. On 64-bit platforms (where Sizehas the same size as mem_alllocated) this happens to work because the result wrapsto the right value, but on (some) 32-bit platforms this fails.This fixes two things - it changes mem_allocated (and related variables) to Size,and it splits the update to two separate steps, to prevent any underflows.Discussion:https://www.postgresql.org/message-id/15151.1570163761%40sss.pgh.pa.us
1 parent967e276 commitf2369bc

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,9 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size)
11541154
returnNULL;
11551155
}
11561156

1157-
context->mem_allocated+=blksize-oldblksize;
1157+
/* updated separately, not to underflow when (oldblksize > blksize) */
1158+
context->mem_allocated-=oldblksize;
1159+
context->mem_allocated+=blksize;
11581160

11591161
block->freeptr=block->endptr= ((char*)block)+blksize;
11601162

@@ -1427,7 +1429,7 @@ AllocSetCheck(MemoryContext context)
14271429
constchar*name=set->header.name;
14281430
AllocBlockprevblock;
14291431
AllocBlockblock;
1430-
int64total_allocated=0;
1432+
Sizetotal_allocated=0;
14311433

14321434
for (prevblock=NULL,block=set->blocks;
14331435
block!=NULL;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ GenerationCheck(MemoryContext context)
753753
GenerationContext*gen= (GenerationContext*)context;
754754
constchar*name=context->name;
755755
dlist_iteriter;
756-
int64total_allocated=0;
756+
Sizetotal_allocated=0;
757757

758758
/* walk all blocks in this context */
759759
dlist_foreach(iter,&gen->blocks)

‎src/include/nodes/memnodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ typedef struct MemoryContextData
7979
/* these two fields are placed here to minimize alignment wastage: */
8080
boolisReset;/* T = no space alloced since last reset */
8181
boolallowInCritSection;/* allow palloc in critical section */
82-
int64mem_allocated;/* track memory allocated for this context */
82+
Sizemem_allocated;/* track memory allocated for this context */
8383
constMemoryContextMethods*methods;/* virtual function table */
8484
MemoryContextparent;/* NULL if no parent (toplevel context) */
8585
MemoryContextfirstchild;/* head of linked list of children */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp