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)
 
uint32 smgrmaxcombine (SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
 
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 *old_nblocks, 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 933 of file smgr.c.

934{
936}
void smgrdestroyall(void)
Definition: smgr.c:368

References smgrdestroyall().

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

◆ ProcessBarrierSmgrRelease()

bool ProcessBarrierSmgrRelease ( void  )

Definition at line 943 of file smgr.c.

944{
946 return true;
947}
void smgrreleaseall(void)
Definition: smgr.c:394

References smgrreleaseall().

Referenced by ProcessProcSignalBarrier().

◆ smgrclose()

◆ smgrcreate()

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

Definition at line 463 of file smgr.c.

464{
466 smgrsw[reln->smgr_which].smgr_create(reln, forknum, isRedo);
468}
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:135
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:133
static const f_smgr smgrsw[]
Definition: smgr.c:122
int smgr_which
Definition: smgr.h:54
void(* smgr_create)(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:93

References HOLD_INTERRUPTS, RESUME_INTERRUPTS, 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 368 of file smgr.c.

369{
371
372 /* seems unsafe to accept interrupts while in a dlist_foreach_modify() */
374
375 /*
376 * Zap all unpinned SMgrRelations. We rely on smgrdestroy() to remove
377 * each one from the list.
378 */
380 {
382 iter.cur);
383
384 smgrdestroy(rel);
385 }
386
388}
#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:305
static dlist_head unpinned_relns
Definition: smgr.c:154
dlist_node * cur
Definition: ilist.h:200

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

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

◆ smgrdosyncall()

void smgrdosyncall ( SMgrRelation rels,
int  nrels 
)

Definition at line 480 of file smgr.c.

481{
482 int i = 0;
483 ForkNumber forknum;
484
485 if (nrels == 0)
486 return;
487
488 FlushRelationsAllBuffers(rels, nrels);
489
491
492 /*
493 * Sync the physical file(s).
494 */
495 for (i = 0; i < nrels; i++)
496 {
497 int which = rels[i]->smgr_which;
498
499 for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
500 {
501 if (smgrsw[which].smgr_exists(rels[i], forknum))
502 smgrsw[which].smgr_immedsync(rels[i], forknum);
503 }
504 }
505
507}
void FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
Definition: bufmgr.c:4583
int i
Definition: isn.c:74
ForkNumber
Definition: relpath.h:56
#define MAX_FORKNUM
Definition: relpath.h:70
void(* smgr_immedsync)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:118

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

Referenced by smgrDoPendingSyncs().

◆ smgrdounlinkall()

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

Definition at line 520 of file smgr.c.

521{
522 int i = 0;
523 RelFileLocatorBackend *rlocators;
524 ForkNumber forknum;
525
526 if (nrels == 0)
527 return;
528
529 /*
530 * It would be unsafe to process interrupts between DropRelationBuffers()
531 * and unlinking the underlying files. This probably should be a critical
532 * section, but we're not there yet.
533 */
535
536 /*
537 * Get rid of any remaining buffers for the relations. bufmgr will just
538 * drop them without bothering to write the contents.
539 */
540 DropRelationsAllBuffers(rels, nrels);
541
542 /*
543 * create an array which contains all relations to be dropped, and close
544 * each relation's forks at the smgr level while at it
545 */
546 rlocators = palloc(sizeof(RelFileLocatorBackend) * nrels);
547 for (i = 0; i < nrels; i++)
548 {
549 RelFileLocatorBackend rlocator = rels[i]->smgr_rlocator;
550 int which = rels[i]->smgr_which;
551
552 rlocators[i] = rlocator;
553
554 /* Close the forks at smgr level */
555 for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
556 smgrsw[which].smgr_close(rels[i], forknum);
557 }
558
559 /*
560 * Send a shared-inval message to force other backends to close any
561 * dangling smgr references they may have for these rels. We should do
562 * this before starting the actual unlinking, in case we fail partway
563 * through that step. Note that the sinval messages will eventually come
564 * back to this backend, too, and thereby provide a backstop that we
565 * closed our own smgr rel.
566 */
567 for (i = 0; i < nrels; i++)
568 CacheInvalidateSmgr(rlocators[i]);
569
570 /*
571 * Delete the physical file(s).
572 *
573 * Note: smgr_unlink must treat deletion failure as a WARNING, not an
574 * ERROR, because we've already decided to commit or abort the current
575 * xact.
576 */
577
578 for (i = 0; i < nrels; i++)
579 {
580 int which = rels[i]->smgr_which;
581
582 for (forknum = 0; forknum <= MAX_FORKNUM; forknum++)
583 smgrsw[which].smgr_unlink(rlocators[i], forknum, isRedo);
584 }
585
586 pfree(rlocators);
587
589}
void DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
Definition: bufmgr.c:4226
void CacheInvalidateSmgr(RelFileLocatorBackend rlocator)
Definition: inval.c:1741
void pfree(void *pointer)
Definition: mcxt.c:1524
void * palloc(Size size)
Definition: mcxt.c:1317
RelFileLocatorBackend smgr_rlocator
Definition: smgr.h:37

References CacheInvalidateSmgr(), DropRelationsAllBuffers(), HOLD_INTERRUPTS, i, MAX_FORKNUM, palloc(), pfree(), RESUME_INTERRUPTS, 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 602 of file smgr.c.

604{
606
607 smgrsw[reln->smgr_which].smgr_extend(reln, forknum, blocknum,
608 buffer, skipFsync);
609
610 /*
611 * Normally we expect this to increase nblocks by one, but if the cached
612 * value isn't as expected, just invalidate it so the next call asks the
613 * kernel.
614 */
615 if (reln->smgr_cached_nblocks[forknum] == blocknum)
616 reln->smgr_cached_nblocks[forknum] = blocknum + 1;
617 else
619
621}
#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:98

References HOLD_INTERRUPTS, InvalidBlockNumber, RESUME_INTERRUPTS, 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 913 of file smgr.c.

914{
916 smgrsw[reln->smgr_which].smgr_immedsync(reln, forknum);
918}

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

Referenced by smgr_bulk_finish().

◆ smgrinit()

void smgrinit ( void  )

Definition at line 170 of file smgr.c.

171{
172 int i;
173
175
176 for (i = 0; i < NSmgr; i++)
177 {
178 if (smgrsw[i].smgr_init)
179 smgrsw[i].smgr_init();
180 }
181
183
184 /* register the shutdown proc */
186}
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:309
static const int NSmgr
Definition: smgr.c:146
static void smgrshutdown(int code, Datum arg)
Definition: smgr.c:192
void(* smgr_init)(void)
Definition: smgr.c:89

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

Referenced by BaseInit().

◆ smgrmaxcombine()

uint32 smgrmaxcombine ( SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum 
)

Definition at line 679 of file smgr.c.

681{
682 uint32 ret;
683
685 ret = smgrsw[reln->smgr_which].smgr_maxcombine(reln, forknum, blocknum);
687
688 return ret;
689}
uint32_t uint32
Definition: c.h:502
uint32(* smgr_maxcombine)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition: smgr.c:104

References HOLD_INTERRUPTS, RESUME_INTERRUPTS, f_smgr::smgr_maxcombine, SMgrRelationData::smgr_which, and smgrsw.

Referenced by StartReadBuffersImpl().

◆ smgrnblocks()

BlockNumber smgrnblocks ( SMgrRelation  reln,
ForkNumber  forknum 
)

Definition at line 767 of file smgr.c.

768{
769 BlockNumber result;
770
771 /* Check and return if we get the cached value for the number of blocks. */
772 result = smgrnblocks_cached(reln, forknum);
773 if (result != InvalidBlockNumber)
774 return result;
775
777
778 result = smgrsw[reln->smgr_which].smgr_nblocks(reln, forknum);
779
780 reln->smgr_cached_nblocks[forknum] = result;
781
783
784 return result;
785}
uint32 BlockNumber
Definition: block.h:31
BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:795
BlockNumber(* smgr_nblocks)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:115

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

Referenced by ExtendBufferedRelLocal(), ExtendBufferedRelShared(), ExtendBufferedRelTo(), FreeSpaceMapPrepareTruncateRel(), fsm_readbuf(), gistBuildCallback(), pg_truncate_visibility_map(), RelationCopyStorage(), RelationCopyStorageUsingBuffer(), RelationGetNumberOfBlocksInFork(), RelationTruncate(), ScanSourceDatabasePgClass(), smgr_bulk_start_smgr(), smgr_redo(), 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 795 of file smgr.c.

796{
797 /*
798 * For now, this function uses cached values only in recovery due to lack
799 * of a shared invalidation mechanism for changes in file size. Code
800 * elsewhere reads smgr_cached_nblocks and copes with stale data.
801 */
802 if (InRecovery && reln->smgr_cached_nblocks[forknum] != InvalidBlockNumber)
803 return reln->smgr_cached_nblocks[forknum];
804
805 return InvalidBlockNumber;
806}
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 222 of file smgr.c.

223{
224 RelFileLocatorBackend brlocator;
225 SMgrRelation reln;
226 bool found;
227
229
231
232 if (SMgrRelationHash == NULL)
233 {
234 /* First time through: initialize the hash table */
235 HASHCTL ctl;
236
237 ctl.keysize = sizeof(RelFileLocatorBackend);
238 ctl.entrysize = sizeof(SMgrRelationData);
239 SMgrRelationHash = hash_create("smgr relation table", 400,
242 }
243
244 /* Look up or create an entry */
245 brlocator.locator = rlocator;
246 brlocator.backend = backend;
248 &brlocator,
249 HASH_ENTER, &found);
250
251 /* Initialize it if not present before */
252 if (!found)
253 {
254 /* hash_search already filled in the lookup key */
256 for (int i = 0; i <= MAX_FORKNUM; ++i)
258 reln->smgr_which = 0; /* we only have md.c at present */
259
260 /* it is not pinned yet */
261 reln->pincount = 0;
263
264 /* implementation-specific initialization */
265 smgrsw[reln->smgr_which].smgr_open(reln);
266 }
267
269
270 return reln;
271}
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
Assert(PointerIsAligned(start, uint64))
@ 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:1838
struct RelFileLocatorBackend RelFileLocatorBackend
#define RelFileNumberIsValid(relnumber)
Definition: relpath.h:27
static HTAB * SMgrRelationHash
Definition: smgr.c:152
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:91

References Assert(), RelFileLocatorBackend::backend, ctl, dlist_init(), dlist_push_tail(), HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HOLD_INTERRUPTS, i, InvalidBlockNumber, RelFileLocatorBackend::locator, MAX_FORKNUM, SMgrRelationData::node, SMgrRelationData::pincount, RelFileNumberIsValid, RelFileLocator::relNumber, RESUME_INTERRUPTS, 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(), FlushLocalBuffer(), IssuePendingWritebacks(), mdsyncfiletag(), ReadBufferWithoutRelcache(), RelationCopyStorageUsingBuffer(), RelationCreateStorage(), RelationGetSmgr(), RelationSetNewRelfilenumber(), ScanSourceDatabasePgClass(), smgr_redo(), smgrDoPendingDeletes(), smgrDoPendingSyncs(), XLogPrefetcherNextBlock(), and XLogReadBufferExtended().

◆ smgrpin()

void smgrpin ( SMgrRelation  reln)

Definition at line 278 of file smgr.c.

279{
280 if (reln->pincount == 0)
281 dlist_delete(&reln->node);
282 reln->pincount++;
283}
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 660 of file smgr.c.

662{
663 bool ret;
664
666 ret = smgrsw[reln->smgr_which].smgr_prefetch(reln, forknum, blocknum, nblocks);
668
669 return ret;
670}
bool(* smgr_prefetch)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks)
Definition: smgr.c:102

References HOLD_INTERRUPTS, RESUME_INTERRUPTS, 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 117 of file smgr.h.

119{
120 smgrreadv(reln, forknum, blocknum, &buffer, 1);
121}
void smgrreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks)
Definition: smgr.c:703

References smgrreadv().

Referenced by pg_prewarm(), and RelationCopyStorage().

◆ smgrreadv()

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

Definition at line 703 of file smgr.c.

705{
707 smgrsw[reln->smgr_which].smgr_readv(reln, forknum, blocknum, buffers,
708 nblocks);
710}
void(* smgr_readv)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks)
Definition: smgr.c:106

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

Referenced by smgrread(), and WaitReadBuffers().

◆ smgrregistersync()

void smgrregistersync ( SMgrRelation  reln,
ForkNumber  forknum 
)

Definition at line 879 of file smgr.c.

880{
882 smgrsw[reln->smgr_which].smgr_registersync(reln, forknum);
884}
void(* smgr_registersync)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:119

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

Referenced by smgr_bulk_finish().

◆ smgrrelease()

void smgrrelease ( SMgrRelation  reln)

Definition at line 332 of file smgr.c.

333{
335
336 for (ForkNumber forknum = 0; forknum <= MAX_FORKNUM; forknum++)
337 {
338 smgrsw[reln->smgr_which].smgr_close(reln, forknum);
340 }
342
344}
void(* smgr_close)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:92

References HOLD_INTERRUPTS, InvalidBlockNumber, MAX_FORKNUM, RESUME_INTERRUPTS, 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 394 of file smgr.c.

395{
396 HASH_SEQ_STATUS status;
397 SMgrRelation reln;
398
399 /* Nothing to do if hashtable not set up */
400 if (SMgrRelationHash == NULL)
401 return;
402
403 /* seems unsafe to accept interrupts while iterating */
405
407
408 while ((reln = (SMgrRelation) hash_seq_search(&status)) != NULL)
409 {
410 smgrrelease(reln);
411 }
412
414}
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1420
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1385

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

Referenced by ProcessBarrierSmgrRelease(), and RelationCacheInvalidate().

◆ smgrreleaserellocator()

void smgrreleaserellocator ( RelFileLocatorBackend  rlocator)

Definition at line 425 of file smgr.c.

426{
427 SMgrRelation reln;
428
429 /* Nothing to do if hashtable not set up */
430 if (SMgrRelationHash == NULL)
431 return;
432
434 &rlocator,
435 HASH_FIND, NULL);
436 if (reln != NULL)
437 smgrrelease(reln);
438}
@ 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 old_nblocks,
BlockNumber nblocks 
)

Definition at line 823 of file smgr.c.

825{
826 int i;
827
828 /*
829 * Get rid of any buffers for the about-to-be-deleted blocks. bufmgr will
830 * just drop them without bothering to write the contents.
831 */
832 DropRelationBuffers(reln, forknum, nforks, nblocks);
833
834 /*
835 * Send a shared-inval message to force other backends to close any smgr
836 * references they may have for this rel. This is useful because they
837 * might have open file pointers to segments that got removed, and/or
838 * smgr_targblock variables pointing past the new rel end. (The inval
839 * message will come back to our backend, too, causing a
840 * probably-unnecessary local smgr flush. But we don't expect that this
841 * is a performance-critical path.) As in the unlink code, we want to be
842 * sure the message is sent before we start changing things on-disk.
843 */
845
846 /* Do the truncation */
847 for (i = 0; i < nforks; i++)
848 {
849 /* Make the cached size is invalid if we encounter an error. */
850 reln->smgr_cached_nblocks[forknum[i]] = InvalidBlockNumber;
851
852 smgrsw[reln->smgr_which].smgr_truncate(reln, forknum[i],
853 old_nblocks[i], nblocks[i]);
854
855 /*
856 * We might as well update the local smgr_cached_nblocks values. The
857 * smgr cache inval message that this function sent will cause other
858 * backends to invalidate their copies of smgr_cached_nblocks, and
859 * these ones too at the next command boundary. But ensure they aren't
860 * outright wrong until then.
861 */
862 reln->smgr_cached_nblocks[forknum[i]] = nblocks[i];
863 }
864}
void DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum, int nforks, BlockNumber *firstDelBlock)
Definition: bufmgr.c:4103
void(* smgr_truncate)(SMgrRelation reln, ForkNumber forknum, BlockNumber old_blocks, BlockNumber nblocks)
Definition: smgr.c:116

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

294{
295 Assert(reln->pincount > 0);
296 reln->pincount--;
297 if (reln->pincount == 0)
299}

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

126{
127 smgrwritev(reln, forknum, blocknum, &buffer, 1, skipFsync);
128}
void smgrwritev(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffers, BlockNumber nblocks, bool skipFsync)
Definition: smgr.c:739

References smgrwritev().

Referenced by FlushBuffer(), FlushLocalBuffer(), and smgr_bulk_flush().

◆ smgrwriteback()

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

Definition at line 753 of file smgr.c.

755{
757 smgrsw[reln->smgr_which].smgr_writeback(reln, forknum, blocknum,
758 nblocks);
760}
void(* smgr_writeback)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: smgr.c:113

References HOLD_INTERRUPTS, RESUME_INTERRUPTS, 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 739 of file smgr.c.

741{
743 smgrsw[reln->smgr_which].smgr_writev(reln, forknum, blocknum,
744 buffers, nblocks, skipFsync);
746}
void(* smgr_writev)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffers, BlockNumber nblocks, bool skipFsync)
Definition: smgr.c:109

References HOLD_INTERRUPTS, RESUME_INTERRUPTS, 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 631 of file smgr.c.

633{
635
636 smgrsw[reln->smgr_which].smgr_zeroextend(reln, forknum, blocknum,
637 nblocks, skipFsync);
638
639 /*
640 * Normally we expect this to increase the fork size by nblocks, but if
641 * the cached value isn't as expected, just invalidate it so the next call
642 * asks the kernel.
643 */
644 if (reln->smgr_cached_nblocks[forknum] == blocknum)
645 reln->smgr_cached_nblocks[forknum] = blocknum + nblocks;
646 else
648
650}
void(* smgr_zeroextend)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
Definition: smgr.c:100

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

Referenced by ExtendBufferedRelLocal(), and ExtendBufferedRelShared().