Commit 9e936693 authored by Tom Lane's avatar Tom Lane

Fix free space map to correctly track the total amount of FSM space needed

even when a single relation requires more than max_fsm_pages pages.  Also,
make VACUUM emit a warning in this case, since it likely means that VACUUM
FULL or other drastic corrective measure is needed.  Per reports from Jeff
Frost and others of unexpected changes in the claimed max_fsm_pages need.
parent b0d64a09
...@@ -37,13 +37,13 @@ Notes ...@@ -37,13 +37,13 @@ Notes
pg_freespacemap_relations pg_freespacemap_relations
Column | references | Description Column | references | Description
----------------+----------------------+------------------------------------ ------------------+----------------------+----------------------------------
reltablespace | pg_tablespace.oid | Tablespace oid of the relation. reltablespace | pg_tablespace.oid | Tablespace oid of the relation.
reldatabase | pg_database.oid | Database oid of the relation. reldatabase | pg_database.oid | Database oid of the relation.
relfilenode | pg_class.relfilenode | Relfilenode of the relation. relfilenode | pg_class.relfilenode | Relfilenode of the relation.
avgrequest | | Moving average of free space avgrequest | | Moving average of free space
| | requests (NULL for indexes) | | requests (NULL for indexes)
lastpagecount | | Count of pages last reported as interestingpages | | Count of pages last reported as
| | containing useful free space. | | containing useful free space.
storedpages | | Count of pages actually stored storedpages | | Count of pages actually stored
| | in free space map. | | in free space map.
...@@ -65,11 +65,11 @@ Notes ...@@ -65,11 +65,11 @@ Notes
For pg_freespacemap_relations, there is one row for each relation in the free For pg_freespacemap_relations, there is one row for each relation in the free
space map. storedpages is the number of pages actually stored in the map, space map. storedpages is the number of pages actually stored in the map,
while lastpagecount is the number of pages VACUUM last tried to store while interestingpages is the number of pages the last VACUUM thought had
(ie, the number that VACUUM thought had useful amounts of free space). useful amounts of free space.
If storedpages is consistently less than lastpagecount then it'd be a good If storedpages is consistently less than interestingpages then it'd be a
idea to increase max_fsm_pages. Also, if the number of rows in good idea to increase max_fsm_pages. Also, if the number of rows in
pg_freespacemap_relations is close to max_fsm_relations, then you should pg_freespacemap_relations is close to max_fsm_relations, then you should
consider increasing max_fsm_relations. consider increasing max_fsm_relations.
...@@ -97,25 +97,25 @@ Sample output - pg_freespacemap_relations ...@@ -97,25 +97,25 @@ Sample output - pg_freespacemap_relations
regression=# \d pg_freespacemap_relations regression=# \d pg_freespacemap_relations
View "public.pg_freespacemap_relations" View "public.pg_freespacemap_relations"
Column | Type | Modifiers Column | Type | Modifiers
---------------+---------+----------- ------------------+---------+-----------
reltablespace | oid | reltablespace | oid |
reldatabase | oid | reldatabase | oid |
relfilenode | oid | relfilenode | oid |
avgrequest | integer | avgrequest | integer |
lastpagecount | integer | interestingpages | integer |
storedpages | integer | storedpages | integer |
nextpage | integer | nextpage | integer |
View definition: View definition:
SELECT p.reltablespace, p.reldatabase, p.relfilenode, p.avgrequest, p.lastpagecount, p.storedpages, p.nextpage SELECT p.reltablespace, p.reldatabase, p.relfilenode, p.avgrequest, p.interestingpages, p.storedpages, p.nextpage
FROM pg_freespacemap_relations() p(reltablespace oid, reldatabase oid, relfilenode oid, avgrequest integer, lastpagecount integer, storedpages integer, nextpage integer); FROM pg_freespacemap_relations() p(reltablespace oid, reldatabase oid, relfilenode oid, avgrequest integer, interestingpages integer, storedpages integer, nextpage integer);
regression=# SELECT c.relname, r.avgrequest, r.lastpagecount, r.storedpages regression=# SELECT c.relname, r.avgrequest, r.interestingpages, r.storedpages
FROM pg_freespacemap_relations r INNER JOIN pg_class c FROM pg_freespacemap_relations r INNER JOIN pg_class c
ON c.relfilenode = r.relfilenode INNER JOIN pg_database d ON c.relfilenode = r.relfilenode INNER JOIN pg_database d
ON r.reldatabase = d.oid AND (d.datname = current_database()) ON r.reldatabase = d.oid AND (d.datname = current_database())
ORDER BY r.storedpages DESC LIMIT 10; ORDER BY r.storedpages DESC LIMIT 10;
relname | avgrequest | lastpagecount | storedpages relname | avgrequest | interestingpages | storedpages
---------------------------------+------------+---------------+------------- ---------------------------------+------------+------------------+-------------
onek | 256 | 109 | 109 onek | 256 | 109 | 109
pg_attribute | 167 | 93 | 93 pg_attribute | 167 | 93 | 93
pg_class | 191 | 49 | 49 pg_class | 191 | 49 | 49
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* pg_freespacemap.c * pg_freespacemap.c
* display some contents of the free space relation and page maps. * display some contents of the free space relation and page maps.
* *
* $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v 1.6 2006/05/30 22:12:13 tgl Exp $ * $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v 1.7 2006/09/21 20:31:21 tgl Exp $
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -53,7 +53,7 @@ typedef struct ...@@ -53,7 +53,7 @@ typedef struct
Oid reldatabase; Oid reldatabase;
Oid relfilenode; Oid relfilenode;
Size avgrequest; Size avgrequest;
int lastpagecount; BlockNumber interestingpages;
int storedpages; int storedpages;
int nextpage; int nextpage;
bool isindex; bool isindex;
...@@ -303,7 +303,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS) ...@@ -303,7 +303,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS)
OIDOID, -1, 0); OIDOID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 4, "avgrequest", TupleDescInitEntry(tupledesc, (AttrNumber) 4, "avgrequest",
INT4OID, -1, 0); INT4OID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 5, "lastpagecount", TupleDescInitEntry(tupledesc, (AttrNumber) 5, "interestingpages",
INT4OID, -1, 0); INT4OID, -1, 0);
TupleDescInitEntry(tupledesc, (AttrNumber) 6, "storedpages", TupleDescInitEntry(tupledesc, (AttrNumber) 6, "storedpages",
INT4OID, -1, 0); INT4OID, -1, 0);
...@@ -334,7 +334,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS) ...@@ -334,7 +334,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS)
fctx->record[i].reldatabase = fsmrel->key.dbNode; fctx->record[i].reldatabase = fsmrel->key.dbNode;
fctx->record[i].relfilenode = fsmrel->key.relNode; fctx->record[i].relfilenode = fsmrel->key.relNode;
fctx->record[i].avgrequest = (int64)fsmrel->avgRequest; fctx->record[i].avgrequest = (int64)fsmrel->avgRequest;
fctx->record[i].lastpagecount = fsmrel->lastPageCount; fctx->record[i].interestingpages = fsmrel->interestingPages;
fctx->record[i].storedpages = fsmrel->storedPages; fctx->record[i].storedpages = fsmrel->storedPages;
fctx->record[i].nextpage = fsmrel->nextPage; fctx->record[i].nextpage = fsmrel->nextPage;
fctx->record[i].isindex = fsmrel->isIndex; fctx->record[i].isindex = fsmrel->isIndex;
...@@ -380,7 +380,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS) ...@@ -380,7 +380,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS)
values[3] = UInt32GetDatum(record->avgrequest); values[3] = UInt32GetDatum(record->avgrequest);
nulls[3] = false; nulls[3] = false;
} }
values[4] = Int32GetDatum(record->lastpagecount); values[4] = Int32GetDatum(record->interestingpages);
nulls[4] = false; nulls[4] = false;
values[5] = Int32GetDatum(record->storedpages); values[5] = Int32GetDatum(record->storedpages);
nulls[5] = false; nulls[5] = false;
......
...@@ -30,7 +30,7 @@ CREATE VIEW pg_freespacemap_relations AS ...@@ -30,7 +30,7 @@ CREATE VIEW pg_freespacemap_relations AS
reldatabase oid, reldatabase oid,
relfilenode oid, relfilenode oid,
avgrequest integer, avgrequest integer,
lastpagecount integer, interestingpages integer,
storedpages integer, storedpages integer,
nextpage integer); nextpage integer);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gin/ginvacuum.c,v 1.5 2006/07/31 20:08:59 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/gin/ginvacuum.c,v 1.6 2006/09/21 20:31:21 tgl Exp $
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -575,7 +575,8 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) { ...@@ -575,7 +575,8 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) {
bool needLock; bool needLock;
BlockNumber npages, BlockNumber npages,
blkno; blkno;
BlockNumber nFreePages, BlockNumber totFreePages,
nFreePages,
*freePages, *freePages,
maxFreePages; maxFreePages;
BlockNumber lastBlock = GIN_ROOT_BLKNO, BlockNumber lastBlock = GIN_ROOT_BLKNO,
...@@ -610,7 +611,7 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) { ...@@ -610,7 +611,7 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) {
if (maxFreePages > MaxFSMPages) if (maxFreePages > MaxFSMPages)
maxFreePages = MaxFSMPages; maxFreePages = MaxFSMPages;
nFreePages = 0; totFreePages = nFreePages = 0;
freePages = (BlockNumber *) palloc(sizeof(BlockNumber) * maxFreePages); freePages = (BlockNumber *) palloc(sizeof(BlockNumber) * maxFreePages);
for (blkno = GIN_ROOT_BLKNO + 1; blkno < npages; blkno++) { for (blkno = GIN_ROOT_BLKNO + 1; blkno < npages; blkno++) {
...@@ -626,6 +627,7 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) { ...@@ -626,6 +627,7 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) {
if ( GinPageIsDeleted(page) ) { if ( GinPageIsDeleted(page) ) {
if (nFreePages < maxFreePages) if (nFreePages < maxFreePages)
freePages[nFreePages++] = blkno; freePages[nFreePages++] = blkno;
totFreePages++;
} else } else
lastFilledBlock = blkno; lastFilledBlock = blkno;
...@@ -638,7 +640,7 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) { ...@@ -638,7 +640,7 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) {
int i; int i;
for (i = 0; i < nFreePages; i++) for (i = 0; i < nFreePages; i++)
if (freePages[i] >= lastFilledBlock) { if (freePages[i] >= lastFilledBlock) {
nFreePages = i; totFreePages = nFreePages = i;
break; break;
} }
...@@ -648,8 +650,8 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) { ...@@ -648,8 +650,8 @@ ginvacuumcleanup(PG_FUNCTION_ARGS) {
stats->pages_removed = lastBlock - lastFilledBlock; stats->pages_removed = lastBlock - lastFilledBlock;
} }
RecordIndexFreeSpace(&index->rd_node, nFreePages, freePages); RecordIndexFreeSpace(&index->rd_node, totFreePages, nFreePages, freePages);
stats->pages_free = nFreePages; stats->pages_free = totFreePages;
if (needLock) if (needLock)
LockRelationForExtension(index, ExclusiveLock); LockRelationForExtension(index, ExclusiveLock);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.26 2006/07/31 20:08:59 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.27 2006/09/21 20:31:21 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -491,7 +491,8 @@ gistvacuumcleanup(PG_FUNCTION_ARGS) ...@@ -491,7 +491,8 @@ gistvacuumcleanup(PG_FUNCTION_ARGS)
Relation rel = info->index; Relation rel = info->index;
BlockNumber npages, BlockNumber npages,
blkno; blkno;
BlockNumber nFreePages, BlockNumber totFreePages,
nFreePages,
*freePages, *freePages,
maxFreePages; maxFreePages;
BlockNumber lastBlock = GIST_ROOT_BLKNO, BlockNumber lastBlock = GIST_ROOT_BLKNO,
...@@ -563,8 +564,9 @@ gistvacuumcleanup(PG_FUNCTION_ARGS) ...@@ -563,8 +564,9 @@ gistvacuumcleanup(PG_FUNCTION_ARGS)
if (maxFreePages > MaxFSMPages) if (maxFreePages > MaxFSMPages)
maxFreePages = MaxFSMPages; maxFreePages = MaxFSMPages;
nFreePages = 0; totFreePages = nFreePages = 0;
freePages = (BlockNumber *) palloc(sizeof(BlockNumber) * maxFreePages); freePages = (BlockNumber *) palloc(sizeof(BlockNumber) * maxFreePages);
for (blkno = GIST_ROOT_BLKNO + 1; blkno < npages; blkno++) for (blkno = GIST_ROOT_BLKNO + 1; blkno < npages; blkno++)
{ {
Buffer buffer; Buffer buffer;
...@@ -579,10 +581,8 @@ gistvacuumcleanup(PG_FUNCTION_ARGS) ...@@ -579,10 +581,8 @@ gistvacuumcleanup(PG_FUNCTION_ARGS)
if (PageIsNew(page) || GistPageIsDeleted(page)) if (PageIsNew(page) || GistPageIsDeleted(page))
{ {
if (nFreePages < maxFreePages) if (nFreePages < maxFreePages)
{ freePages[nFreePages++] = blkno;
freePages[nFreePages] = blkno; totFreePages++;
nFreePages++;
}
} }
else else
lastFilledBlock = blkno; lastFilledBlock = blkno;
...@@ -597,7 +597,7 @@ gistvacuumcleanup(PG_FUNCTION_ARGS) ...@@ -597,7 +597,7 @@ gistvacuumcleanup(PG_FUNCTION_ARGS)
for (i = 0; i < nFreePages; i++) for (i = 0; i < nFreePages; i++)
if (freePages[i] >= lastFilledBlock) if (freePages[i] >= lastFilledBlock)
{ {
nFreePages = i; totFreePages = nFreePages = i;
break; break;
} }
...@@ -606,11 +606,11 @@ gistvacuumcleanup(PG_FUNCTION_ARGS) ...@@ -606,11 +606,11 @@ gistvacuumcleanup(PG_FUNCTION_ARGS)
stats->std.pages_removed = lastBlock - lastFilledBlock; stats->std.pages_removed = lastBlock - lastFilledBlock;
} }
RecordIndexFreeSpace(&rel->rd_node, nFreePages, freePages); RecordIndexFreeSpace(&rel->rd_node, totFreePages, nFreePages, freePages);
pfree(freePages); pfree(freePages);
/* return statistics */ /* return statistics */
stats->std.pages_free = nFreePages; stats->std.pages_free = totFreePages;
if (needLock) if (needLock)
LockRelationForExtension(rel, ExclusiveLock); LockRelationForExtension(rel, ExclusiveLock);
stats->std.num_pages = RelationGetNumberOfBlocks(rel); stats->std.num_pages = RelationGetNumberOfBlocks(rel);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.150 2006/08/24 01:18:34 tgl Exp $ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.151 2006/09/21 20:31:22 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -53,8 +53,9 @@ typedef struct ...@@ -53,8 +53,9 @@ typedef struct
void *callback_state; void *callback_state;
BTCycleId cycleid; BTCycleId cycleid;
BlockNumber *freePages; BlockNumber *freePages;
int nFreePages; int nFreePages; /* number of entries in freePages[] */
int maxFreePages; int maxFreePages; /* allocated size of freePages[] */
BlockNumber totFreePages; /* true total # of free pages */
MemoryContext pagedelcontext; MemoryContext pagedelcontext;
} BTVacState; } BTVacState;
...@@ -636,6 +637,7 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, ...@@ -636,6 +637,7 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
vstate.freePages = NULL; /* temporarily */ vstate.freePages = NULL; /* temporarily */
vstate.nFreePages = 0; vstate.nFreePages = 0;
vstate.maxFreePages = 0; vstate.maxFreePages = 0;
vstate.totFreePages = 0;
/* Create a temporary memory context to run _bt_pagedel in */ /* Create a temporary memory context to run _bt_pagedel in */
vstate.pagedelcontext = AllocSetContextCreate(CurrentMemoryContext, vstate.pagedelcontext = AllocSetContextCreate(CurrentMemoryContext,
...@@ -716,6 +718,7 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, ...@@ -716,6 +718,7 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
new_pages--; new_pages--;
stats->pages_deleted--; stats->pages_deleted--;
vstate.nFreePages--; vstate.nFreePages--;
vstate.totFreePages = vstate.nFreePages; /* can't be more */
} }
if (new_pages != num_pages) if (new_pages != num_pages)
{ {
...@@ -736,7 +739,8 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, ...@@ -736,7 +739,8 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
* pages in the index, discarding any old info the map may have. We do not * pages in the index, discarding any old info the map may have. We do not
* need to sort the page numbers; they're in order already. * need to sort the page numbers; they're in order already.
*/ */
RecordIndexFreeSpace(&rel->rd_node, vstate.nFreePages, vstate.freePages); RecordIndexFreeSpace(&rel->rd_node, vstate.totFreePages,
vstate.nFreePages, vstate.freePages);
pfree(vstate.freePages); pfree(vstate.freePages);
...@@ -744,7 +748,7 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, ...@@ -744,7 +748,7 @@ btvacuumscan(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
/* update statistics */ /* update statistics */
stats->num_pages = num_pages; stats->num_pages = num_pages;
stats->pages_free = vstate.nFreePages; stats->pages_free = vstate.totFreePages;
} }
/* /*
...@@ -816,6 +820,7 @@ restart: ...@@ -816,6 +820,7 @@ restart:
/* Okay to recycle this page */ /* Okay to recycle this page */
if (vstate->nFreePages < vstate->maxFreePages) if (vstate->nFreePages < vstate->maxFreePages)
vstate->freePages[vstate->nFreePages++] = blkno; vstate->freePages[vstate->nFreePages++] = blkno;
vstate->totFreePages++;
stats->pages_deleted++; stats->pages_deleted++;
} }
else if (P_ISDELETED(opaque)) else if (P_ISDELETED(opaque))
...@@ -954,6 +959,7 @@ restart: ...@@ -954,6 +959,7 @@ restart:
{ {
if (vstate->nFreePages < vstate->maxFreePages) if (vstate->nFreePages < vstate->maxFreePages)
vstate->freePages[vstate->nFreePages++] = blkno; vstate->freePages[vstate->nFreePages++] = blkno;
vstate->totFreePages++;
} }
MemoryContextSwitchTo(oldcontext); MemoryContextSwitchTo(oldcontext);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.339 2006/09/17 22:16:22 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.340 2006/09/21 20:31:22 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -3314,7 +3314,7 @@ vac_update_fsm(Relation onerel, VacPageList fraged_pages, ...@@ -3314,7 +3314,7 @@ vac_update_fsm(Relation onerel, VacPageList fraged_pages,
} }
} }
RecordRelationFreeSpace(&onerel->rd_node, outPages, pageSpaces); RecordRelationFreeSpace(&onerel->rd_node, outPages, outPages, pageSpaces);
pfree(pageSpaces); pfree(pageSpaces);
} }
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.78 2006/09/13 17:47:08 tgl Exp $ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.79 2006/09/21 20:31:22 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -90,6 +90,7 @@ typedef struct LVRelStats ...@@ -90,6 +90,7 @@ typedef struct LVRelStats
int num_free_pages; /* current # of entries */ int num_free_pages; /* current # of entries */
int max_free_pages; /* # slots allocated in array */ int max_free_pages; /* # slots allocated in array */
PageFreeSpaceInfo *free_pages; /* array or heap of blkno/avail */ PageFreeSpaceInfo *free_pages; /* array or heap of blkno/avail */
BlockNumber tot_free_pages; /* total pages with >= threshold space */
} LVRelStats; } LVRelStats;
...@@ -523,12 +524,21 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats, ...@@ -523,12 +524,21 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
tups_vacuumed, num_tuples, nblocks), tups_vacuumed, num_tuples, nblocks),
errdetail("%.0f dead row versions cannot be removed yet.\n" errdetail("%.0f dead row versions cannot be removed yet.\n"
"There were %.0f unused item pointers.\n" "There were %.0f unused item pointers.\n"
"%u pages contain useful free space.\n"
"%u pages are entirely empty.\n" "%u pages are entirely empty.\n"
"%s.", "%s.",
nkeep, nkeep,
nunused, nunused,
vacrelstats->tot_free_pages,
empty_pages, empty_pages,
pg_rusage_show(&ru0)))); pg_rusage_show(&ru0))));
if (vacrelstats->tot_free_pages > MaxFSMPages)
ereport(WARNING,
(errmsg("relation \"%s.%s\" contains more than \"max_fsm_pages\" pages with useful free space",
get_namespace_name(RelationGetNamespace(onerel)),
relname),
errhint("Consider compacting this relation or increasing the configuration parameter \"max_fsm_pages\".")));
} }
...@@ -793,6 +803,14 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats, ...@@ -793,6 +803,14 @@ lazy_truncate_heap(Relation onerel, LVRelStats *vacrelstats,
} }
} }
vacrelstats->num_free_pages = j; vacrelstats->num_free_pages = j;
/*
* If tot_free_pages was more than num_free_pages, we can't tell for sure
* what its correct value is now, because we don't know which of the
* forgotten pages are getting truncated. Conservatively set it equal
* to num_free_pages.
*/
vacrelstats->tot_free_pages = j;
/* We destroyed the heap ordering, so mark array unordered */ /* We destroyed the heap ordering, so mark array unordered */
vacrelstats->fs_is_heap = false; vacrelstats->fs_is_heap = false;
...@@ -960,6 +978,7 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks) ...@@ -960,6 +978,7 @@ lazy_space_alloc(LVRelStats *vacrelstats, BlockNumber relblocks)
vacrelstats->max_free_pages = maxpages; vacrelstats->max_free_pages = maxpages;
vacrelstats->free_pages = (PageFreeSpaceInfo *) vacrelstats->free_pages = (PageFreeSpaceInfo *)
palloc(maxpages * sizeof(PageFreeSpaceInfo)); palloc(maxpages * sizeof(PageFreeSpaceInfo));
vacrelstats->tot_free_pages = 0;
} }
/* /*
...@@ -1009,6 +1028,9 @@ lazy_record_free_space(LVRelStats *vacrelstats, ...@@ -1009,6 +1028,9 @@ lazy_record_free_space(LVRelStats *vacrelstats,
if (avail < vacrelstats->threshold) if (avail < vacrelstats->threshold)
return; return;
/* Count all pages over threshold, even if not enough space in array */
vacrelstats->tot_free_pages++;
/* Copy pointers to local variables for notational simplicity */ /* Copy pointers to local variables for notational simplicity */
pageSpaces = vacrelstats->free_pages; pageSpaces = vacrelstats->free_pages;
n = vacrelstats->max_free_pages; n = vacrelstats->max_free_pages;
...@@ -1138,7 +1160,8 @@ lazy_update_fsm(Relation onerel, LVRelStats *vacrelstats) ...@@ -1138,7 +1160,8 @@ lazy_update_fsm(Relation onerel, LVRelStats *vacrelstats)
qsort(pageSpaces, nPages, sizeof(PageFreeSpaceInfo), qsort(pageSpaces, nPages, sizeof(PageFreeSpaceInfo),
vac_cmp_page_spaces); vac_cmp_page_spaces);
RecordRelationFreeSpace(&onerel->rd_node, nPages, pageSpaces); RecordRelationFreeSpace(&onerel->rd_node, vacrelstats->tot_free_pages,
nPages, pageSpaces);
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.54 2006/07/14 14:52:22 momjian Exp $ * $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.55 2006/09/21 20:31:22 tgl Exp $
* *
* *
* NOTES: * NOTES:
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
* behavior keeps track of which relation is least recently used. * behavior keeps track of which relation is least recently used.
* *
* For each known relation, we track the average request size given to * For each known relation, we track the average request size given to
* GetPageWithFreeSpace() as well as the most recent number of pages given * GetPageWithFreeSpace() as well as the most recent number of pages reported
* to RecordRelationFreeSpace(). The average request size is not directly * to RecordRelationFreeSpace(). The average request size is not directly
* used in this module, but we expect VACUUM to use it to filter out * used in this module, but we expect VACUUM to use it to filter out
* uninteresting amounts of space before calling RecordRelationFreeSpace(). * uninteresting amounts of space before calling RecordRelationFreeSpace().
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
* relfilenode * relfilenode
* isIndex * isIndex
* avgRequest * avgRequest
* lastPageCount * interestingPages
* storedPages * storedPages
* arena data array of storedPages FSMPageData or IndexFSMPageData * arena data array of storedPages FSMPageData or IndexFSMPageData
*---------- *----------
...@@ -111,7 +111,7 @@ typedef struct FsmCacheRelHeader ...@@ -111,7 +111,7 @@ typedef struct FsmCacheRelHeader
RelFileNode key; /* hash key (must be first) */ RelFileNode key; /* hash key (must be first) */
bool isIndex; /* if true, we store only page numbers */ bool isIndex; /* if true, we store only page numbers */
uint32 avgRequest; /* moving average of space requests */ uint32 avgRequest; /* moving average of space requests */
int32 lastPageCount; /* pages passed to RecordRelationFreeSpace */ BlockNumber interestingPages; /* # of pages with useful free space */
int32 storedPages; /* # of pages stored in arena */ int32 storedPages; /* # of pages stored in arena */
} FsmCacheRelHeader; } FsmCacheRelHeader;
...@@ -128,7 +128,8 @@ static void CheckFreeSpaceMapStatistics(int elevel, int numRels, ...@@ -128,7 +128,8 @@ static void CheckFreeSpaceMapStatistics(int elevel, int numRels,
static FSMRelation *lookup_fsm_rel(RelFileNode *rel); static FSMRelation *lookup_fsm_rel(RelFileNode *rel);
static FSMRelation *create_fsm_rel(RelFileNode *rel); static FSMRelation *create_fsm_rel(RelFileNode *rel);
static void delete_fsm_rel(FSMRelation *fsmrel); static void delete_fsm_rel(FSMRelation *fsmrel);
static int realloc_fsm_rel(FSMRelation *fsmrel, int nPages, bool isIndex); static int realloc_fsm_rel(FSMRelation *fsmrel, BlockNumber interestingPages,
bool isIndex);
static void link_fsm_rel_usage(FSMRelation *fsmrel); static void link_fsm_rel_usage(FSMRelation *fsmrel);
static void unlink_fsm_rel_usage(FSMRelation *fsmrel); static void unlink_fsm_rel_usage(FSMRelation *fsmrel);
static void link_fsm_rel_storage(FSMRelation *fsmrel); static void link_fsm_rel_storage(FSMRelation *fsmrel);
...@@ -146,6 +147,7 @@ static void pack_incoming_pages(FSMPageData *newLocation, int newPages, ...@@ -146,6 +147,7 @@ static void pack_incoming_pages(FSMPageData *newLocation, int newPages,
static void pack_existing_pages(FSMPageData *newLocation, int newPages, static void pack_existing_pages(FSMPageData *newLocation, int newPages,
FSMPageData *oldLocation, int oldPages); FSMPageData *oldLocation, int oldPages);
static int fsm_calc_request(FSMRelation *fsmrel); static int fsm_calc_request(FSMRelation *fsmrel);
static int fsm_calc_request_unclamped(FSMRelation *fsmrel);
static int fsm_calc_target_allocation(int myRequest); static int fsm_calc_target_allocation(int myRequest);
static int fsm_current_chunks(FSMRelation *fsmrel); static int fsm_current_chunks(FSMRelation *fsmrel);
static int fsm_current_allocation(FSMRelation *fsmrel); static int fsm_current_allocation(FSMRelation *fsmrel);
...@@ -361,11 +363,17 @@ GetAvgFSMRequestSize(RelFileNode *rel) ...@@ -361,11 +363,17 @@ GetAvgFSMRequestSize(RelFileNode *rel)
* *
* Any pre-existing info about the relation is assumed obsolete and discarded. * Any pre-existing info about the relation is assumed obsolete and discarded.
* *
* interestingPages is the total number of pages in the relation that have
* at least threshold free space; nPages is the number actually reported in
* pageSpaces[] (may be less --- in particular, callers typically clamp their
* space usage to MaxFSMPages).
*
* The given pageSpaces[] array must be sorted in order by blkno. Note that * The given pageSpaces[] array must be sorted in order by blkno. Note that
* the FSM is at liberty to discard some or all of the data. * the FSM is at liberty to discard some or all of the data.
*/ */
void void
RecordRelationFreeSpace(RelFileNode *rel, RecordRelationFreeSpace(RelFileNode *rel,
BlockNumber interestingPages,
int nPages, int nPages,
PageFreeSpaceInfo *pageSpaces) PageFreeSpaceInfo *pageSpaces)
{ {
...@@ -392,7 +400,7 @@ RecordRelationFreeSpace(RelFileNode *rel, ...@@ -392,7 +400,7 @@ RecordRelationFreeSpace(RelFileNode *rel,
int curAllocPages; int curAllocPages;
FSMPageData *newLocation; FSMPageData *newLocation;
curAlloc = realloc_fsm_rel(fsmrel, nPages, false); curAlloc = realloc_fsm_rel(fsmrel, interestingPages, false);
curAllocPages = curAlloc * CHUNKPAGES; curAllocPages = curAlloc * CHUNKPAGES;
/* /*
...@@ -455,6 +463,7 @@ GetFreeIndexPage(RelFileNode *rel) ...@@ -455,6 +463,7 @@ GetFreeIndexPage(RelFileNode *rel)
*/ */
void void
RecordIndexFreeSpace(RelFileNode *rel, RecordIndexFreeSpace(RelFileNode *rel,
BlockNumber interestingPages,
int nPages, int nPages,
BlockNumber *pages) BlockNumber *pages)
{ {
...@@ -481,7 +490,7 @@ RecordIndexFreeSpace(RelFileNode *rel, ...@@ -481,7 +490,7 @@ RecordIndexFreeSpace(RelFileNode *rel,
int i; int i;
IndexFSMPageData *newLocation; IndexFSMPageData *newLocation;
curAlloc = realloc_fsm_rel(fsmrel, nPages, true); curAlloc = realloc_fsm_rel(fsmrel, interestingPages, true);
curAllocPages = curAlloc * INDEXCHUNKPAGES; curAllocPages = curAlloc * INDEXCHUNKPAGES;
/* /*
...@@ -530,7 +539,7 @@ FreeSpaceMapTruncateRel(RelFileNode *rel, BlockNumber nblocks) ...@@ -530,7 +539,7 @@ FreeSpaceMapTruncateRel(RelFileNode *rel, BlockNumber nblocks)
(void) lookup_fsm_page_entry(fsmrel, nblocks, &pageIndex); (void) lookup_fsm_page_entry(fsmrel, nblocks, &pageIndex);
/* Delete all such entries */ /* Delete all such entries */
fsmrel->storedPages = pageIndex; fsmrel->storedPages = pageIndex;
/* XXX should we adjust rel's lastPageCount and sumRequests? */ /* XXX should we adjust rel's interestingPages and sumRequests? */
} }
LWLockRelease(FreeSpaceLock); LWLockRelease(FreeSpaceLock);
} }
...@@ -587,20 +596,24 @@ PrintFreeSpaceMapStatistics(int elevel) ...@@ -587,20 +596,24 @@ PrintFreeSpaceMapStatistics(int elevel)
{ {
FSMRelation *fsmrel; FSMRelation *fsmrel;
int storedPages = 0; int storedPages = 0;
double sumRequests = 0;
int numRels; int numRels;
double sumRequests;
double needed; double needed;
LWLockAcquire(FreeSpaceLock, LW_EXCLUSIVE); LWLockAcquire(FreeSpaceLock, LW_EXCLUSIVE);
/* Count total space used --- tedious, but seems useful */ /*
* Count total space actually used, as well as the unclamped request total
*/
for (fsmrel = FreeSpaceMap->firstRel; for (fsmrel = FreeSpaceMap->firstRel;
fsmrel != NULL; fsmrel != NULL;
fsmrel = fsmrel->nextPhysical) fsmrel = fsmrel->nextPhysical)
{
storedPages += fsmrel->storedPages; storedPages += fsmrel->storedPages;
sumRequests += fsm_calc_request_unclamped(fsmrel);
}
/* Copy other stats before dropping lock */ /* Copy other stats before dropping lock */
numRels = FreeSpaceMap->numRels; numRels = FreeSpaceMap->numRels;
sumRequests = FreeSpaceMap->sumRequests;
LWLockRelease(FreeSpaceLock); LWLockRelease(FreeSpaceLock);
/* Convert stats to actual number of page slots needed */ /* Convert stats to actual number of page slots needed */
...@@ -613,7 +626,8 @@ PrintFreeSpaceMapStatistics(int elevel) ...@@ -613,7 +626,8 @@ PrintFreeSpaceMapStatistics(int elevel)
"%.0f page slots are required to track all free space.\n" "%.0f page slots are required to track all free space.\n"
"Current limits are: %d page slots, %d relations, using %.0f KB.", "Current limits are: %d page slots, %d relations, using %.0f KB.",
Min(needed, MaxFSMPages), Min(needed, MaxFSMPages),
needed, MaxFSMPages, MaxFSMRelations, needed,
MaxFSMPages, MaxFSMRelations,
(double) FreeSpaceShmemSize() / 1024.0))); (double) FreeSpaceShmemSize() / 1024.0)));
CheckFreeSpaceMapStatistics(NOTICE, numRels, needed); CheckFreeSpaceMapStatistics(NOTICE, numRels, needed);
...@@ -687,7 +701,7 @@ DumpFreeSpaceMap(int code, Datum arg) ...@@ -687,7 +701,7 @@ DumpFreeSpaceMap(int code, Datum arg)
relheader.key = fsmrel->key; relheader.key = fsmrel->key;
relheader.isIndex = fsmrel->isIndex; relheader.isIndex = fsmrel->isIndex;
relheader.avgRequest = fsmrel->avgRequest; relheader.avgRequest = fsmrel->avgRequest;
relheader.lastPageCount = fsmrel->lastPageCount; relheader.interestingPages = fsmrel->interestingPages;
relheader.storedPages = fsmrel->storedPages; relheader.storedPages = fsmrel->storedPages;
if (fwrite(&relheader, 1, sizeof(relheader), fp) != sizeof(relheader)) if (fwrite(&relheader, 1, sizeof(relheader), fp) != sizeof(relheader))
goto write_failed; goto write_failed;
...@@ -792,17 +806,12 @@ LoadFreeSpaceMap(void) ...@@ -792,17 +806,12 @@ LoadFreeSpaceMap(void)
if (fread(&relheader, 1, sizeof(relheader), fp) != sizeof(relheader) || if (fread(&relheader, 1, sizeof(relheader), fp) != sizeof(relheader) ||
(relheader.isIndex != false && relheader.isIndex != true) || (relheader.isIndex != false && relheader.isIndex != true) ||
relheader.avgRequest >= BLCKSZ || relheader.avgRequest >= BLCKSZ ||
relheader.lastPageCount < 0 ||
relheader.storedPages < 0) relheader.storedPages < 0)
{ {
elog(LOG, "bogus rel header in \"%s\"", FSM_CACHE_FILENAME); elog(LOG, "bogus rel header in \"%s\"", FSM_CACHE_FILENAME);
goto read_failed; goto read_failed;
} }
/* Make sure lastPageCount doesn't exceed current MaxFSMPages */
if (relheader.lastPageCount > MaxFSMPages)
relheader.lastPageCount = MaxFSMPages;
/* Read the per-page data */ /* Read the per-page data */
nPages = relheader.storedPages; nPages = relheader.storedPages;
if (relheader.isIndex) if (relheader.isIndex)
...@@ -827,7 +836,7 @@ LoadFreeSpaceMap(void) ...@@ -827,7 +836,7 @@ LoadFreeSpaceMap(void)
fsmrel = create_fsm_rel(&relheader.key); fsmrel = create_fsm_rel(&relheader.key);
fsmrel->avgRequest = relheader.avgRequest; fsmrel->avgRequest = relheader.avgRequest;
curAlloc = realloc_fsm_rel(fsmrel, relheader.lastPageCount, curAlloc = realloc_fsm_rel(fsmrel, relheader.interestingPages,
relheader.isIndex); relheader.isIndex);
if (relheader.isIndex) if (relheader.isIndex)
{ {
...@@ -932,7 +941,7 @@ create_fsm_rel(RelFileNode *rel) ...@@ -932,7 +941,7 @@ create_fsm_rel(RelFileNode *rel)
/* New hashtable entry, initialize it (hash_search set the key) */ /* New hashtable entry, initialize it (hash_search set the key) */
fsmrel->isIndex = false; /* until we learn different */ fsmrel->isIndex = false; /* until we learn different */
fsmrel->avgRequest = INITIAL_AVERAGE; fsmrel->avgRequest = INITIAL_AVERAGE;
fsmrel->lastPageCount = 0; fsmrel->interestingPages = 0;
fsmrel->firstChunk = -1; /* no space allocated */ fsmrel->firstChunk = -1; /* no space allocated */
fsmrel->storedPages = 0; fsmrel->storedPages = 0;
fsmrel->nextPage = 0; fsmrel->nextPage = 0;
...@@ -988,7 +997,8 @@ delete_fsm_rel(FSMRelation *fsmrel) ...@@ -988,7 +997,8 @@ delete_fsm_rel(FSMRelation *fsmrel)
* The return value is the actual new allocation, in chunks. * The return value is the actual new allocation, in chunks.
*/ */
static int static int
realloc_fsm_rel(FSMRelation *fsmrel, int nPages, bool isIndex) realloc_fsm_rel(FSMRelation *fsmrel, BlockNumber interestingPages,
bool isIndex)
{ {
int myRequest; int myRequest;
int myAlloc; int myAlloc;
...@@ -999,7 +1009,7 @@ realloc_fsm_rel(FSMRelation *fsmrel, int nPages, bool isIndex) ...@@ -999,7 +1009,7 @@ realloc_fsm_rel(FSMRelation *fsmrel, int nPages, bool isIndex)
*/ */
fsmrel->storedPages = 0; fsmrel->storedPages = 0;
FreeSpaceMap->sumRequests -= fsm_calc_request(fsmrel); FreeSpaceMap->sumRequests -= fsm_calc_request(fsmrel);
fsmrel->lastPageCount = nPages; fsmrel->interestingPages = interestingPages;
fsmrel->isIndex = isIndex; fsmrel->isIndex = isIndex;
myRequest = fsm_calc_request(fsmrel); myRequest = fsm_calc_request(fsmrel);
FreeSpaceMap->sumRequests += myRequest; FreeSpaceMap->sumRequests += myRequest;
...@@ -1012,7 +1022,7 @@ realloc_fsm_rel(FSMRelation *fsmrel, int nPages, bool isIndex) ...@@ -1012,7 +1022,7 @@ realloc_fsm_rel(FSMRelation *fsmrel, int nPages, bool isIndex)
* new data in-place. * new data in-place.
*/ */
curAlloc = fsm_current_allocation(fsmrel); curAlloc = fsm_current_allocation(fsmrel);
if (myAlloc > curAlloc && (myRequest + 1) > curAlloc && nPages > 0) if (myAlloc > curAlloc && (myRequest + 1) > curAlloc && interestingPages > 0)
{ {
/* Remove entry from storage list, and compact */ /* Remove entry from storage list, and compact */
unlink_fsm_rel_storage(fsmrel); unlink_fsm_rel_storage(fsmrel);
...@@ -1649,27 +1659,70 @@ pack_existing_pages(FSMPageData *newLocation, int newPages, ...@@ -1649,27 +1659,70 @@ pack_existing_pages(FSMPageData *newLocation, int newPages,
} }
/* /*
* Calculate number of chunks "requested" by a rel. * Calculate number of chunks "requested" by a rel. The "request" is
* anything beyond the rel's one guaranteed chunk.
* *
* Rel's lastPageCount and isIndex settings must be up-to-date when called. * Rel's interestingPages and isIndex settings must be up-to-date when called.
* *
* See notes at top of file for details. * See notes at top of file for details.
*/ */
static int static int
fsm_calc_request(FSMRelation *fsmrel) fsm_calc_request(FSMRelation *fsmrel)
{ {
int chunkCount; int req;
/* Convert page count to chunk count */ /* Convert page count to chunk count */
if (fsmrel->isIndex) if (fsmrel->isIndex)
chunkCount = (fsmrel->lastPageCount - 1) / INDEXCHUNKPAGES + 1; {
/* test to avoid unsigned underflow at zero */
if (fsmrel->interestingPages <= INDEXCHUNKPAGES)
return 0;
/* quotient will fit in int, even if interestingPages doesn't */
req = (fsmrel->interestingPages - 1) / INDEXCHUNKPAGES;
}
else else
chunkCount = (fsmrel->lastPageCount - 1) / CHUNKPAGES + 1; {
/* "Request" is anything beyond our one guaranteed chunk */ if (fsmrel->interestingPages <= CHUNKPAGES)
if (chunkCount <= 0) return 0;
req = (fsmrel->interestingPages - 1) / CHUNKPAGES;
}
/*
* We clamp the per-relation requests to at most half the arena size;
* this is intended to prevent a single bloated relation from crowding
* out FSM service for every other rel.
*/
req = Min(req, FreeSpaceMap->totalChunks / 2);
return req;
}
/*
* Same as above, but without the clamp ... this is just intended for
* reporting the total space needed to store all information.
*/
static int
fsm_calc_request_unclamped(FSMRelation *fsmrel)
{
int req;
/* Convert page count to chunk count */
if (fsmrel->isIndex)
{
/* test to avoid unsigned underflow at zero */
if (fsmrel->interestingPages <= INDEXCHUNKPAGES)
return 0; return 0;
/* quotient will fit in int, even if interestingPages doesn't */
req = (fsmrel->interestingPages - 1) / INDEXCHUNKPAGES;
}
else else
return chunkCount - 1; {
if (fsmrel->interestingPages <= CHUNKPAGES)
return 0;
req = (fsmrel->interestingPages - 1) / CHUNKPAGES;
}
return req;
} }
/* /*
...@@ -1769,11 +1822,11 @@ DumpFreeSpace(void) ...@@ -1769,11 +1822,11 @@ DumpFreeSpace(void)
for (fsmrel = FreeSpaceMap->usageList; fsmrel; fsmrel = fsmrel->nextUsage) for (fsmrel = FreeSpaceMap->usageList; fsmrel; fsmrel = fsmrel->nextUsage)
{ {
relNum++; relNum++;
fprintf(stderr, "Map %d: rel %u/%u/%u isIndex %d avgRequest %u lastPageCount %d nextPage %d\nMap= ", fprintf(stderr, "Map %d: rel %u/%u/%u isIndex %d avgRequest %u interestingPages %u nextPage %d\nMap= ",
relNum, relNum,
fsmrel->key.spcNode, fsmrel->key.dbNode, fsmrel->key.relNode, fsmrel->key.spcNode, fsmrel->key.dbNode, fsmrel->key.relNode,
(int) fsmrel->isIndex, fsmrel->avgRequest, (int) fsmrel->isIndex, fsmrel->avgRequest,
fsmrel->lastPageCount, fsmrel->nextPage); fsmrel->interestingPages, fsmrel->nextPage);
if (fsmrel->isIndex) if (fsmrel->isIndex)
{ {
IndexFSMPageData *page; IndexFSMPageData *page;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/storage/freespace.h,v 1.21 2006/07/13 16:49:20 momjian Exp $ * $PostgreSQL: pgsql/src/include/storage/freespace.h,v 1.22 2006/09/21 20:31:22 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -115,7 +115,7 @@ struct FSMRelation ...@@ -115,7 +115,7 @@ struct FSMRelation
FSMRelation *priorPhysical; /* prior rel in arena-storage order */ FSMRelation *priorPhysical; /* prior rel in arena-storage order */
bool isIndex; /* if true, we store only page numbers */ bool isIndex; /* if true, we store only page numbers */
Size avgRequest; /* moving average of space requests */ Size avgRequest; /* moving average of space requests */
int lastPageCount; /* pages passed to RecordRelationFreeSpace */ BlockNumber interestingPages; /* # of pages with useful free space */
int firstChunk; /* chunk # of my first chunk in arena */ int firstChunk; /* chunk # of my first chunk in arena */
int storedPages; /* # of pages stored in arena */ int storedPages; /* # of pages stored in arena */
int nextPage; /* index (from 0) to start next search at */ int nextPage; /* index (from 0) to start next search at */
...@@ -133,6 +133,7 @@ extern int MaxFSMPages; ...@@ -133,6 +133,7 @@ extern int MaxFSMPages;
*/ */
extern void InitFreeSpaceMap(void); extern void InitFreeSpaceMap(void);
extern Size FreeSpaceShmemSize(void); extern Size FreeSpaceShmemSize(void);
extern FSMHeader *GetFreeSpaceMap(void);
extern BlockNumber GetPageWithFreeSpace(RelFileNode *rel, Size spaceNeeded); extern BlockNumber GetPageWithFreeSpace(RelFileNode *rel, Size spaceNeeded);
extern BlockNumber RecordAndGetPageWithFreeSpace(RelFileNode *rel, extern BlockNumber RecordAndGetPageWithFreeSpace(RelFileNode *rel,
...@@ -141,11 +142,13 @@ extern BlockNumber RecordAndGetPageWithFreeSpace(RelFileNode *rel, ...@@ -141,11 +142,13 @@ extern BlockNumber RecordAndGetPageWithFreeSpace(RelFileNode *rel,
Size spaceNeeded); Size spaceNeeded);
extern Size GetAvgFSMRequestSize(RelFileNode *rel); extern Size GetAvgFSMRequestSize(RelFileNode *rel);
extern void RecordRelationFreeSpace(RelFileNode *rel, extern void RecordRelationFreeSpace(RelFileNode *rel,
BlockNumber interestingPages,
int nPages, int nPages,
PageFreeSpaceInfo *pageSpaces); PageFreeSpaceInfo *pageSpaces);
extern BlockNumber GetFreeIndexPage(RelFileNode *rel); extern BlockNumber GetFreeIndexPage(RelFileNode *rel);
extern void RecordIndexFreeSpace(RelFileNode *rel, extern void RecordIndexFreeSpace(RelFileNode *rel,
BlockNumber interestingPages,
int nPages, int nPages,
BlockNumber *pages); BlockNumber *pages);
...@@ -157,7 +160,6 @@ extern void PrintFreeSpaceMapStatistics(int elevel); ...@@ -157,7 +160,6 @@ extern void PrintFreeSpaceMapStatistics(int elevel);
extern void DumpFreeSpaceMap(int code, Datum arg); extern void DumpFreeSpaceMap(int code, Datum arg);
extern void LoadFreeSpaceMap(void); extern void LoadFreeSpaceMap(void);
extern FSMHeader *GetFreeSpaceMap(void);
#ifdef FREESPACE_DEBUG #ifdef FREESPACE_DEBUG
extern void DumpFreeSpace(void); extern void DumpFreeSpace(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment