PostgreSQL Source Code  git master
smgr.h File Reference
#include "lib/ilist.h"
#include "storage/block.h"
#include "storage/relfilelocator.h"
Include dependency graph for smgr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SMgrRelationData
 

Macros

#define SmgrIsTemp(smgr)    RelFileLocatorBackendIsTemp((smgr)->smgr_rlocator)
 

Typedefs

typedef struct SMgrRelationData SMgrRelationData
 
typedef SMgrRelationDataSMgrRelation
 

Functions

void smgrinit (void)
 
SMgrRelation smgropen (RelFileLocator rlocator, BackendId backend)
 
bool smgrexists (SMgrRelation reln, ForkNumber forknum)
 
void smgrpin (SMgrRelation reln)
 
void smgrunpin (SMgrRelation reln)
 
void smgrclose (SMgrRelation reln)
 
void smgrdestroyall (void)
 
void smgrrelease (SMgrRelation reln)
 
void smgrreleaseall (void)
 
void smgrreleaserellocator (RelFileLocatorBackend rlocator)
 
void smgrcreate (SMgrRelation reln, ForkNumber forknum, bool isRedo)
 
void smgrdosyncall (SMgrRelation *rels, int nrels)
 
void smgrdounlinkall (SMgrRelation *rels, int nrels, bool isRedo)
 
void smgrextend (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
 
void smgrzeroextend (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
 
bool smgrprefetch (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks)
 
void smgrreadv (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffer, BlockNumber nblocks)
 
void smgrwritev (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffer, BlockNumber nblocks, bool skipFsync)
 
void smgrwriteback (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
 
BlockNumber smgrnblocks (SMgrRelation reln, ForkNumber forknum)
 
BlockNumber smgrnblocks_cached (SMgrRelation reln, ForkNumber forknum)
 
void smgrtruncate (SMgrRelation reln, ForkNumber *forknum, int nforks, BlockNumber *nblocks)
 
void smgrimmedsync (SMgrRelation reln, ForkNumber forknum)
 
void AtEOXact_SMgr (void)
 
bool ProcessBarrierSmgrRelease (void)
 
static void smgrread (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void *buffer)
 
static void smgrwrite (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
 

Macro Definition Documentation

◆ SmgrIsTemp

#define SmgrIsTemp (   smgr)     RelFileLocatorBackendIsTemp((smgr)->smgr_rlocator)

Definition at line 73 of file smgr.h.

Typedef Documentation

◆ SMgrRelation

Definition at line 71 of file smgr.h.

◆ SMgrRelationData

Function Documentation

◆ AtEOXact_SMgr()

void AtEOXact_SMgr ( void  )

Definition at line 778 of file smgr.c.

779 {
780  smgrdestroyall();
781 }
void smgrdestroyall(void)
Definition: smgr.c:331

References smgrdestroyall().

Referenced by AbortTransaction(), AutoVacLauncherMain(), BackgroundWriterMain(), CheckpointerMain(), CommitTransaction(), PrepareTransaction(), and WalWriterMain().

◆ ProcessBarrierSmgrRelease()

bool ProcessBarrierSmgrRelease ( void  )

Definition at line 788 of file smgr.c.

789 {
790  smgrreleaseall();
791  return true;
792 }
void smgrreleaseall(void)
Definition: smgr.c:354

References smgrreleaseall().

Referenced by ProcessProcSignalBarrier().

◆ smgrclose()

◆ smgrcreate()

void smgrcreate ( SMgrRelation  reln,
ForkNumber  forknum,
bool  isRedo 
)

Definition at line 412 of file smgr.c.

413 {
414  smgrsw[reln->smgr_which].smgr_create(reln, forknum, isRedo);
415 }
static const f_smgr smgrsw[]
Definition: smgr.c:107
int smgr_which
Definition: smgr.h:54
void(* smgr_create)(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:81

References f_smgr::smgr_create, SMgrRelationData::smgr_which, and smgrsw.

Referenced by CreateAndCopyRelationData(), ExtendBufferedRelTo(), fill_seq_with_data(), heapam_relation_copy_data(), heapam_relation_set_new_filelocator(), index_build(), index_copy_data(), RelationCreateStorage(), smgr_redo(), and XLogReadBufferExtended().

◆ smgrdestroyall()

void smgrdestroyall ( void  )

Definition at line 331 of file smgr.c.

332 {
333  dlist_mutable_iter iter;
334 
335  /*
336  * Zap all unpinned SMgrRelations. We rely on smgrdestroy() to remove
337  * each one from the list.
338  */
340  {
342  iter.cur);
343 
344  smgrdestroy(rel);
345  }
346 }
#define dlist_foreach_modify(iter, lhead)
Definition: ilist.h:640
#define dlist_container(type, membername, ptr)
Definition: ilist.h:593
static void smgrdestroy(SMgrRelation reln)
Definition: smgr.c:276
static dlist_head unpinned_relns
Definition: smgr.c:137
dlist_node * cur
Definition: ilist.h:200

References dlist_mutable_iter::cur, dlist_container, dlist_foreach_modify, smgrdestroy(), and unpinned_relns.

Referenced by AtEOXact_SMgr(), BackgroundWriterMain(), CheckpointerMain(), RelationCacheInvalidate(), RequestCheckpoint(), and XLogDropDatabase().

◆ smgrdosyncall()

void smgrdosyncall ( SMgrRelation rels,
int  nrels 
)

Definition at line 427 of file smgr.c.

428 {
429  int i = 0;
430  ForkNumber forknum;
431 
432  if (nrels == 0)
433  return;
434 
435  FlushRelationsAllBuffers(rels, nrels);
436 
437  /*
438  * Sync the physical file(s).
439  */
440  for (i = 0; i < nrels; i++)
441  {
442  int which = rels[i]->smgr_which;
443 
444  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
445  {
446  if (smgrsw[which].smgr_exists(rels[i], forknum))
447  smgrsw[which].smgr_immedsync(rels[i], forknum);
448  }
449  }
450 }
void FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
Definition: bufmgr.c:4244
int i
Definition: isn.c:73
ForkNumber
Definition: relpath.h:48
#define MAX_FORKNUM
Definition: relpath.h:62
void(* smgr_immedsync)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:104

References FlushRelationsAllBuffers(), i, MAX_FORKNUM, f_smgr::smgr_immedsync, SMgrRelationData::smgr_which, and smgrsw.

Referenced by smgrDoPendingSyncs().

◆ smgrdounlinkall()

void smgrdounlinkall ( SMgrRelation rels,
int  nrels,
bool  isRedo 
)

Definition at line 463 of file smgr.c.

464 {
465  int i = 0;
466  RelFileLocatorBackend *rlocators;
467  ForkNumber forknum;
468 
469  if (nrels == 0)
470  return;
471 
472  /*
473  * Get rid of any remaining buffers for the relations. bufmgr will just
474  * drop them without bothering to write the contents.
475  */
476  DropRelationsAllBuffers(rels, nrels);
477 
478  /*
479  * create an array which contains all relations to be dropped, and close
480  * each relation's forks at the smgr level while at it
481  */
482  rlocators = palloc(sizeof(RelFileLocatorBackend) * nrels);
483  for (i = 0; i < nrels; i++)
484  {
485  RelFileLocatorBackend rlocator = rels[i]->smgr_rlocator;
486  int which = rels[i]->smgr_which;
487 
488  rlocators[i] = rlocator;
489 
490  /* Close the forks at smgr level */
491  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
492  smgrsw[which].smgr_close(rels[i], forknum);
493  }
494 
495  /*
496  * Send a shared-inval message to force other backends to close any
497  * dangling smgr references they may have for these rels. We should do
498  * this before starting the actual unlinking, in case we fail partway
499  * through that step. Note that the sinval messages will eventually come
500  * back to this backend, too, and thereby provide a backstop that we
501  * closed our own smgr rel.
502  */
503  for (i = 0; i < nrels; i++)
504  CacheInvalidateSmgr(rlocators[i]);
505 
506  /*
507  * Delete the physical file(s).
508  *
509  * Note: smgr_unlink must treat deletion failure as a WARNING, not an
510  * ERROR, because we've already decided to commit or abort the current
511  * xact.
512  */
513 
514  for (i = 0; i < nrels; i++)
515  {
516  int which = rels[i]->smgr_which;
517 
518  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
519  smgrsw[which].smgr_unlink(rlocators[i], forknum, isRedo);
520  }
521 
522  pfree(rlocators);
523 }
void DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
Definition: bufmgr.c:3808
void CacheInvalidateSmgr(RelFileLocatorBackend rlocator)
Definition: inval.c:1460
void pfree(void *pointer)
Definition: mcxt.c:1431
void * palloc(Size size)
Definition: mcxt.c:1201
RelFileLocatorBackend smgr_rlocator
Definition: smgr.h:37

References CacheInvalidateSmgr(), DropRelationsAllBuffers(), i, MAX_FORKNUM, palloc(), pfree(), SMgrRelationData::smgr_rlocator, SMgrRelationData::smgr_which, and smgrsw.

Referenced by DropRelationFiles(), RelationSetNewRelfilenumber(), and smgrDoPendingDeletes().

◆ smgrexists()

◆ smgrextend()

void smgrextend ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
const void *  buffer,
bool  skipFsync 
)

Definition at line 536 of file smgr.c.

538 {
539  smgrsw[reln->smgr_which].smgr_extend(reln, forknum, blocknum,
540  buffer, skipFsync);
541 
542  /*
543  * Normally we expect this to increase nblocks by one, but if the cached
544  * value isn't as expected, just invalidate it so the next call asks the
545  * kernel.
546  */
547  if (reln->smgr_cached_nblocks[forknum] == blocknum)
548  reln->smgr_cached_nblocks[forknum] = blocknum + 1;
549  else
550  reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
551 }
#define InvalidBlockNumber
Definition: block.h:33
BlockNumber smgr_cached_nblocks[MAX_FORKNUM+1]
Definition: smgr.h:46
void(* smgr_extend)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
Definition: smgr.c:86

References InvalidBlockNumber, SMgrRelationData::smgr_cached_nblocks, f_smgr::smgr_extend, SMgrRelationData::smgr_which, and smgrsw.

Referenced by _bt_blwritepage(), _hash_alloc_buckets(), end_heap_rewrite(), gist_indexsortbuild(), gist_indexsortbuild_flush_ready_pages(), raw_heap_insert(), RelationCopyStorage(), and RelationCopyStorageUsingBuffer().

◆ smgrimmedsync()

void smgrimmedsync ( SMgrRelation  reln,
ForkNumber  forknum 
)

Definition at line 760 of file smgr.c.

761 {
762  smgrsw[reln->smgr_which].smgr_immedsync(reln, forknum);
763 }

References f_smgr::smgr_immedsync, SMgrRelationData::smgr_which, and smgrsw.

Referenced by _bt_load(), end_heap_rewrite(), gist_indexsortbuild(), and RelationCopyStorage().

◆ smgrinit()

void smgrinit ( void  )

Definition at line 153 of file smgr.c.

154 {
155  int i;
156 
157  for (i = 0; i < NSmgr; i++)
158  {
159  if (smgrsw[i].smgr_init)
160  smgrsw[i].smgr_init();
161  }
162 
163  /* register the shutdown proc */
165 }
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:309
static const int NSmgr
Definition: smgr.c:129
static void smgrshutdown(int code, Datum arg)
Definition: smgr.c:171
void(* smgr_init)(void)
Definition: smgr.c:77

References i, NSmgr, on_proc_exit(), f_smgr::smgr_init, smgrshutdown(), and smgrsw.

Referenced by BaseInit().

◆ smgrnblocks()

BlockNumber smgrnblocks ( SMgrRelation  reln,
ForkNumber  forknum 
)

Definition at line 648 of file smgr.c.

649 {
650  BlockNumber result;
651 
652  /* Check and return if we get the cached value for the number of blocks. */
653  result = smgrnblocks_cached(reln, forknum);
654  if (result != InvalidBlockNumber)
655  return result;
656 
657  result = smgrsw[reln->smgr_which].smgr_nblocks(reln, forknum);
658 
659  reln->smgr_cached_nblocks[forknum] = result;
660 
661  return result;
662 }
uint32 BlockNumber
Definition: block.h:31
BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:672
BlockNumber(* smgr_nblocks)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:101

References InvalidBlockNumber, SMgrRelationData::smgr_cached_nblocks, f_smgr::smgr_nblocks, SMgrRelationData::smgr_which, smgrnblocks_cached(), and smgrsw.

Referenced by ExtendBufferedRelLocal(), ExtendBufferedRelShared(), ExtendBufferedRelTo(), FreeSpaceMapPrepareTruncateRel(), fsm_readbuf(), gistBuildCallback(), RelationCopyStorage(), RelationCopyStorageUsingBuffer(), RelationGetNumberOfBlocksInFork(), ScanSourceDatabasePgClass(), smgrDoPendingSyncs(), table_block_relation_size(), visibilitymap_prepare_truncate(), vm_readbuf(), XLogPrefetcherNextBlock(), and XLogReadBufferExtended().

◆ smgrnblocks_cached()

BlockNumber smgrnblocks_cached ( SMgrRelation  reln,
ForkNumber  forknum 
)

Definition at line 672 of file smgr.c.

673 {
674  /*
675  * For now, we only use cached values in recovery due to lack of a shared
676  * invalidation mechanism for changes in file size.
677  */
678  if (InRecovery && reln->smgr_cached_nblocks[forknum] != InvalidBlockNumber)
679  return reln->smgr_cached_nblocks[forknum];
680 
681  return InvalidBlockNumber;
682 }
bool InRecovery
Definition: xlogutils.c:53

References InRecovery, InvalidBlockNumber, and SMgrRelationData::smgr_cached_nblocks.

Referenced by DropRelationBuffers(), DropRelationsAllBuffers(), and smgrnblocks().

◆ smgropen()

SMgrRelation smgropen ( RelFileLocator  rlocator,
BackendId  backend 
)

Definition at line 197 of file smgr.c.

198 {
199  RelFileLocatorBackend brlocator;
200  SMgrRelation reln;
201  bool found;
202 
204 
205  if (SMgrRelationHash == NULL)
206  {
207  /* First time through: initialize the hash table */
208  HASHCTL ctl;
209 
210  ctl.keysize = sizeof(RelFileLocatorBackend);
211  ctl.entrysize = sizeof(SMgrRelationData);
212  SMgrRelationHash = hash_create("smgr relation table", 400,
213  &ctl, HASH_ELEM | HASH_BLOBS);
215  }
216 
217  /* Look up or create an entry */
218  brlocator.locator = rlocator;
219  brlocator.backend = backend;
221  &brlocator,
222  HASH_ENTER, &found);
223 
224  /* Initialize it if not present before */
225  if (!found)
226  {
227  /* hash_search already filled in the lookup key */
229  for (int i = 0; i <= MAX_FORKNUM; ++i)
231  reln->smgr_which = 0; /* we only have md.c at present */
232 
233  /* implementation-specific initialization */
234  smgrsw[reln->smgr_which].smgr_open(reln);
235 
236  /* it is not pinned yet */
237  reln->pincount = 0;
239  }
240 
241  return reln;
242 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:953
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:350
@ HASH_ENTER
Definition: hsearch.h:114
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_BLOBS
Definition: hsearch.h:97
static void dlist_init(dlist_head *head)
Definition: ilist.h:314
static void dlist_push_tail(dlist_head *head, dlist_node *node)
Definition: ilist.h:364
Assert(fmt[strlen(fmt) - 1] !='\n')
struct RelFileLocatorBackend RelFileLocatorBackend
#define RelFileNumberIsValid(relnumber)
Definition: relpath.h:27
static HTAB * SMgrRelationHash
Definition: smgr.c:135
struct SMgrRelationData SMgrRelationData
SMgrRelationData * SMgrRelation
Definition: smgr.h:71
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
RelFileLocator locator
RelFileNumber relNumber
BlockNumber smgr_targblock
Definition: smgr.h:45
dlist_node node
Definition: smgr.h:68
int pincount
Definition: smgr.h:67
void(* smgr_open)(SMgrRelation reln)
Definition: smgr.c:79

References Assert(), RelFileLocatorBackend::backend, dlist_init(), dlist_push_tail(), HASHCTL::entrysize, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), i, InvalidBlockNumber, HASHCTL::keysize, RelFileLocatorBackend::locator, MAX_FORKNUM, SMgrRelationData::node, SMgrRelationData::pincount, RelFileNumberIsValid, RelFileLocator::relNumber, SMgrRelationData::smgr_cached_nblocks, f_smgr::smgr_open, SMgrRelationData::smgr_targblock, SMgrRelationData::smgr_which, SMgrRelationHash, smgrsw, and unpinned_relns.

Referenced by CreateAndCopyRelationData(), CreateFakeRelcacheEntry(), DropRelationFiles(), fill_seq_with_data(), FlushBuffer(), GetLocalVictimBuffer(), IssuePendingWritebacks(), mdsyncfiletag(), ReadBufferWithoutRelcache(), RelationCopyStorageUsingBuffer(), RelationCreateStorage(), RelationGetSmgr(), RelationSetNewRelfilenumber(), ScanSourceDatabasePgClass(), smgr_redo(), smgrDoPendingDeletes(), smgrDoPendingSyncs(), XLogPrefetcherNextBlock(), and XLogReadBufferExtended().

◆ smgrpin()

void smgrpin ( SMgrRelation  reln)

Definition at line 249 of file smgr.c.

250 {
251  if (reln->pincount == 0)
252  dlist_delete(&reln->node);
253  reln->pincount++;
254 }
static void dlist_delete(dlist_node *node)
Definition: ilist.h:405

References dlist_delete(), SMgrRelationData::node, and SMgrRelationData::pincount.

Referenced by RelationGetSmgr().

◆ smgrprefetch()

bool smgrprefetch ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
int  nblocks 
)

Definition at line 586 of file smgr.c.

588 {
589  return smgrsw[reln->smgr_which].smgr_prefetch(reln, forknum, blocknum, nblocks);
590 }
bool(* smgr_prefetch)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks)
Definition: smgr.c:90

References f_smgr::smgr_prefetch, SMgrRelationData::smgr_which, and smgrsw.

Referenced by PrefetchLocalBuffer(), and PrefetchSharedBuffer().

◆ smgrread()

static void smgrread ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
void *  buffer 
)
inlinestatic

Definition at line 113 of file smgr.h.

115 {
116  smgrreadv(reln, forknum, blocknum, &buffer, 1);
117 }
void smgrreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffer, BlockNumber nblocks)
Definition: smgr.c:601

References smgrreadv().

Referenced by pg_prewarm(), ReadBuffer_common(), and RelationCopyStorage().

◆ smgrreadv()

void smgrreadv ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
void **  buffer,
BlockNumber  nblocks 
)

Definition at line 601 of file smgr.c.

603 {
604  smgrsw[reln->smgr_which].smgr_readv(reln, forknum, blocknum, buffers,
605  nblocks);
606 }
void(* smgr_readv)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks)
Definition: smgr.c:92

References f_smgr::smgr_readv, SMgrRelationData::smgr_which, and smgrsw.

Referenced by smgrread().

◆ smgrrelease()

void smgrrelease ( SMgrRelation  reln)

Definition at line 299 of file smgr.c.

300 {
301  for (ForkNumber forknum = 0; forknum <= MAX_FORKNUM; forknum++)
302  {
303  smgrsw[reln->smgr_which].smgr_close(reln, forknum);
304  reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
305  }
307 }
void(* smgr_close)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:80

References InvalidBlockNumber, MAX_FORKNUM, SMgrRelationData::smgr_cached_nblocks, f_smgr::smgr_close, SMgrRelationData::smgr_targblock, SMgrRelationData::smgr_which, and smgrsw.

Referenced by smgrclose(), smgrreleaseall(), and smgrreleaserellocator().

◆ smgrreleaseall()

void smgrreleaseall ( void  )

Definition at line 354 of file smgr.c.

355 {
356  HASH_SEQ_STATUS status;
357  SMgrRelation reln;
358 
359  /* Nothing to do if hashtable not set up */
360  if (SMgrRelationHash == NULL)
361  return;
362 
364 
365  while ((reln = (SMgrRelation) hash_seq_search(&status)) != NULL)
366  {
367  smgrrelease(reln);
368  }
369 }
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1431
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1421

References hash_seq_init(), hash_seq_search(), SMgrRelationHash, and smgrrelease().

Referenced by ProcessBarrierSmgrRelease().

◆ smgrreleaserellocator()

void smgrreleaserellocator ( RelFileLocatorBackend  rlocator)

Definition at line 380 of file smgr.c.

381 {
382  SMgrRelation reln;
383 
384  /* Nothing to do if hashtable not set up */
385  if (SMgrRelationHash == NULL)
386  return;
387 
389  &rlocator,
390  HASH_FIND, NULL);
391  if (reln != NULL)
392  smgrrelease(reln);
393 }
@ HASH_FIND
Definition: hsearch.h:113

References HASH_FIND, hash_search(), SMgrRelationHash, and smgrrelease().

Referenced by LocalExecuteInvalidationMessage().

◆ smgrtruncate()

void smgrtruncate ( SMgrRelation  reln,
ForkNumber forknum,
int  nforks,
BlockNumber nblocks 
)

Definition at line 695 of file smgr.c.

696 {
697  int i;
698 
699  /*
700  * Get rid of any buffers for the about-to-be-deleted blocks. bufmgr will
701  * just drop them without bothering to write the contents.
702  */
703  DropRelationBuffers(reln, forknum, nforks, nblocks);
704 
705  /*
706  * Send a shared-inval message to force other backends to close any smgr
707  * references they may have for this rel. This is useful because they
708  * might have open file pointers to segments that got removed, and/or
709  * smgr_targblock variables pointing past the new rel end. (The inval
710  * message will come back to our backend, too, causing a
711  * probably-unnecessary local smgr flush. But we don't expect that this
712  * is a performance-critical path.) As in the unlink code, we want to be
713  * sure the message is sent before we start changing things on-disk.
714  */
716 
717  /* Do the truncation */
718  for (i = 0; i < nforks; i++)
719  {
720  /* Make the cached size is invalid if we encounter an error. */
721  reln->smgr_cached_nblocks[forknum[i]] = InvalidBlockNumber;
722 
723  smgrsw[reln->smgr_which].smgr_truncate(reln, forknum[i], nblocks[i]);
724 
725  /*
726  * We might as well update the local smgr_cached_nblocks values. The
727  * smgr cache inval message that this function sent will cause other
728  * backends to invalidate their copies of smgr_fsm_nblocks and
729  * smgr_vm_nblocks, and these ones too at the next command boundary.
730  * But these ensure they aren't outright wrong until then.
731  */
732  reln->smgr_cached_nblocks[forknum[i]] = nblocks[i];
733  }
734 }
void DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum, int nforks, BlockNumber *firstDelBlock)
Definition: bufmgr.c:3685
void(* smgr_truncate)(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
Definition: smgr.c:102

References CacheInvalidateSmgr(), DropRelationBuffers(), i, InvalidBlockNumber, SMgrRelationData::smgr_cached_nblocks, SMgrRelationData::smgr_rlocator, f_smgr::smgr_truncate, SMgrRelationData::smgr_which, and smgrsw.

Referenced by pg_truncate_visibility_map(), RelationTruncate(), and smgr_redo().

◆ smgrunpin()

void smgrunpin ( SMgrRelation  reln)

Definition at line 264 of file smgr.c.

265 {
266  Assert(reln->pincount > 0);
267  reln->pincount--;
268  if (reln->pincount == 0)
270 }

References Assert(), dlist_push_tail(), SMgrRelationData::node, SMgrRelationData::pincount, and unpinned_relns.

Referenced by RelationCloseSmgr().

◆ smgrwrite()

static void smgrwrite ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
const void *  buffer,
bool  skipFsync 
)
inlinestatic

Definition at line 120 of file smgr.h.

122 {
123  smgrwritev(reln, forknum, blocknum, &buffer, 1, skipFsync);
124 }
void smgrwritev(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffer, BlockNumber nblocks, bool skipFsync)
Definition: smgr.c:624

References smgrwritev().

Referenced by _bt_blwritepage(), FlushBuffer(), FlushRelationBuffers(), GetLocalVictimBuffer(), and gist_indexsortbuild().

◆ smgrwriteback()

void smgrwriteback ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
BlockNumber  nblocks 
)

Definition at line 636 of file smgr.c.

638 {
639  smgrsw[reln->smgr_which].smgr_writeback(reln, forknum, blocknum,
640  nblocks);
641 }
void(* smgr_writeback)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: smgr.c:99

References SMgrRelationData::smgr_which, f_smgr::smgr_writeback, and smgrsw.

Referenced by IssuePendingWritebacks().

◆ smgrwritev()

void smgrwritev ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
const void **  buffer,
BlockNumber  nblocks,
bool  skipFsync 
)

Definition at line 624 of file smgr.c.

626 {
627  smgrsw[reln->smgr_which].smgr_writev(reln, forknum, blocknum,
628  buffers, nblocks, skipFsync);
629 }
void(* smgr_writev)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffers, BlockNumber nblocks, bool skipFsync)
Definition: smgr.c:95

References SMgrRelationData::smgr_which, f_smgr::smgr_writev, and smgrsw.

Referenced by smgrwrite().

◆ smgrzeroextend()

void smgrzeroextend ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
int  nblocks,
bool  skipFsync 
)

Definition at line 561 of file smgr.c.

563 {
564  smgrsw[reln->smgr_which].smgr_zeroextend(reln, forknum, blocknum,
565  nblocks, skipFsync);
566 
567  /*
568  * Normally we expect this to increase the fork size by nblocks, but if
569  * the cached value isn't as expected, just invalidate it so the next call
570  * asks the kernel.
571  */
572  if (reln->smgr_cached_nblocks[forknum] == blocknum)
573  reln->smgr_cached_nblocks[forknum] = blocknum + nblocks;
574  else
575  reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
576 }
void(* smgr_zeroextend)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
Definition: smgr.c:88

References InvalidBlockNumber, SMgrRelationData::smgr_cached_nblocks, SMgrRelationData::smgr_which, f_smgr::smgr_zeroextend, and smgrsw.

Referenced by ExtendBufferedRelLocal(), and ExtendBufferedRelShared().