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

Commit2fd6a44

Browse files
committed
Revert "Specialize MemoryContextMemAllocated()."
This reverts commite00912e.
1 parent2247a1e commit2fd6a44

File tree

5 files changed

+28
-77
lines changed

5 files changed

+28
-77
lines changed

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

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ typedef struct AllocSetContext
132132
SizemaxBlockSize;/* maximum block size */
133133
SizenextBlockSize;/* next block size to allocate */
134134
SizeallocChunkLimit;/* effective chunk size limit */
135-
SizememAllocated;/* track memory allocated for this context */
136135
AllocBlockkeeper;/* keep this block over resets */
137136
/* freelist this context could be put in, or -1 if not a candidate: */
138137
intfreeListIndex;/* index in context_freelists[], or -1 */
@@ -273,7 +272,6 @@ static void *AllocSetRealloc(MemoryContext context, void *pointer, Size size);
273272
staticvoidAllocSetReset(MemoryContextcontext);
274273
staticvoidAllocSetDelete(MemoryContextcontext);
275274
staticSizeAllocSetGetChunkSpace(MemoryContextcontext,void*pointer);
276-
staticSizeAllocSetMemAllocated(MemoryContextcontext);
277275
staticboolAllocSetIsEmpty(MemoryContextcontext);
278276
staticvoidAllocSetStats(MemoryContextcontext,
279277
MemoryStatsPrintFuncprintfunc,void*passthru,
@@ -293,7 +291,6 @@ static const MemoryContextMethods AllocSetMethods = {
293291
AllocSetReset,
294292
AllocSetDelete,
295293
AllocSetGetChunkSpace,
296-
AllocSetMemAllocated,
297294
AllocSetIsEmpty,
298295
AllocSetStats
299296
#ifdefMEMORY_CONTEXT_CHECKING
@@ -467,7 +464,8 @@ AllocSetContextCreateInternal(MemoryContext parent,
467464
parent,
468465
name);
469466

470-
set->memAllocated=set->keeper->endptr- ((char*)set);
467+
((MemoryContext)set)->mem_allocated=
468+
set->keeper->endptr- ((char*)set);
471469

472470
return (MemoryContext)set;
473471
}
@@ -557,7 +555,7 @@ AllocSetContextCreateInternal(MemoryContext parent,
557555
parent,
558556
name);
559557

560-
set->memAllocated=firstBlockSize;
558+
((MemoryContext)set)->mem_allocated=firstBlockSize;
561559

562560
return (MemoryContext)set;
563561
}
@@ -619,7 +617,7 @@ AllocSetReset(MemoryContext context)
619617
else
620618
{
621619
/* Normal case, release the block */
622-
set->memAllocated-=block->endptr- ((char*)block);
620+
context->mem_allocated-=block->endptr- ((char*)block);
623621

624622
#ifdefCLOBBER_FREED_MEMORY
625623
wipe_mem(block,block->freeptr- ((char*)block));
@@ -629,7 +627,7 @@ AllocSetReset(MemoryContext context)
629627
block=next;
630628
}
631629

632-
Assert(set->memAllocated==keepersize);
630+
Assert(context->mem_allocated==keepersize);
633631

634632
/* Reset block size allocation sequence, too */
635633
set->nextBlockSize=set->initBlockSize;
@@ -705,7 +703,7 @@ AllocSetDelete(MemoryContext context)
705703
AllocBlocknext=block->next;
706704

707705
if (block!=set->keeper)
708-
set->memAllocated-=block->endptr- ((char*)block);
706+
context->mem_allocated-=block->endptr- ((char*)block);
709707

710708
#ifdefCLOBBER_FREED_MEMORY
711709
wipe_mem(block,block->freeptr- ((char*)block));
@@ -717,7 +715,7 @@ AllocSetDelete(MemoryContext context)
717715
block=next;
718716
}
719717

720-
Assert(set->memAllocated==keepersize);
718+
Assert(context->mem_allocated==keepersize);
721719

722720
/* Finally, free the context header, including the keeper block */
723721
free(set);
@@ -760,7 +758,7 @@ AllocSetAlloc(MemoryContext context, Size size)
760758
if (block==NULL)
761759
returnNULL;
762760

763-
set->memAllocated+=blksize;
761+
context->mem_allocated+=blksize;
764762

765763
block->aset=set;
766764
block->freeptr=block->endptr= ((char*)block)+blksize;
@@ -957,7 +955,7 @@ AllocSetAlloc(MemoryContext context, Size size)
957955
if (block==NULL)
958956
returnNULL;
959957

960-
set->memAllocated+=blksize;
958+
context->mem_allocated+=blksize;
961959

962960
block->aset=set;
963961
block->freeptr= ((char*)block)+ALLOC_BLOCKHDRSZ;
@@ -1060,7 +1058,7 @@ AllocSetFree(MemoryContext context, void *pointer)
10601058
if (block->next)
10611059
block->next->prev=block->prev;
10621060

1063-
set->memAllocated-=block->endptr- ((char*)block);
1061+
context->mem_allocated-=block->endptr- ((char*)block);
10641062

10651063
#ifdefCLOBBER_FREED_MEMORY
10661064
wipe_mem(block,block->freeptr- ((char*)block));
@@ -1163,8 +1161,8 @@ AllocSetRealloc(MemoryContext context, void *pointer, Size size)
11631161
}
11641162

11651163
/* updated separately, not to underflow when (oldblksize > blksize) */
1166-
set->memAllocated-=oldblksize;
1167-
set->memAllocated+=blksize;
1164+
context->mem_allocated-=oldblksize;
1165+
context->mem_allocated+=blksize;
11681166

11691167
block->freeptr=block->endptr= ((char*)block)+blksize;
11701168

@@ -1339,24 +1337,6 @@ AllocSetGetChunkSpace(MemoryContext context, void *pointer)
13391337
returnresult;
13401338
}
13411339

1342-
/*
1343-
* All memory currently allocated for this context (including fragmentation
1344-
* and freed chunks).
1345-
*
1346-
* Allocation sizes double (up to maxBlockSize), so the current block may
1347-
* represent half of the total space allocated to the context. Subtract away
1348-
* the free space at the tail of the current block, which may never have been
1349-
* touched.
1350-
*/
1351-
staticSize
1352-
AllocSetMemAllocated(MemoryContextcontext)
1353-
{
1354-
AllocSetset= (AllocSet)context;
1355-
AllocBlockcurrentBlock=set->blocks;
1356-
SizetailSpace=currentBlock->endptr-currentBlock->freeptr;
1357-
returnset->memAllocated-tailSpace;
1358-
}
1359-
13601340
/*
13611341
* AllocSetIsEmpty
13621342
*Is an allocset empty of any allocated space?
@@ -1558,7 +1538,7 @@ AllocSetCheck(MemoryContext context)
15581538
name,block);
15591539
}
15601540

1561-
Assert(total_allocated==set->memAllocated);
1541+
Assert(total_allocated==context->mem_allocated);
15621542
}
15631543

15641544
#endif/* MEMORY_CONTEXT_CHECKING */

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ typedef struct GenerationContext
6161

6262
/* Generational context parameters */
6363
SizeblockSize;/* standard block size */
64-
SizememAllocated;/* track memory allocated for this context */
6564

6665
GenerationBlock*block;/* current (most recently allocated) block */
6766
dlist_headblocks;/* list of blocks */
@@ -153,7 +152,6 @@ static void *GenerationRealloc(MemoryContext context, void *pointer, Size size);
153152
staticvoidGenerationReset(MemoryContextcontext);
154153
staticvoidGenerationDelete(MemoryContextcontext);
155154
staticSizeGenerationGetChunkSpace(MemoryContextcontext,void*pointer);
156-
staticSizeGenerationMemAllocated(MemoryContextcontext);
157155
staticboolGenerationIsEmpty(MemoryContextcontext);
158156
staticvoidGenerationStats(MemoryContextcontext,
159157
MemoryStatsPrintFuncprintfunc,void*passthru,
@@ -173,7 +171,6 @@ static const MemoryContextMethods GenerationMethods = {
173171
GenerationReset,
174172
GenerationDelete,
175173
GenerationGetChunkSpace,
176-
GenerationMemAllocated,
177174
GenerationIsEmpty,
178175
GenerationStats
179176
#ifdefMEMORY_CONTEXT_CHECKING
@@ -261,7 +258,6 @@ GenerationContextCreate(MemoryContext parent,
261258

262259
/* Fill in GenerationContext-specific header fields */
263260
set->blockSize=blockSize;
264-
set->memAllocated=0;
265261
set->block=NULL;
266262
dlist_init(&set->blocks);
267263

@@ -301,7 +297,7 @@ GenerationReset(MemoryContext context)
301297

302298
dlist_delete(miter.cur);
303299

304-
set->memAllocated-=block->blksize;
300+
context->mem_allocated-=block->blksize;
305301

306302
#ifdefCLOBBER_FREED_MEMORY
307303
wipe_mem(block,block->blksize);
@@ -358,7 +354,7 @@ GenerationAlloc(MemoryContext context, Size size)
358354
if (block==NULL)
359355
returnNULL;
360356

361-
set->memAllocated+=blksize;
357+
context->mem_allocated+=blksize;
362358

363359
/* block with a single (used) chunk */
364360
block->blksize=blksize;
@@ -415,7 +411,7 @@ GenerationAlloc(MemoryContext context, Size size)
415411
if (block==NULL)
416412
returnNULL;
417413

418-
set->memAllocated+=blksize;
414+
context->mem_allocated+=blksize;
419415

420416
block->blksize=blksize;
421417
block->nchunks=0;
@@ -532,7 +528,7 @@ GenerationFree(MemoryContext context, void *pointer)
532528
if (set->block==block)
533529
set->block=NULL;
534530

535-
set->memAllocated-=block->blksize;
531+
context->mem_allocated-=block->blksize;
536532
free(block);
537533
}
538534

@@ -670,17 +666,6 @@ GenerationGetChunkSpace(MemoryContext context, void *pointer)
670666
returnresult;
671667
}
672668

673-
/*
674-
* All memory currently allocated for this context (including fragmentation
675-
* and freed chunks).
676-
*/
677-
staticSize
678-
GenerationMemAllocated(MemoryContextcontext)
679-
{
680-
GenerationContext*set= (GenerationContext*)context;
681-
returnset->memAllocated;
682-
}
683-
684669
/*
685670
* GenerationIsEmpty
686671
*Is a GenerationContext empty of any allocated space?
@@ -859,7 +844,7 @@ GenerationCheck(MemoryContext context)
859844
name,nfree,block,block->nfree);
860845
}
861846

862-
Assert(total_allocated==gen->memAllocated);
847+
Assert(total_allocated==context->mem_allocated);
863848
}
864849

865850
#endif/* MEMORY_CONTEXT_CHECKING */

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ MemoryContextIsEmpty(MemoryContext context)
469469
Size
470470
MemoryContextMemAllocated(MemoryContextcontext,boolrecurse)
471471
{
472-
Sizetotal=context->methods->mem_allocated(context);
472+
Sizetotal=context->mem_allocated;
473473

474474
AssertArg(MemoryContextIsValid(context));
475475

@@ -760,6 +760,7 @@ MemoryContextCreate(MemoryContext node,
760760
node->methods=methods;
761761
node->parent=parent;
762762
node->firstchild=NULL;
763+
node->mem_allocated=0;
763764
node->prevchild=NULL;
764765
node->name=name;
765766
node->ident=NULL;

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

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ typedef struct SlabContext
6767
SizefullChunkSize;/* chunk size including header and alignment */
6868
SizeblockSize;/* block size */
6969
SizeheaderSize;/* allocated size of context header */
70-
SizememAllocated;/* track memory allocated for this context */
7170
intchunksPerBlock;/* number of chunks per block */
7271
intminFreeChunks;/* min number of free chunks in any block */
7372
intnblocks;/* number of blocks allocated */
@@ -133,7 +132,6 @@ static void *SlabRealloc(MemoryContext context, void *pointer, Size size);
133132
staticvoidSlabReset(MemoryContextcontext);
134133
staticvoidSlabDelete(MemoryContextcontext);
135134
staticSizeSlabGetChunkSpace(MemoryContextcontext,void*pointer);
136-
staticSizeSlabMemAllocated(MemoryContextcontext);
137135
staticboolSlabIsEmpty(MemoryContextcontext);
138136
staticvoidSlabStats(MemoryContextcontext,
139137
MemoryStatsPrintFuncprintfunc,void*passthru,
@@ -152,7 +150,6 @@ static const MemoryContextMethods SlabMethods = {
152150
SlabReset,
153151
SlabDelete,
154152
SlabGetChunkSpace,
155-
SlabMemAllocated,
156153
SlabIsEmpty,
157154
SlabStats
158155
#ifdefMEMORY_CONTEXT_CHECKING
@@ -265,7 +262,6 @@ SlabContextCreate(MemoryContext parent,
265262
slab->fullChunkSize=fullChunkSize;
266263
slab->blockSize=blockSize;
267264
slab->headerSize=headerSize;
268-
slab->memAllocated=0;
269265
slab->chunksPerBlock=chunksPerBlock;
270266
slab->minFreeChunks=0;
271267
slab->nblocks=0;
@@ -290,17 +286,6 @@ SlabContextCreate(MemoryContext parent,
290286
return (MemoryContext)slab;
291287
}
292288

293-
/*
294-
* All memory currently allocated for this context (including fragmentation
295-
* and freed chunks).
296-
*/
297-
staticSize
298-
SlabMemAllocated(MemoryContextcontext)
299-
{
300-
SlabContext*slab= (SlabContext*)context;
301-
returnslab->memAllocated;
302-
}
303-
304289
/*
305290
* SlabReset
306291
*Frees all memory which is allocated in the given set.
@@ -337,14 +322,14 @@ SlabReset(MemoryContext context)
337322
#endif
338323
free(block);
339324
slab->nblocks--;
340-
slab->memAllocated-=slab->blockSize;
325+
context->mem_allocated-=slab->blockSize;
341326
}
342327
}
343328

344329
slab->minFreeChunks=0;
345330

346331
Assert(slab->nblocks==0);
347-
Assert(slab->memAllocated==0);
332+
Assert(context->mem_allocated==0);
348333
}
349334

350335
/*
@@ -422,7 +407,7 @@ SlabAlloc(MemoryContext context, Size size)
422407

423408
slab->minFreeChunks=slab->chunksPerBlock;
424409
slab->nblocks+=1;
425-
slab->memAllocated+=slab->blockSize;
410+
context->mem_allocated+=slab->blockSize;
426411
}
427412

428413
/* grab the block from the freelist (even the new block is there) */
@@ -516,7 +501,7 @@ SlabAlloc(MemoryContext context, Size size)
516501

517502
SlabAllocInfo(slab,chunk);
518503

519-
Assert(slab->nblocks*slab->blockSize==slab->memAllocated);
504+
Assert(slab->nblocks*slab->blockSize==context->mem_allocated);
520505

521506
returnSlabChunkGetPointer(chunk);
522507
}
@@ -593,13 +578,13 @@ SlabFree(MemoryContext context, void *pointer)
593578
{
594579
free(block);
595580
slab->nblocks--;
596-
slab->memAllocated-=slab->blockSize;
581+
context->mem_allocated-=slab->blockSize;
597582
}
598583
else
599584
dlist_push_head(&slab->freelist[block->nfree],&block->node);
600585

601586
Assert(slab->nblocks >=0);
602-
Assert(slab->nblocks*slab->blockSize==slab->memAllocated);
587+
Assert(slab->nblocks*slab->blockSize==context->mem_allocated);
603588
}
604589

605590
/*
@@ -819,7 +804,7 @@ SlabCheck(MemoryContext context)
819804
}
820805
}
821806

822-
Assert(slab->nblocks*slab->blockSize==slab->memAllocated);
807+
Assert(slab->nblocks*slab->blockSize==context->mem_allocated);
823808
}
824809

825810
#endif/* MEMORY_CONTEXT_CHECKING */

‎src/include/nodes/memnodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ typedef struct MemoryContextMethods
6363
void(*reset) (MemoryContextcontext);
6464
void(*delete_context) (MemoryContextcontext);
6565
Size(*get_chunk_space) (MemoryContextcontext,void*pointer);
66-
Size(*mem_allocated) (MemoryContextcontext);
6766
bool(*is_empty) (MemoryContextcontext);
6867
void(*stats) (MemoryContextcontext,
6968
MemoryStatsPrintFuncprintfunc,void*passthru,
@@ -80,6 +79,7 @@ typedef struct MemoryContextData
8079
/* these two fields are placed here to minimize alignment wastage: */
8180
boolisReset;/* T = no space alloced since last reset */
8281
boolallowInCritSection;/* allow palloc in critical section */
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