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

Commit6f4cfe4

Browse files
committed
Improve GIN index build's tracking of memory usage by using
GetMemoryChunkSpace, not just the palloc request size. This brings theallocatedMemory counter close enough to reality (as measured byMemoryContextStats printouts) that I think we can get rid of the arbitraryfactor-of-2 adjustment that was put into the code initially. Given thesensitivity of GIN build to work memory size, not using as much of workmemory as we're allowed to seems a pretty bad idea.
1 parent16dcd5e commit6f4cfe4

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

‎src/backend/access/gin/ginbulk.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
*$PostgreSQL: pgsql/src/backend/access/gin/ginbulk.c,v 1.9 2007/02/01 04:16:08 neilc Exp $
11+
*$PostgreSQL: pgsql/src/backend/access/gin/ginbulk.c,v 1.10 2007/11/16 21:55:59 tgl Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

1515
#include"postgres.h"
1616

1717
#include"access/gin.h"
1818
#include"utils/datum.h"
19+
#include"utils/memutils.h"
1920

2021

2122
#defineDEF_NENTRY2048
@@ -38,7 +39,7 @@ EAAllocate(BuildAccumulator *accum)
3839
if (accum->entryallocator==NULL||accum->length >=DEF_NENTRY)
3940
{
4041
accum->entryallocator=palloc(sizeof(EntryAccumulator)*DEF_NENTRY);
41-
accum->allocatedMemory+=sizeof(EntryAccumulator)*DEF_NENTRY;
42+
accum->allocatedMemory+=GetMemoryChunkSpace(accum->entryallocator);
4243
accum->length=0;
4344
}
4445

@@ -55,10 +56,11 @@ ginInsertData(BuildAccumulator *accum, EntryAccumulator *entry, ItemPointer heap
5556
{
5657
if (entry->number >=entry->length)
5758
{
58-
accum->allocatedMemory+=sizeof(ItemPointerData)*entry->length;
59+
accum->allocatedMemory-=GetMemoryChunkSpace(entry->list);
5960
entry->length *=2;
6061
entry->list= (ItemPointerData*)repalloc(entry->list,
6162
sizeof(ItemPointerData)*entry->length);
63+
accum->allocatedMemory+=GetMemoryChunkSpace(entry->list);
6264
}
6365

6466
if (entry->shouldSort== FALSE)
@@ -95,10 +97,10 @@ getDatumCopy(BuildAccumulator *accum, Datum value)
9597
realSize=datumGetSize(value, false,att[0]->attlen);
9698

9799
s= (char*)palloc(realSize);
100+
accum->allocatedMemory+=GetMemoryChunkSpace(s);
101+
98102
memcpy(s,DatumGetPointer(value),realSize);
99103
res=PointerGetDatum(s);
100-
101-
accum->allocatedMemory+=realSize;
102104
}
103105
returnres;
104106
}
@@ -143,8 +145,8 @@ ginInsertEntry(BuildAccumulator *accum, ItemPointer heapptr, Datum entry)
143145
ea->number=1;
144146
ea->shouldSort= FALSE;
145147
ea->list= (ItemPointerData*)palloc(sizeof(ItemPointerData)*DEF_NPTR);
148+
accum->allocatedMemory+=GetMemoryChunkSpace(ea->list);
146149
ea->list[0]=*heapptr;
147-
accum->allocatedMemory+=sizeof(ItemPointerData)*DEF_NPTR;
148150

149151
if (pea==NULL)
150152
accum->entries=ea;
@@ -270,11 +272,11 @@ ginGetEntry(BuildAccumulator *accum, Datum *value, uint32 *n)
270272
EntryAccumulator*entry;
271273
ItemPointerData*list;
272274

273-
274275
if (accum->stack==NULL)
275276
{
276277
/* first call */
277278
accum->stack=palloc0(sizeof(EntryAccumulator*)* (accum->maxdepth+1));
279+
accum->allocatedMemory+=GetMemoryChunkSpace(accum->stack);
278280
entry=accum->entries;
279281

280282
if (entry==NULL)
@@ -295,6 +297,7 @@ ginGetEntry(BuildAccumulator *accum, Datum *value, uint32 *n)
295297
}
296298
else
297299
{
300+
accum->allocatedMemory-=GetMemoryChunkSpace(accum->stack[accum->stackpos]->list);
298301
pfree(accum->stack[accum->stackpos]->list);
299302
accum->stack[accum->stackpos]->list=NULL;
300303
entry=walkTree(accum);

‎src/backend/access/gin/gininsert.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
*$PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.9 2007/06/05 12:47:49 teodor Exp $
11+
*$PostgreSQL: pgsql/src/backend/access/gin/gininsert.c,v 1.10 2007/11/16 21:55:59 tgl Exp $
1212
*-------------------------------------------------------------------------
1313
*/
1414

1515
#include"postgres.h"
16+
1617
#include"access/genam.h"
1718
#include"access/gin.h"
1819
#include"catalog/index.h"
1920
#include"miscadmin.h"
2021
#include"utils/memutils.h"
2122

23+
2224
typedefstruct
2325
{
2426
GinStateginstate;
@@ -132,8 +134,7 @@ addItemPointersToTuple(Relation index, GinState *ginstate, GinBtreeStack *stack,
132134
}
133135

134136
/*
135-
* Inserts only one entry to the index, but it can adds more that 1
136-
* ItemPointer.
137+
* Inserts only one entry to the index, but it can add more than 1 ItemPointer.
137138
*/
138139
staticvoid
139140
ginEntryInsert(Relationindex,GinState*ginstate,Datumvalue,ItemPointerData*items,uint32nitem,boolisBuild)
@@ -198,7 +199,7 @@ ginEntryInsert(Relation index, GinState *ginstate, Datum value, ItemPointerData
198199

199200
/*
200201
* Saves indexed value in memory accumulator during index creation
201-
* Function isn'tuse during normal insert
202+
* Function isn'tused during normal insert
202203
*/
203204
staticuint32
204205
ginHeapTupleBulkInsert(GinBuildState*buildstate,Datumvalue,ItemPointerheapptr)
@@ -226,7 +227,6 @@ static void
226227
ginBuildCallback(Relationindex,HeapTuplehtup,Datum*values,
227228
bool*isnull,booltupleIsAlive,void*state)
228229
{
229-
230230
GinBuildState*buildstate= (GinBuildState*)state;
231231
MemoryContextoldCtx;
232232

@@ -237,11 +237,8 @@ ginBuildCallback(Relation index, HeapTuple htup, Datum *values,
237237

238238
buildstate->indtuples+=ginHeapTupleBulkInsert(buildstate,*values,&htup->t_self);
239239

240-
/*
241-
* we use only half maintenance_work_mem, because there is some leaks
242-
* during insertion and extract values
243-
*/
244-
if (buildstate->accum.allocatedMemory >=maintenance_work_mem*1024L /2L)
240+
/* If we've maxed out our available memory, dump everything to the index */
241+
if (buildstate->accum.allocatedMemory >=maintenance_work_mem*1024L)
245242
{
246243
ItemPointerData*list;
247244
Datumentry;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp