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, ProcNumber 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 **buffers, BlockNumber nblocks)
 
void smgrwritev (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffers, 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 smgrregistersync (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 807 of file smgr.c.

808 {
809  smgrdestroyall();
810 }
void smgrdestroyall(void)
Definition: smgr.c:332

References smgrdestroyall().

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

◆ ProcessBarrierSmgrRelease()

bool ProcessBarrierSmgrRelease ( void  )

Definition at line 817 of file smgr.c.

818 {
819  smgrreleaseall();
820  return true;
821 }
void smgrreleaseall(void)
Definition: smgr.c:353

References smgrreleaseall().

Referenced by ProcessProcSignalBarrier().

◆ smgrclose()

◆ smgrcreate()

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

Definition at line 411 of file smgr.c.

412 {
413  smgrsw[reln->smgr_which].smgr_create(reln, forknum, isRedo);
414 }
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:80

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 332 of file smgr.c.

333 {
334  dlist_mutable_iter iter;
335 
336  /*
337  * Zap all unpinned SMgrRelations. We rely on smgrdestroy() to remove
338  * each one from the list.
339  */
341  {
343  iter.cur);
344 
345  smgrdestroy(rel);
346  }
347 }
#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:277
static dlist_head unpinned_relns
Definition: smgr.c:138
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(), RequestCheckpoint(), and XLogDropDatabase().

◆ smgrdosyncall()

void smgrdosyncall ( SMgrRelation rels,
int  nrels 
)

Definition at line 426 of file smgr.c.

427 {
428  int i = 0;
429  ForkNumber forknum;
430 
431  if (nrels == 0)
432  return;
433 
434  FlushRelationsAllBuffers(rels, nrels);
435 
436  /*
437  * Sync the physical file(s).
438  */
439  for (i = 0; i < nrels; i++)
440  {
441  int which = rels[i]->smgr_which;
442 
443  for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
444  {
445  if (smgrsw[which].smgr_exists(rels[i], forknum))
446  smgrsw[which].smgr_immedsync(rels[i], forknum);
447  }
448  }
449 }
void FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
Definition: bufmgr.c:4579
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:103

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 462 of file smgr.c.

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

537 {
538  smgrsw[reln->smgr_which].smgr_extend(reln, forknum, blocknum,
539  buffer, skipFsync);
540 
541  /*
542  * Normally we expect this to increase nblocks by one, but if the cached
543  * value isn't as expected, just invalidate it so the next call asks the
544  * kernel.
545  */
546  if (reln->smgr_cached_nblocks[forknum] == blocknum)
547  reln->smgr_cached_nblocks[forknum] = blocknum + 1;
548  else
549  reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
550 }
#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:85

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

Referenced by _hash_alloc_buckets(), RelationCopyStorageUsingBuffer(), and smgr_bulk_flush().

◆ smgrimmedsync()

void smgrimmedsync ( SMgrRelation  reln,
ForkNumber  forknum 
)

Definition at line 789 of file smgr.c.

790 {
791  smgrsw[reln->smgr_which].smgr_immedsync(reln, forknum);
792 }

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

Referenced by smgr_bulk_finish().

◆ smgrinit()

void smgrinit ( void  )

Definition at line 154 of file smgr.c.

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

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 655 of file smgr.c.

656 {
657  BlockNumber result;
658 
659  /* Check and return if we get the cached value for the number of blocks. */
660  result = smgrnblocks_cached(reln, forknum);
661  if (result != InvalidBlockNumber)
662  return result;
663 
664  result = smgrsw[reln->smgr_which].smgr_nblocks(reln, forknum);
665 
666  reln->smgr_cached_nblocks[forknum] = result;
667 
668  return result;
669 }
uint32 BlockNumber
Definition: block.h:31
BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:679
BlockNumber(* smgr_nblocks)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:100

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 679 of file smgr.c.

680 {
681  /*
682  * For now, this function uses cached values only in recovery due to lack
683  * of a shared invalidation mechanism for changes in file size. Code
684  * elsewhere reads smgr_cached_nblocks and copes with stale data.
685  */
686  if (InRecovery && reln->smgr_cached_nblocks[forknum] != InvalidBlockNumber)
687  return reln->smgr_cached_nblocks[forknum];
688 
689  return InvalidBlockNumber;
690 }
bool InRecovery
Definition: xlogutils.c:50

References InRecovery, InvalidBlockNumber, and SMgrRelationData::smgr_cached_nblocks.

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

◆ smgropen()

SMgrRelation smgropen ( RelFileLocator  rlocator,
ProcNumber  backend 
)

Definition at line 198 of file smgr.c.

199 {
200  RelFileLocatorBackend brlocator;
201  SMgrRelation reln;
202  bool found;
203 
205 
206  if (SMgrRelationHash == NULL)
207  {
208  /* First time through: initialize the hash table */
209  HASHCTL ctl;
210 
211  ctl.keysize = sizeof(RelFileLocatorBackend);
212  ctl.entrysize = sizeof(SMgrRelationData);
213  SMgrRelationHash = hash_create("smgr relation table", 400,
214  &ctl, HASH_ELEM | HASH_BLOBS);
216  }
217 
218  /* Look up or create an entry */
219  brlocator.locator = rlocator;
220  brlocator.backend = backend;
222  &brlocator,
223  HASH_ENTER, &found);
224 
225  /* Initialize it if not present before */
226  if (!found)
227  {
228  /* hash_search already filled in the lookup key */
230  for (int i = 0; i <= MAX_FORKNUM; ++i)
232  reln->smgr_which = 0; /* we only have md.c at present */
233 
234  /* implementation-specific initialization */
235  smgrsw[reln->smgr_which].smgr_open(reln);
236 
237  /* it is not pinned yet */
238  reln->pincount = 0;
240  }
241 
242  return reln;
243 }
#define Assert(condition)
Definition: c.h:858
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:955
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:352
@ 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
tree ctl
Definition: radixtree.h:1853
struct RelFileLocatorBackend RelFileLocatorBackend
#define RelFileNumberIsValid(relnumber)
Definition: relpath.h:27
static HTAB * SMgrRelationHash
Definition: smgr.c:136
struct SMgrRelationData SMgrRelationData
SMgrRelationData * SMgrRelation
Definition: smgr.h:71
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:78

References Assert, RelFileLocatorBackend::backend, ctl, dlist_init(), dlist_push_tail(), HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), i, InvalidBlockNumber, 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 250 of file smgr.c.

251 {
252  if (reln->pincount == 0)
253  dlist_delete(&reln->node);
254  reln->pincount++;
255 }
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 585 of file smgr.c.

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

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

Referenced by PrefetchLocalBuffer(), PrefetchSharedBuffer(), and StartReadBuffersImpl().

◆ smgrread()

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

Definition at line 114 of file smgr.h.

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

References smgrreadv().

Referenced by pg_prewarm(), and RelationCopyStorage().

◆ smgrreadv()

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

Definition at line 600 of file smgr.c.

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

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

Referenced by smgrread(), and WaitReadBuffers().

◆ smgrregistersync()

void smgrregistersync ( SMgrRelation  reln,
ForkNumber  forknum 
)

Definition at line 757 of file smgr.c.

758 {
759  smgrsw[reln->smgr_which].smgr_registersync(reln, forknum);
760 }
void(* smgr_registersync)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:104

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

Referenced by smgr_bulk_finish().

◆ smgrrelease()

void smgrrelease ( SMgrRelation  reln)

Definition at line 300 of file smgr.c.

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

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 353 of file smgr.c.

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

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

Referenced by ProcessBarrierSmgrRelease(), and RelationCacheInvalidate().

◆ smgrreleaserellocator()

void smgrreleaserellocator ( RelFileLocatorBackend  rlocator)

Definition at line 379 of file smgr.c.

380 {
381  SMgrRelation reln;
382 
383  /* Nothing to do if hashtable not set up */
384  if (SMgrRelationHash == NULL)
385  return;
386 
388  &rlocator,
389  HASH_FIND, NULL);
390  if (reln != NULL)
391  smgrrelease(reln);
392 }
@ 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 703 of file smgr.c.

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

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 265 of file smgr.c.

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

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 121 of file smgr.h.

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

References smgrwritev().

Referenced by FlushBuffer(), FlushRelationBuffers(), GetLocalVictimBuffer(), and smgr_bulk_flush().

◆ smgrwriteback()

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

Definition at line 643 of file smgr.c.

645 {
646  smgrsw[reln->smgr_which].smgr_writeback(reln, forknum, blocknum,
647  nblocks);
648 }
void(* smgr_writeback)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: smgr.c:98

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

Referenced by IssuePendingWritebacks().

◆ smgrwritev()

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

Definition at line 631 of file smgr.c.

633 {
634  smgrsw[reln->smgr_which].smgr_writev(reln, forknum, blocknum,
635  buffers, nblocks, skipFsync);
636 }
void(* smgr_writev)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffers, BlockNumber nblocks, bool skipFsync)
Definition: smgr.c:94

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 560 of file smgr.c.

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

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

Referenced by ExtendBufferedRelLocal(), and ExtendBufferedRelShared().