PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
smgr.h File Reference
#include "lib/ilist.h"
#include "storage/aio_types.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 smgrstartreadv (PgAioHandle *ioh, 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)
 
void pgaio_io_set_target_smgr (PgAioHandle *ioh, SMgrRelationData *smgr, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skip_fsync)
 

Variables

PGDLLIMPORT const PgAioTargetInfo aio_smgr_target_info
 

Macro Definition Documentation

◆ SmgrIsTemp

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

Definition at line 74 of file smgr.h.

Typedef Documentation

◆ SMgrRelation

Definition at line 72 of file smgr.h.

◆ SMgrRelationData

Function Documentation

◆ AtEOXact_SMgr()

void AtEOXact_SMgr ( void  )

Definition at line 1008 of file smgr.c.

1009{
1011}
void smgrdestroyall(void)
Definition: smgr.c:386

References smgrdestroyall().

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

◆ pgaio_io_set_target_smgr()

void pgaio_io_set_target_smgr ( PgAioHandle ioh,
SMgrRelationData smgr,
ForkNumber  forknum,
BlockNumber  blocknum,
int  nblocks,
bool  skip_fsync 
)

Definition at line 1029 of file smgr.c.

1035{
1037
1039
1040 /* backend is implied via IO owner */
1041 sd->smgr.rlocator = smgr->smgr_rlocator.locator;
1042 sd->smgr.forkNum = forknum;
1043 sd->smgr.blockNum = blocknum;
1044 sd->smgr.nblocks = nblocks;
1045 sd->smgr.is_temp = SmgrIsTemp(smgr);
1046 /* Temp relations should never be fsync'd */
1047 sd->smgr.skip_fsync = skip_fsync && !SmgrIsTemp(smgr);
1048}
@ PGAIO_TID_SMGR
Definition: aio.h:120
PgAioTargetData * pgaio_io_get_target_data(PgAioHandle *ioh)
Definition: aio_target.c:72
void pgaio_io_set_target(PgAioHandle *ioh, PgAioTargetID targetid)
Definition: aio_target.c:63
#define SmgrIsTemp(smgr)
Definition: smgr.h:74
RelFileLocator locator
RelFileLocatorBackend smgr_rlocator
Definition: smgr.h:38
BlockNumber blockNum
Definition: aio_types.h:66
RelFileLocator rlocator
Definition: aio_types.h:65
BlockNumber nblocks
Definition: aio_types.h:67
struct PgAioTargetData::@124 smgr
ForkNumber forkNum
Definition: aio_types.h:68

References PgAioTargetData::blockNum, PgAioTargetData::forkNum, PgAioTargetData::is_temp, RelFileLocatorBackend::locator, PgAioTargetData::nblocks, pgaio_io_get_target_data(), pgaio_io_set_target(), PGAIO_TID_SMGR, PgAioTargetData::rlocator, PgAioTargetData::skip_fsync, PgAioTargetData::smgr, SMgrRelationData::smgr_rlocator, and SmgrIsTemp.

Referenced by mdstartreadv().

◆ ProcessBarrierSmgrRelease()

bool ProcessBarrierSmgrRelease ( void  )

Definition at line 1018 of file smgr.c.

1019{
1021 return true;
1022}
void smgrreleaseall(void)
Definition: smgr.c:412

References smgrreleaseall().

Referenced by ProcessProcSignalBarrier().

◆ smgrclose()

◆ smgrcreate()

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

Definition at line 481 of file smgr.c.

482{
484 smgrsw[reln->smgr_which].smgr_create(reln, forknum, isRedo);
486}
#define RESUME_INTERRUPTS()
Definition: miscadmin.h:136
#define HOLD_INTERRUPTS()
Definition: miscadmin.h:134
static const f_smgr smgrsw[]
Definition: smgr.c:128
int smgr_which
Definition: smgr.h:55
void(* smgr_create)(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:94

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

387{
389
390 /* seems unsafe to accept interrupts while in a dlist_foreach_modify() */
392
393 /*
394 * Zap all unpinned SMgrRelations. We rely on smgrdestroy() to remove
395 * each one from the list.
396 */
398 {
400 iter.cur);
401
402 smgrdestroy(rel);
403 }
404
406}
#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:323
static dlist_head unpinned_relns
Definition: smgr.c:162
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 498 of file smgr.c.

499{
500 int i = 0;
501 ForkNumber forknum;
502
503 if (nrels == 0)
504 return;
505
506 FlushRelationsAllBuffers(rels, nrels);
507
509
510 /*
511 * Sync the physical file(s).
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 {
519 if (smgrsw[which].smgr_exists(rels[i], forknum))
520 smgrsw[which].smgr_immedsync(rels[i], forknum);
521 }
522 }
523
525}
void FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
Definition: bufmgr.c:4963
int i
Definition: isn.c:77
ForkNumber
Definition: relpath.h:56
#define MAX_FORKNUM
Definition: relpath.h:70
void(* smgr_immedsync)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:123

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

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

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

622{
624
625 smgrsw[reln->smgr_which].smgr_extend(reln, forknum, blocknum,
626 buffer, skipFsync);
627
628 /*
629 * Normally we expect this to increase nblocks by one, but if the cached
630 * value isn't as expected, just invalidate it so the next call asks the
631 * kernel.
632 */
633 if (reln->smgr_cached_nblocks[forknum] == blocknum)
634 reln->smgr_cached_nblocks[forknum] = blocknum + 1;
635 else
637
639}
#define InvalidBlockNumber
Definition: block.h:33
BlockNumber smgr_cached_nblocks[MAX_FORKNUM+1]
Definition: smgr.h:47
void(* smgr_extend)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
Definition: smgr.c:99

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

966{
968 smgrsw[reln->smgr_which].smgr_immedsync(reln, forknum);
970}

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

189{
190 int i;
191
193
194 for (i = 0; i < NSmgr; i++)
195 {
196 if (smgrsw[i].smgr_init)
197 smgrsw[i].smgr_init();
198 }
199
201
202 /* register the shutdown proc */
204}
void on_proc_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:309
static const int NSmgr
Definition: smgr.c:154
static void smgrshutdown(int code, Datum arg)
Definition: smgr.c:210
void(* smgr_init)(void)
Definition: smgr.c:90

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

699{
700 uint32 ret;
701
703 ret = smgrsw[reln->smgr_which].smgr_maxcombine(reln, forknum, blocknum);
705
706 return ret;
707}
uint32_t uint32
Definition: c.h:502
uint32(* smgr_maxcombine)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition: smgr.c:105

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

820{
821 BlockNumber result;
822
823 /* Check and return if we get the cached value for the number of blocks. */
824 result = smgrnblocks_cached(reln, forknum);
825 if (result != InvalidBlockNumber)
826 return result;
827
829
830 result = smgrsw[reln->smgr_which].smgr_nblocks(reln, forknum);
831
832 reln->smgr_cached_nblocks[forknum] = result;
833
835
836 return result;
837}
uint32 BlockNumber
Definition: block.h:31
BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:847
BlockNumber(* smgr_nblocks)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:120

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

848{
849 /*
850 * For now, this function uses cached values only in recovery due to lack
851 * of a shared invalidation mechanism for changes in file size. Code
852 * elsewhere reads smgr_cached_nblocks and copes with stale data.
853 */
854 if (InRecovery && reln->smgr_cached_nblocks[forknum] != InvalidBlockNumber)
855 return reln->smgr_cached_nblocks[forknum];
856
857 return InvalidBlockNumber;
858}
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 240 of file smgr.c.

241{
242 RelFileLocatorBackend brlocator;
243 SMgrRelation reln;
244 bool found;
245
247
249
250 if (SMgrRelationHash == NULL)
251 {
252 /* First time through: initialize the hash table */
253 HASHCTL ctl;
254
255 ctl.keysize = sizeof(RelFileLocatorBackend);
256 ctl.entrysize = sizeof(SMgrRelationData);
257 SMgrRelationHash = hash_create("smgr relation table", 400,
260 }
261
262 /* Look up or create an entry */
263 brlocator.locator = rlocator;
264 brlocator.backend = backend;
266 &brlocator,
267 HASH_ENTER, &found);
268
269 /* Initialize it if not present before */
270 if (!found)
271 {
272 /* hash_search already filled in the lookup key */
274 for (int i = 0; i <= MAX_FORKNUM; ++i)
276 reln->smgr_which = 0; /* we only have md.c at present */
277
278 /* it is not pinned yet */
279 reln->pincount = 0;
281
282 /* implementation-specific initialization */
283 smgrsw[reln->smgr_which].smgr_open(reln);
284 }
285
287
288 return reln;
289}
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:160
struct SMgrRelationData SMgrRelationData
SMgrRelationData * SMgrRelation
Definition: smgr.h:72
RelFileNumber relNumber
BlockNumber smgr_targblock
Definition: smgr.h:46
dlist_node node
Definition: smgr.h:69
int pincount
Definition: smgr.h:68
void(* smgr_open)(SMgrRelation reln)
Definition: smgr.c:92

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_aio_reopen(), smgr_redo(), smgrDoPendingDeletes(), smgrDoPendingSyncs(), XLogPrefetcherNextBlock(), and XLogReadBufferExtended().

◆ smgrpin()

void smgrpin ( SMgrRelation  reln)

Definition at line 296 of file smgr.c.

297{
298 if (reln->pincount == 0)
299 dlist_delete(&reln->node);
300 reln->pincount++;
301}
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 678 of file smgr.c.

680{
681 bool ret;
682
684 ret = smgrsw[reln->smgr_which].smgr_prefetch(reln, forknum, blocknum, nblocks);
686
687 return ret;
688}
bool(* smgr_prefetch)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks)
Definition: smgr.c:103

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

126{
127 smgrreadv(reln, forknum, blocknum, &buffer, 1);
128}
void smgrreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks)
Definition: smgr.c:721

References smgrreadv().

Referenced by pg_prewarm(), and RelationCopyStorage().

◆ smgrreadv()

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

Definition at line 721 of file smgr.c.

723{
725 smgrsw[reln->smgr_which].smgr_readv(reln, forknum, blocknum, buffers,
726 nblocks);
728}
void(* smgr_readv)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks)
Definition: smgr.c:107

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

Referenced by smgrread().

◆ smgrregistersync()

void smgrregistersync ( SMgrRelation  reln,
ForkNumber  forknum 
)

Definition at line 931 of file smgr.c.

932{
934 smgrsw[reln->smgr_which].smgr_registersync(reln, forknum);
936}
void(* smgr_registersync)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:124

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

351{
353
354 for (ForkNumber forknum = 0; forknum <= MAX_FORKNUM; forknum++)
355 {
356 smgrsw[reln->smgr_which].smgr_close(reln, forknum);
358 }
360
362}
void(* smgr_close)(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:93

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

413{
414 HASH_SEQ_STATUS status;
415 SMgrRelation reln;
416
417 /* Nothing to do if hashtable not set up */
418 if (SMgrRelationHash == NULL)
419 return;
420
421 /* seems unsafe to accept interrupts while iterating */
423
425
426 while ((reln = (SMgrRelation) hash_seq_search(&status)) != NULL)
427 {
428 smgrrelease(reln);
429 }
430
432}
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(), read_rel_block_ll(), and RelationCacheInvalidate().

◆ smgrreleaserellocator()

void smgrreleaserellocator ( RelFileLocatorBackend  rlocator)

Definition at line 443 of file smgr.c.

444{
445 SMgrRelation reln;
446
447 /* Nothing to do if hashtable not set up */
448 if (SMgrRelationHash == NULL)
449 return;
450
452 &rlocator,
453 HASH_FIND, NULL);
454 if (reln != NULL)
455 smgrrelease(reln);
456}
@ HASH_FIND
Definition: hsearch.h:113

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

Referenced by LocalExecuteInvalidationMessage().

◆ smgrstartreadv()

void smgrstartreadv ( PgAioHandle ioh,
SMgrRelation  reln,
ForkNumber  forknum,
BlockNumber  blocknum,
void **  buffers,
BlockNumber  nblocks 
)

Definition at line 753 of file smgr.c.

756{
759 reln, forknum, blocknum, buffers,
760 nblocks);
762}
void(* smgr_startreadv)(PgAioHandle *ioh, SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks)
Definition: smgr.c:110

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

Referenced by AsyncReadBuffers(), and read_rel_block_ll().

◆ smgrtruncate()

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

Definition at line 875 of file smgr.c.

877{
878 int i;
879
880 /*
881 * Get rid of any buffers for the about-to-be-deleted blocks. bufmgr will
882 * just drop them without bothering to write the contents.
883 */
884 DropRelationBuffers(reln, forknum, nforks, nblocks);
885
886 /*
887 * Send a shared-inval message to force other backends to close any smgr
888 * references they may have for this rel. This is useful because they
889 * might have open file pointers to segments that got removed, and/or
890 * smgr_targblock variables pointing past the new rel end. (The inval
891 * message will come back to our backend, too, causing a
892 * probably-unnecessary local smgr flush. But we don't expect that this
893 * is a performance-critical path.) As in the unlink code, we want to be
894 * sure the message is sent before we start changing things on-disk.
895 */
897
898 /* Do the truncation */
899 for (i = 0; i < nforks; i++)
900 {
901 /* Make the cached size is invalid if we encounter an error. */
902 reln->smgr_cached_nblocks[forknum[i]] = InvalidBlockNumber;
903
904 smgrsw[reln->smgr_which].smgr_truncate(reln, forknum[i],
905 old_nblocks[i], nblocks[i]);
906
907 /*
908 * We might as well update the local smgr_cached_nblocks values. The
909 * smgr cache inval message that this function sent will cause other
910 * backends to invalidate their copies of smgr_cached_nblocks, and
911 * these ones too at the next command boundary. But ensure they aren't
912 * outright wrong until then.
913 */
914 reln->smgr_cached_nblocks[forknum[i]] = nblocks[i];
915 }
916}
void DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum, int nforks, BlockNumber *firstDelBlock)
Definition: bufmgr.c:4470
void(* smgr_truncate)(SMgrRelation reln, ForkNumber forknum, BlockNumber old_blocks, BlockNumber nblocks)
Definition: smgr.c:121

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

312{
313 Assert(reln->pincount > 0);
314 reln->pincount--;
315 if (reln->pincount == 0)
317}

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

133{
134 smgrwritev(reln, forknum, blocknum, &buffer, 1, skipFsync);
135}
void smgrwritev(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffers, BlockNumber nblocks, bool skipFsync)
Definition: smgr.c:791

References smgrwritev().

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

◆ smgrwriteback()

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

Definition at line 805 of file smgr.c.

807{
809 smgrsw[reln->smgr_which].smgr_writeback(reln, forknum, blocknum,
810 nblocks);
812}
void(* smgr_writeback)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, BlockNumber nblocks)
Definition: smgr.c:118

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

793{
795 smgrsw[reln->smgr_which].smgr_writev(reln, forknum, blocknum,
796 buffers, nblocks, skipFsync);
798}
void(* smgr_writev)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffers, BlockNumber nblocks, bool skipFsync)
Definition: smgr.c:114

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

651{
653
654 smgrsw[reln->smgr_which].smgr_zeroextend(reln, forknum, blocknum,
655 nblocks, skipFsync);
656
657 /*
658 * Normally we expect this to increase the fork size by nblocks, but if
659 * the cached value isn't as expected, just invalidate it so the next call
660 * asks the kernel.
661 */
662 if (reln->smgr_cached_nblocks[forknum] == blocknum)
663 reln->smgr_cached_nblocks[forknum] = blocknum + nblocks;
664 else
666
668}
void(* smgr_zeroextend)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
Definition: smgr.c:101

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

Referenced by ExtendBufferedRelLocal(), and ExtendBufferedRelShared().

Variable Documentation

◆ aio_smgr_target_info

PGDLLIMPORT const PgAioTargetInfo aio_smgr_target_info
extern

Definition at line 172 of file smgr.c.