PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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.

125{
126 smgrreadv(reln, forknum, blocknum, &buffer, 1);
127}
128
129static inline void
131 const void *buffer, bool skipFsync)
132{
133 smgrwritev(reln, forknum, blocknum, &buffer, 1, skipFsync);
134}
135
137 SMgrRelationData *smgr,
138 ForkNumber forknum,
139 BlockNumber blocknum,
140 int nblocks,
141 bool skip_fsync);
142
143#endif /* SMGR_H */
uint32 BlockNumber
Definition block.h:31
static int fb(int x)
ForkNumber
Definition relpath.h:56
static void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
Definition smgr.h:131
void smgrwritev(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void **buffers, BlockNumber nblocks, bool skipFsync)
Definition smgr.c:791
void smgrreadv(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, void **buffers, BlockNumber nblocks)
Definition smgr.c:721
void pgaio_io_set_target_smgr(PgAioHandle *ioh, SMgrRelationData *smgr, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skip_fsync)
Definition smgr.c:1038

Typedef Documentation

◆ SMgrRelation

Definition at line 72 of file smgr.h.

◆ SMgrRelationData

Function Documentation

◆ AtEOXact_SMgr()

void AtEOXact_SMgr ( void  )
extern

Definition at line 1017 of file smgr.c.

1018{
1020}
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 
)
extern

Definition at line 1038 of file smgr.c.

1044{
1046
1048
1049 /* backend is implied via IO owner */
1050 sd->smgr.rlocator = smgr->smgr_rlocator.locator;
1051 sd->smgr.forkNum = forknum;
1052 sd->smgr.blockNum = blocknum;
1053 sd->smgr.nblocks = nblocks;
1054 sd->smgr.is_temp = SmgrIsTemp(smgr);
1055 /* Temp relations should never be fsync'd */
1056 sd->smgr.skip_fsync = skip_fsync && !SmgrIsTemp(smgr);
1057}
@ PGAIO_TID_SMGR
Definition aio.h:120
PgAioTargetData * pgaio_io_get_target_data(PgAioHandle *ioh)
Definition aio_target.c:73
void pgaio_io_set_target(PgAioHandle *ioh, PgAioTargetID targetid)
Definition aio_target.c:64
#define SmgrIsTemp(smgr)
Definition smgr.h:74
RelFileLocator locator
RelFileLocatorBackend smgr_rlocator
Definition smgr.h:38

References fb(), RelFileLocatorBackend::locator, pgaio_io_get_target_data(), pgaio_io_set_target(), PGAIO_TID_SMGR, SMgrRelationData::smgr_rlocator, and SmgrIsTemp.

Referenced by mdstartreadv().

◆ ProcessBarrierSmgrRelease()

bool ProcessBarrierSmgrRelease ( void  )
extern

Definition at line 1027 of file smgr.c.

1028{
1030 return true;
1031}
void smgrreleaseall(void)
Definition smgr.c:412

References smgrreleaseall().

Referenced by ProcessProcSignalBarrier().

◆ smgrclose()

◆ smgrcreate()

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

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
void(* smgr_create)(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition smgr.c:94

References fb(), HOLD_INTERRUPTS, RESUME_INTERRUPTS, f_smgr::smgr_create, 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  )
extern

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(), xlog_redo(), and XLogDropDatabase().

◆ smgrdosyncall()

void smgrdosyncall ( SMgrRelation rels,
int  nrels 
)
extern

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:5165
int i
Definition isn.c:77
#define MAX_FORKNUM
Definition relpath.h:70
int smgr_which
Definition smgr.h:55
void(* smgr_immedsync)(SMgrRelation reln, ForkNumber forknum)
Definition smgr.c:123

References fb(), 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 
)
extern

Definition at line 538 of file smgr.c.

539{
540 int i = 0;
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 */
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++)
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
605
607}
void DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
Definition bufmgr.c:4800
#define palloc_array(type, count)
Definition fe_memutils.h:76
void CacheInvalidateSmgr(RelFileLocatorBackend rlocator)
Definition inval.c:1755
void pfree(void *pointer)
Definition mcxt.c:1616

References CacheInvalidateSmgr(), DropRelationsAllBuffers(), fb(), HOLD_INTERRUPTS, i, MAX_FORKNUM, palloc_array, 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 
)
extern

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
636 reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
637
639}
#define InvalidBlockNumber
Definition block.h:33
void(* smgr_extend)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
Definition smgr.c:99

References fb(), HOLD_INTERRUPTS, InvalidBlockNumber, RESUME_INTERRUPTS, f_smgr::smgr_extend, and smgrsw.

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

◆ smgrimmedsync()

void smgrimmedsync ( SMgrRelation  reln,
ForkNumber  forknum 
)
extern

Definition at line 974 of file smgr.c.

975{
977 smgrsw[reln->smgr_which].smgr_immedsync(reln, forknum);
979}

References fb(), HOLD_INTERRUPTS, RESUME_INTERRUPTS, f_smgr::smgr_immedsync, and smgrsw.

Referenced by smgr_bulk_finish().

◆ smgrinit()

void smgrinit ( void  )
extern

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:316
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 
)
extern

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:546
uint32(* smgr_maxcombine)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
Definition smgr.c:105

References fb(), HOLD_INTERRUPTS, RESUME_INTERRUPTS, f_smgr::smgr_maxcombine, and smgrsw.

Referenced by StartReadBuffersImpl().

◆ smgrnblocks()

BlockNumber smgrnblocks ( SMgrRelation  reln,
ForkNumber  forknum 
)
extern

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}
BlockNumber smgrnblocks_cached(SMgrRelation reln, ForkNumber forknum)
Definition smgr.c:847
BlockNumber(* smgr_nblocks)(SMgrRelation reln, ForkNumber forknum)
Definition smgr.c:120

References fb(), HOLD_INTERRUPTS, InvalidBlockNumber, RESUME_INTERRUPTS, f_smgr::smgr_nblocks, 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 
)
extern

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 fb(), InRecovery, and InvalidBlockNumber.

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

◆ smgropen()

SMgrRelation smgropen ( RelFileLocator  rlocator,
ProcNumber  backend 
)
extern

Definition at line 240 of file smgr.c.

241{
244 bool found;
245
247
249
250 if (SMgrRelationHash == NULL)
251 {
252 /* First time through: initialize the hash table */
253 HASHCTL ctl;
254
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 */
273 reln->smgr_targblock = InvalidBlockNumber;
274 for (int i = 0; i <= MAX_FORKNUM; ++i)
275 reln->smgr_cached_nblocks[i] = InvalidBlockNumber;
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}
struct SMgrRelationData * SMgrRelation
Definition bufmgr.h:97
#define Assert(condition)
Definition c.h:873
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition dynahash.c:952
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Definition dynahash.c:358
@ 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
#define RelFileNumberIsValid(relnumber)
Definition relpath.h:27
static HTAB * SMgrRelationHash
Definition smgr.c:160
Size keysize
Definition hsearch.h:75
RelFileNumber relNumber
void(* smgr_open)(SMgrRelation reln)
Definition smgr.c:92

References Assert, ctl, dlist_init(), dlist_push_tail(), fb(), HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HOLD_INTERRUPTS, i, InvalidBlockNumber, HASHCTL::keysize, MAX_FORKNUM, RelFileNumberIsValid, RelFileLocator::relNumber, RESUME_INTERRUPTS, f_smgr::smgr_open, 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)
extern

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(), and fb().

Referenced by RelationGetSmgr().

◆ smgrprefetch()

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

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 fb(), HOLD_INTERRUPTS, RESUME_INTERRUPTS, f_smgr::smgr_prefetch, 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}

References fb(), and smgrreadv().

Referenced by pg_prewarm(), and RelationCopyStorage().

◆ smgrreadv()

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

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 fb(), HOLD_INTERRUPTS, RESUME_INTERRUPTS, f_smgr::smgr_readv, and smgrsw.

Referenced by smgrread().

◆ smgrregistersync()

void smgrregistersync ( SMgrRelation  reln,
ForkNumber  forknum 
)
extern

Definition at line 940 of file smgr.c.

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

References fb(), HOLD_INTERRUPTS, RESUME_INTERRUPTS, f_smgr::smgr_registersync, and smgrsw.

Referenced by smgr_bulk_finish().

◆ smgrrelease()

void smgrrelease ( SMgrRelation  reln)
extern

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);
357 reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
358 }
359 reln->smgr_targblock = InvalidBlockNumber;
360
362}
void(* smgr_close)(SMgrRelation reln, ForkNumber forknum)
Definition smgr.c:93

References fb(), HOLD_INTERRUPTS, InvalidBlockNumber, MAX_FORKNUM, RESUME_INTERRUPTS, f_smgr::smgr_close, and smgrsw.

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

◆ smgrreleaseall()

void smgrreleaseall ( void  )
extern

Definition at line 412 of file smgr.c.

413{
414 HASH_SEQ_STATUS status;
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 {
429 }
430
432}
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition dynahash.c:1415
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition dynahash.c:1380

References fb(), 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)
extern

Definition at line 443 of file smgr.c.

444{
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)
456}
@ HASH_FIND
Definition hsearch.h:113

References fb(), 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 
)
extern

Definition at line 753 of file smgr.c.

756{
758 smgrsw[reln->smgr_which].smgr_startreadv(ioh,
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 fb(), HOLD_INTERRUPTS, RESUME_INTERRUPTS, f_smgr::smgr_startreadv, and smgrsw.

Referenced by AsyncReadBuffers(), and read_rel_block_ll().

◆ smgrtruncate()

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

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 */
896 CacheInvalidateSmgr(reln->smgr_rlocator);
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 * We can have nblocks > old_nblocks when a relation was truncated
915 * multiple times, a replica applied all the truncations, and later
916 * restarts from a restartpoint located before the truncations. The
917 * relation on disk will be the size of the last truncate. When
918 * replaying the first truncate, we will have nblocks > current size.
919 * In such cases, smgr_truncate does nothing, so set the cached size
920 * to the old size rather than the requested size.
921 */
922 reln->smgr_cached_nblocks[forknum[i]] =
923 nblocks[i] > old_nblocks[i] ? old_nblocks[i] : nblocks[i];
924 }
925}
void DropRelationBuffers(SMgrRelation smgr_reln, ForkNumber *forkNum, int nforks, BlockNumber *firstDelBlock)
Definition bufmgr.c:4680
void(* smgr_truncate)(SMgrRelation reln, ForkNumber forknum, BlockNumber old_blocks, BlockNumber nblocks)
Definition smgr.c:121

References CacheInvalidateSmgr(), DropRelationBuffers(), fb(), i, InvalidBlockNumber, f_smgr::smgr_truncate, and smgrsw.

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

◆ smgrunpin()

void smgrunpin ( SMgrRelation  reln)
extern

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(), fb(), 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}

References fb(), and smgrwritev().

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

◆ smgrwriteback()

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

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 fb(), HOLD_INTERRUPTS, RESUME_INTERRUPTS, 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 
)
extern

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 fb(), HOLD_INTERRUPTS, RESUME_INTERRUPTS, f_smgr::smgr_writev, and smgrsw.

Referenced by smgrwrite().

◆ smgrzeroextend()

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

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
665 reln->smgr_cached_nblocks[forknum] = InvalidBlockNumber;
666
668}
void(* smgr_zeroextend)(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
Definition smgr.c:101

References fb(), HOLD_INTERRUPTS, InvalidBlockNumber, RESUME_INTERRUPTS, 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.

172 {
173 .name = "smgr",
174 .reopen = smgr_aio_reopen,
175 .describe_identity = smgr_aio_describe_identity,
176};
static char * smgr_aio_describe_identity(const PgAioTargetData *sd)
Definition smgr.c:1104
static void smgr_aio_reopen(PgAioHandle *ioh)
Definition smgr.c:1064