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

Commit3fcc7e8

Browse files
committed
Reduce memory consumption during VACUUM of large relations, by using
FSMPageData (6 bytes) instead of PageFreeSpaceInfo (8 or 16 bytes)for the temporary array of page-free-space information.Itagaki Takahiro
1 parent9537739 commit3fcc7e8

File tree

4 files changed

+48
-60
lines changed

4 files changed

+48
-60
lines changed

‎src/backend/commands/vacuum.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.365 2008/02/20 14:31:35 alvherre Exp $
16+
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.366 2008/03/10 02:04:08 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -3461,7 +3461,7 @@ vac_update_fsm(Relation onerel, VacPageList fraged_pages,
34613461
intnPages=fraged_pages->num_pages;
34623462
VacPage*pagedesc=fraged_pages->pagedesc;
34633463
Sizethreshold;
3464-
PageFreeSpaceInfo*pageSpaces;
3464+
FSMPageData*pageSpaces;
34653465
intoutPages;
34663466
inti;
34673467

@@ -3477,8 +3477,7 @@ vac_update_fsm(Relation onerel, VacPageList fraged_pages,
34773477
*/
34783478
threshold=GetAvgFSMRequestSize(&onerel->rd_node);
34793479

3480-
pageSpaces= (PageFreeSpaceInfo*)
3481-
palloc(nPages*sizeof(PageFreeSpaceInfo));
3480+
pageSpaces= (FSMPageData*)palloc(nPages*sizeof(FSMPageData));
34823481
outPages=0;
34833482

34843483
for (i=0;i<nPages;i++)
@@ -3493,8 +3492,8 @@ vac_update_fsm(Relation onerel, VacPageList fraged_pages,
34933492

34943493
if (pagedesc[i]->free >=threshold)
34953494
{
3496-
pageSpaces[outPages].blkno=pagedesc[i]->blkno;
3497-
pageSpaces[outPages].avail=pagedesc[i]->free;
3495+
FSMPageSetPageNum(&pageSpaces[outPages],pagedesc[i]->blkno);
3496+
FSMPageSetSpace(&pageSpaces[outPages],pagedesc[i]->free);
34983497
outPages++;
34993498
}
35003499
}

‎src/backend/commands/vacuumlazy.c

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*
3939
*
4040
* IDENTIFICATION
41-
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.103 2008/01/01 19:45:49 momjian Exp $
41+
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.104 2008/03/10 02:04:09 tgl Exp $
4242
*
4343
*-------------------------------------------------------------------------
4444
*/
@@ -98,7 +98,7 @@ typedef struct LVRelStats
9898
boolfs_is_heap;/* are we using heap organization? */
9999
intnum_free_pages;/* current # of entries */
100100
intmax_free_pages;/* # slots allocated in array */
101-
PageFreeSpaceInfo*free_pages;/* array or heap of blkno/avail */
101+
FSMPageData*free_pages;/* array or heap of blkno/avail */
102102
BlockNumbertot_free_pages;/* total pages with >= threshold space */
103103
intnum_index_scans;
104104
}LVRelStats;
@@ -813,7 +813,7 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
813813
{
814814
BlockNumberold_rel_pages=vacrelstats->rel_pages;
815815
BlockNumbernew_rel_pages;
816-
PageFreeSpaceInfo*pageSpaces;
816+
FSMPageData*pageSpaces;
817817
intn;
818818
inti,
819819
j;
@@ -881,7 +881,7 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats)
881881
j=0;
882882
for (i=0;i<n;i++)
883883
{
884-
if (pageSpaces[i].blkno<new_rel_pages)
884+
if (FSMPageGetPageNum(&pageSpaces[i])<new_rel_pages)
885885
{
886886
pageSpaces[j]=pageSpaces[i];
887887
j++;
@@ -1028,16 +1028,16 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
10281028
palloc(maxtuples*sizeof(ItemPointerData));
10291029

10301030
maxpages=MaxFSMPages;
1031-
maxpages=Min(maxpages,MaxAllocSize /sizeof(PageFreeSpaceInfo));
1031+
maxpages=Min(maxpages,MaxAllocSize /sizeof(FSMPageData));
10321032
/* No need to allocate more pages than the relation has blocks */
10331033
if (relblocks< (BlockNumber)maxpages)
10341034
maxpages= (int)relblocks;
10351035

10361036
vacrelstats->fs_is_heap= false;
10371037
vacrelstats->num_free_pages=0;
10381038
vacrelstats->max_free_pages=maxpages;
1039-
vacrelstats->free_pages= (PageFreeSpaceInfo*)
1040-
palloc(maxpages*sizeof(PageFreeSpaceInfo));
1039+
vacrelstats->free_pages= (FSMPageData*)
1040+
palloc(maxpages*sizeof(FSMPageData));
10411041
vacrelstats->tot_free_pages=0;
10421042
}
10431043

@@ -1068,7 +1068,7 @@ lazy_record_free_space(LVRelStats *vacrelstats,
10681068
BlockNumberpage,
10691069
Sizeavail)
10701070
{
1071-
PageFreeSpaceInfo*pageSpaces;
1071+
FSMPageData*pageSpaces;
10721072
intn;
10731073

10741074
/*
@@ -1098,8 +1098,8 @@ lazy_record_free_space(LVRelStats *vacrelstats,
10981098
/* If we haven't filled the array yet, just keep adding entries */
10991099
if (vacrelstats->num_free_pages<n)
11001100
{
1101-
pageSpaces[vacrelstats->num_free_pages].blkno=page;
1102-
pageSpaces[vacrelstats->num_free_pages].avail=avail;
1101+
FSMPageSetPageNum(&pageSpaces[vacrelstats->num_free_pages],page);
1102+
FSMPageSetSpace(&pageSpaces[vacrelstats->num_free_pages],avail);
11031103
vacrelstats->num_free_pages++;
11041104
return;
11051105
}
@@ -1127,8 +1127,8 @@ lazy_record_free_space(LVRelStats *vacrelstats,
11271127

11281128
while (--l >=0)
11291129
{
1130-
BlockNumberR=pageSpaces[l].blkno;
1131-
SizeK=pageSpaces[l].avail;
1130+
BlockNumberR=FSMPageGetPageNum(&pageSpaces[l]);
1131+
SizeK=FSMPageGetSpace(&pageSpaces[l]);
11321132
inti;/* i is where the "hole" is */
11331133

11341134
i=l;
@@ -1138,22 +1138,22 @@ lazy_record_free_space(LVRelStats *vacrelstats,
11381138

11391139
if (j >=n)
11401140
break;
1141-
if (j+1<n&&pageSpaces[j].avail>pageSpaces[j+1].avail)
1141+
if (j+1<n&&FSMPageGetSpace(&pageSpaces[j])>FSMPageGetSpace(&pageSpaces[j+1]))
11421142
j++;
1143-
if (K <=pageSpaces[j].avail)
1143+
if (K <=FSMPageGetSpace(&pageSpaces[j]))
11441144
break;
11451145
pageSpaces[i]=pageSpaces[j];
11461146
i=j;
11471147
}
1148-
pageSpaces[i].blkno=R;
1149-
pageSpaces[i].avail=K;
1148+
FSMPageSetPageNum(&pageSpaces[i],R);
1149+
FSMPageSetSpace(&pageSpaces[i],K);
11501150
}
11511151

11521152
vacrelstats->fs_is_heap= true;
11531153
}
11541154

11551155
/* If new page has more than zero'th entry, insert it into heap */
1156-
if (avail>pageSpaces[0].avail)
1156+
if (avail>FSMPageGetSpace(&pageSpaces[0]))
11571157
{
11581158
/*
11591159
* Notionally, we replace the zero'th entry with the new data, and
@@ -1169,15 +1169,15 @@ lazy_record_free_space(LVRelStats *vacrelstats,
11691169

11701170
if (j >=n)
11711171
break;
1172-
if (j+1<n&&pageSpaces[j].avail>pageSpaces[j+1].avail)
1172+
if (j+1<n&&FSMPageGetSpace(&pageSpaces[j])>FSMPageGetSpace(&pageSpaces[j+1]))
11731173
j++;
1174-
if (avail <=pageSpaces[j].avail)
1174+
if (avail <=FSMPageGetSpace(&pageSpaces[j]))
11751175
break;
11761176
pageSpaces[i]=pageSpaces[j];
11771177
i=j;
11781178
}
1179-
pageSpaces[i].blkno=page;
1180-
pageSpaces[i].avail=avail;
1179+
FSMPageSetPageNum(&pageSpaces[i],page);
1180+
FSMPageSetSpace(&pageSpaces[i],avail);
11811181
}
11821182
}
11831183

@@ -1210,14 +1210,14 @@ lazy_tid_reaped(ItemPointer itemptr, void *state)
12101210
staticvoid
12111211
lazy_update_fsm(Relationonerel,LVRelStats*vacrelstats)
12121212
{
1213-
PageFreeSpaceInfo*pageSpaces=vacrelstats->free_pages;
1213+
FSMPageData*pageSpaces=vacrelstats->free_pages;
12141214
intnPages=vacrelstats->num_free_pages;
12151215

12161216
/*
12171217
* Sort data into order, as required by RecordRelationFreeSpace.
12181218
*/
12191219
if (nPages>1)
1220-
qsort(pageSpaces,nPages,sizeof(PageFreeSpaceInfo),
1220+
qsort(pageSpaces,nPages,sizeof(FSMPageData),
12211221
vac_cmp_page_spaces);
12221222

12231223
RecordRelationFreeSpace(&onerel->rd_node,vacrelstats->tot_free_pages,
@@ -1257,12 +1257,14 @@ vac_cmp_itemptr(const void *left, const void *right)
12571257
staticint
12581258
vac_cmp_page_spaces(constvoid*left,constvoid*right)
12591259
{
1260-
PageFreeSpaceInfo*linfo= (PageFreeSpaceInfo*)left;
1261-
PageFreeSpaceInfo*rinfo= (PageFreeSpaceInfo*)right;
1260+
FSMPageData*linfo= (FSMPageData*)left;
1261+
FSMPageData*rinfo= (FSMPageData*)right;
1262+
BlockNumberlblkno=FSMPageGetPageNum(linfo);
1263+
BlockNumberrblkno=FSMPageGetPageNum(rinfo);
12621264

1263-
if (linfo->blkno<rinfo->blkno)
1265+
if (lblkno<rblkno)
12641266
return-1;
1265-
elseif (linfo->blkno>rinfo->blkno)
1267+
elseif (lblkno>rblkno)
12661268
return1;
12671269
return0;
12681270
}

‎src/backend/storage/freespace/freespace.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.59 2008/01/01 19:45:51 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.60 2008/03/10 02:04:09 tgl Exp $
1212
*
1313
*
1414
* NOTES:
@@ -143,7 +143,7 @@ static bool lookup_fsm_page_entry(FSMRelation *fsmrel, BlockNumber page,
143143
staticvoidcompact_fsm_storage(void);
144144
staticvoidpush_fsm_rels_after(FSMRelation*afterRel);
145145
staticvoidpack_incoming_pages(FSMPageData*newLocation,intnewPages,
146-
PageFreeSpaceInfo*pageSpaces,intnPages);
146+
FSMPageData*pageSpaces,intnPages);
147147
staticvoidpack_existing_pages(FSMPageData*newLocation,intnewPages,
148148
FSMPageData*oldLocation,intoldPages);
149149
staticintfsm_calc_request(FSMRelation*fsmrel);
@@ -375,7 +375,7 @@ void
375375
RecordRelationFreeSpace(RelFileNode*rel,
376376
BlockNumberinterestingPages,
377377
intnPages,
378-
PageFreeSpaceInfo*pageSpaces)
378+
FSMPageData*pageSpaces)
379379
{
380380
FSMRelation*fsmrel;
381381

@@ -415,14 +415,12 @@ RecordRelationFreeSpace(RelFileNode *rel,
415415

416416
for (i=0;i<nPages;i++)
417417
{
418-
BlockNumberpage=pageSpaces[i].blkno;
419-
Sizeavail=pageSpaces[i].avail;
418+
BlockNumberpage=FSMPageGetPageNum(&pageSpaces[i]);
420419

421420
/* Check caller provides sorted data */
422-
if (i>0&&page <=pageSpaces[i-1].blkno)
421+
if (i>0&&page <=FSMPageGetPageNum(&pageSpaces[i-1]))
423422
elog(ERROR,"free-space data is not in page order");
424-
FSMPageSetPageNum(newLocation,page);
425-
FSMPageSetSpace(newLocation,avail);
423+
*newLocation=pageSpaces[i];
426424
newLocation++;
427425
}
428426
fsmrel->storedPages=nPages;
@@ -1534,7 +1532,7 @@ push_fsm_rels_after(FSMRelation *afterRel)
15341532

15351533
staticvoid
15361534
pack_incoming_pages(FSMPageData*newLocation,intnewPages,
1537-
PageFreeSpaceInfo*pageSpaces,intnPages)
1535+
FSMPageData*pageSpaces,intnPages)
15381536
{
15391537
inthistogram[HISTOGRAM_BINS];
15401538
intabove,
@@ -1548,7 +1546,7 @@ pack_incoming_pages(FSMPageData *newLocation, int newPages,
15481546
MemSet(histogram,0,sizeof(histogram));
15491547
for (i=0;i<nPages;i++)
15501548
{
1551-
Sizeavail=pageSpaces[i].avail;
1549+
Sizeavail=FSMPageGetSpace(&pageSpaces[i]);
15521550

15531551
if (avail >=BLCKSZ)
15541552
elog(ERROR,"bogus freespace amount");
@@ -1572,18 +1570,17 @@ pack_incoming_pages(FSMPageData *newLocation, int newPages,
15721570
/* And copy the appropriate data */
15731571
for (i=0;i<nPages;i++)
15741572
{
1575-
BlockNumberpage=pageSpaces[i].blkno;
1576-
Sizeavail=pageSpaces[i].avail;
1573+
BlockNumberpage=FSMPageGetPageNum(&pageSpaces[i]);
1574+
Sizeavail=FSMPageGetSpace(&pageSpaces[i]);
15771575

15781576
/* Check caller provides sorted data */
1579-
if (i>0&&page <=pageSpaces[i-1].blkno)
1577+
if (i>0&&page <=FSMPageGetPageNum(&pageSpaces[i-1]))
15801578
elog(ERROR,"free-space data is not in page order");
15811579
/* Save this page? */
15821580
if (avail >=thresholdU||
15831581
(avail >=thresholdL&& (--binct >=0)))
15841582
{
1585-
FSMPageSetPageNum(newLocation,page);
1586-
FSMPageSetSpace(newLocation,avail);
1583+
*newLocation=pageSpaces[i];
15871584
newLocation++;
15881585
newPages--;
15891586
}

‎src/include/storage/freespace.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/storage/freespace.h,v 1.27 2008/01/01 19:45:59 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/storage/freespace.h,v 1.28 2008/03/10 02:04:10 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -18,16 +18,6 @@
1818
#include"storage/itemptr.h"
1919

2020

21-
/*
22-
* exported types
23-
*/
24-
typedefstructPageFreeSpaceInfo
25-
{
26-
BlockNumberblkno;/* which page in relation */
27-
Sizeavail;/* space available on this page */
28-
}PageFreeSpaceInfo;
29-
30-
3121
/* Initial value for average-request moving average */
3222
#defineINITIAL_AVERAGE ((Size) (BLCKSZ / 32))
3323

@@ -144,7 +134,7 @@ extern Size GetAvgFSMRequestSize(RelFileNode *rel);
144134
externvoidRecordRelationFreeSpace(RelFileNode*rel,
145135
BlockNumberinterestingPages,
146136
intnPages,
147-
PageFreeSpaceInfo*pageSpaces);
137+
FSMPageData*pageSpaces);
148138

149139
externBlockNumberGetFreeIndexPage(RelFileNode*rel);
150140
externvoidRecordIndexFreeSpace(RelFileNode*rel,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp