PostgreSQL Source Code
git master
|
#include "port/atomics.h"
#include "storage/buf.h"
#include "storage/bufmgr.h"
#include "storage/condition_variable.h"
#include "storage/latch.h"
#include "storage/lwlock.h"
#include "storage/shmem.h"
#include "storage/smgr.h"
#include "storage/spin.h"
#include "utils/relcache.h"
Go to the source code of this file.
Data Structures | |
struct | buftag |
struct | BufferDesc |
union | BufferDescPadded |
struct | PendingWriteback |
struct | WritebackContext |
struct | CkptSortItem |
Macros | |
#define | BUF_REFCOUNT_ONE 1 |
#define | BUF_REFCOUNT_MASK ((1U << 18) - 1) |
#define | BUF_USAGECOUNT_MASK 0x003C0000U |
#define | BUF_USAGECOUNT_ONE (1U << 18) |
#define | BUF_USAGECOUNT_SHIFT 18 |
#define | BUF_FLAG_MASK 0xFFC00000U |
#define | BUF_STATE_GET_REFCOUNT(state) ((state) & BUF_REFCOUNT_MASK) |
#define | BUF_STATE_GET_USAGECOUNT(state) (((state) & BUF_USAGECOUNT_MASK) >> BUF_USAGECOUNT_SHIFT) |
#define | BM_LOCKED (1U << 22) /* buffer header is locked */ |
#define | BM_DIRTY (1U << 23) /* data needs writing */ |
#define | BM_VALID (1U << 24) /* data is valid */ |
#define | BM_TAG_VALID (1U << 25) /* tag is assigned */ |
#define | BM_IO_IN_PROGRESS (1U << 26) /* read or write in progress */ |
#define | BM_IO_ERROR (1U << 27) /* previous I/O failed */ |
#define | BM_JUST_DIRTIED (1U << 28) /* dirtied since write started */ |
#define | BM_PIN_COUNT_WAITER (1U << 29) /* have waiter for sole pin */ |
#define | BM_CHECKPOINT_NEEDED (1U << 30) /* must write for checkpoint */ |
#define | BM_PERMANENT |
#define | BM_MAX_USAGE_COUNT 5 |
#define | CLEAR_BUFFERTAG(a) |
#define | INIT_BUFFERTAG(a, xx_rlocator, xx_forkNum, xx_blockNum) |
#define | BUFFERTAGS_EQUAL(a, b) |
#define | BufTableHashPartition(hashcode) ((hashcode) % NUM_BUFFER_PARTITIONS) |
#define | BufMappingPartitionLock(hashcode) |
#define | BufMappingPartitionLockByIndex(i) (&MainLWLockArray[BUFFER_MAPPING_LWLOCK_OFFSET + (i)].lock) |
#define | BUFFERDESC_PAD_TO_SIZE (SIZEOF_VOID_P == 8 ? 64 : 1) |
#define | GetBufferDescriptor(id) (&BufferDescriptors[(id)].bufferdesc) |
#define | GetLocalBufferDescriptor(id) (&LocalBufferDescriptors[(id)]) |
#define | BufferDescriptorGetBuffer(bdesc) ((bdesc)->buf_id + 1) |
#define | BufferDescriptorGetIOCV(bdesc) (&(BufferIOCVArray[(bdesc)->buf_id]).cv) |
#define | BufferDescriptorGetContentLock(bdesc) ((LWLock*) (&(bdesc)->content_lock)) |
#define | FREENEXT_END_OF_LIST (-1) |
#define | FREENEXT_NOT_IN_LIST (-2) |
#define | UnlockBufHdr(desc, s) |
Typedefs | |
typedef struct buftag | BufferTag |
typedef struct BufferDesc | BufferDesc |
typedef union BufferDescPadded | BufferDescPadded |
typedef struct PendingWriteback | PendingWriteback |
typedef struct WritebackContext | WritebackContext |
typedef struct CkptSortItem | CkptSortItem |
#define BM_CHECKPOINT_NEEDED (1U << 30) /* must write for checkpoint */ |
Definition at line 66 of file buf_internals.h.
#define BM_DIRTY (1U << 23) /* data needs writing */ |
Definition at line 59 of file buf_internals.h.
#define BM_IO_ERROR (1U << 27) /* previous I/O failed */ |
Definition at line 63 of file buf_internals.h.
Definition at line 62 of file buf_internals.h.
#define BM_JUST_DIRTIED (1U << 28) /* dirtied since write started */ |
Definition at line 64 of file buf_internals.h.
#define BM_LOCKED (1U << 22) /* buffer header is locked */ |
Definition at line 58 of file buf_internals.h.
#define BM_MAX_USAGE_COUNT 5 |
Definition at line 76 of file buf_internals.h.
#define BM_PERMANENT |
Definition at line 67 of file buf_internals.h.
#define BM_PIN_COUNT_WAITER (1U << 29) /* have waiter for sole pin */ |
Definition at line 65 of file buf_internals.h.
#define BM_TAG_VALID (1U << 25) /* tag is assigned */ |
Definition at line 61 of file buf_internals.h.
#define BM_VALID (1U << 24) /* data is valid */ |
Definition at line 60 of file buf_internals.h.
#define BUF_FLAG_MASK 0xFFC00000U |
Definition at line 46 of file buf_internals.h.
#define BUF_REFCOUNT_MASK ((1U << 18) - 1) |
Definition at line 42 of file buf_internals.h.
#define BUF_REFCOUNT_ONE 1 |
Definition at line 41 of file buf_internals.h.
#define BUF_STATE_GET_REFCOUNT | ( | state | ) | ((state) & BUF_REFCOUNT_MASK) |
Definition at line 49 of file buf_internals.h.
#define BUF_STATE_GET_USAGECOUNT | ( | state | ) | (((state) & BUF_USAGECOUNT_MASK) >> BUF_USAGECOUNT_SHIFT) |
Definition at line 50 of file buf_internals.h.
#define BUF_USAGECOUNT_MASK 0x003C0000U |
Definition at line 43 of file buf_internals.h.
#define BUF_USAGECOUNT_ONE (1U << 18) |
Definition at line 44 of file buf_internals.h.
#define BUF_USAGECOUNT_SHIFT 18 |
Definition at line 45 of file buf_internals.h.
#define BUFFERDESC_PAD_TO_SIZE (SIZEOF_VOID_P == 8 ? 64 : 1) |
Definition at line 214 of file buf_internals.h.
#define BufferDescriptorGetBuffer | ( | bdesc | ) | ((bdesc)->buf_id + 1) |
Definition at line 225 of file buf_internals.h.
#define BufferDescriptorGetContentLock | ( | bdesc | ) | ((LWLock*) (&(bdesc)->content_lock)) |
Definition at line 229 of file buf_internals.h.
#define BufferDescriptorGetIOCV | ( | bdesc | ) | (&(BufferIOCVArray[(bdesc)->buf_id]).cv) |
Definition at line 227 of file buf_internals.h.
#define BufMappingPartitionLock | ( | hashcode | ) |
Definition at line 128 of file buf_internals.h.
#define BufMappingPartitionLockByIndex | ( | i | ) | (&MainLWLockArray[BUFFER_MAPPING_LWLOCK_OFFSET + (i)].lock) |
Definition at line 131 of file buf_internals.h.
#define BufTableHashPartition | ( | hashcode | ) | ((hashcode) % NUM_BUFFER_PARTITIONS) |
Definition at line 126 of file buf_internals.h.
#define CLEAR_BUFFERTAG | ( | a | ) |
Definition at line 97 of file buf_internals.h.
#define FREENEXT_END_OF_LIST (-1) |
Definition at line 238 of file buf_internals.h.
#define FREENEXT_NOT_IN_LIST (-2) |
Definition at line 239 of file buf_internals.h.
#define GetBufferDescriptor | ( | id | ) | (&BufferDescriptors[(id)].bufferdesc) |
Definition at line 222 of file buf_internals.h.
#define GetLocalBufferDescriptor | ( | id | ) | (&LocalBufferDescriptors[(id)]) |
Definition at line 223 of file buf_internals.h.
#define INIT_BUFFERTAG | ( | a, | |
xx_rlocator, | |||
xx_forkNum, | |||
xx_blockNum | |||
) |
Definition at line 106 of file buf_internals.h.
#define UnlockBufHdr | ( | desc, | |
s | |||
) |
Definition at line 246 of file buf_internals.h.
typedef struct BufferDesc BufferDesc |
typedef union BufferDescPadded BufferDescPadded |
typedef struct CkptSortItem CkptSortItem |
typedef struct PendingWriteback PendingWriteback |
typedef struct WritebackContext WritebackContext |
void AtEOXact_LocalBuffers | ( | bool | isCommit | ) |
Definition at line 577 of file localbuf.c.
References CheckForLocalBufferLeaks().
Referenced by AtEOXact_Buffers().
Definition at line 149 of file buf_table.c.
References elog(), ERROR, HASH_REMOVE, hash_search_with_hash_value(), and SharedBufHash.
Referenced by BufferAlloc(), and InvalidateBuffer().
Definition at line 79 of file buf_table.c.
References get_hash_value(), and SharedBufHash.
Referenced by BufferAlloc(), FindAndDropRelFileLocatorBuffers(), InvalidateBuffer(), and PrefetchSharedBuffer().
Definition at line 119 of file buf_table.c.
References Assert(), buftag::blockNum, HASH_ENTER, hash_search_with_hash_value(), BufferLookupEnt::id, P_NEW, and SharedBufHash.
Referenced by BufferAlloc().
Definition at line 91 of file buf_table.c.
References HASH_FIND, hash_search_with_hash_value(), BufferLookupEnt::id, and SharedBufHash.
Referenced by BufferAlloc(), FindAndDropRelFileLocatorBuffers(), and PrefetchSharedBuffer().
Size BufTableShmemSize | ( | int | size | ) |
Definition at line 42 of file buf_table.c.
References hash_estimate_size().
Referenced by StrategyShmemSize().
void DropRelFileLocatorAllLocalBuffers | ( | RelFileLocator | rlocator | ) |
Definition at line 373 of file localbuf.c.
References buftag::blockNum, BM_TAG_VALID, BUF_FLAG_MASK, BUF_USAGECOUNT_MASK, CLEAR_BUFFERTAG, elog(), ERROR, buftag::forkNum, GetLocalBufferDescriptor, HASH_REMOVE, hash_search(), i, LocalBufHash, LocalRefCount, MyBackendId, NLocBuffer, pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), RelFileLocatorEquals, relpathbackend, buftag::rlocator, BufferDesc::state, and BufferDesc::tag.
Referenced by DropRelFileLocatorsAllBuffers().
void DropRelFileLocatorLocalBuffers | ( | RelFileLocator | rlocator, |
ForkNumber | forkNum, | ||
BlockNumber | firstDelBlock | ||
) |
Definition at line 326 of file localbuf.c.
References buftag::blockNum, BM_TAG_VALID, BUF_FLAG_MASK, BUF_USAGECOUNT_MASK, CLEAR_BUFFERTAG, elog(), ERROR, buftag::forkNum, GetLocalBufferDescriptor, HASH_REMOVE, hash_search(), i, LocalBufHash, LocalRefCount, MyBackendId, NLocBuffer, pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), RelFileLocatorEquals, relpathbackend, buftag::rlocator, BufferDesc::state, and BufferDesc::tag.
Referenced by DropRelFileLocatorBuffers().
bool have_free_buffer | ( | void | ) |
Definition at line 180 of file freelist.c.
References BufferStrategyControl::firstFreeBuffer, and StrategyControl.
Referenced by apw_load_buffers(), and autoprewarm_database_main().
void InitBufTable | ( | int | size | ) |
Definition at line 52 of file buf_table.c.
References HASHCTL::entrysize, HASH_BLOBS, HASH_ELEM, HASH_PARTITION, HASHCTL::keysize, NUM_BUFFER_PARTITIONS, HASHCTL::num_partitions, SharedBufHash, and ShmemInitHash().
Referenced by StrategyInitialize().
void IssuePendingWritebacks | ( | WritebackContext * | context | ) |
Definition at line 4924 of file bufmgr.c.
References buftag::blockNum, cur, buftag::forkNum, i, InvalidBackendId, next, WritebackContext::nr_pending, WritebackContext::pending_writebacks, RelFileLocatorEquals, buftag::rlocator, smgropen(), and smgrwriteback().
Referenced by BufferSync(), and ScheduleBufferTagForWriteback().
BufferDesc* LocalBufferAlloc | ( | SMgrRelation | smgr, |
ForkNumber | forkNum, | ||
BlockNumber | blockNum, | ||
bool * | foundPtr | ||
) |
Definition at line 109 of file localbuf.c.
References Assert(), b, buftag::blockNum, BM_DIRTY, BM_IO_ERROR, BM_JUST_DIRTIED, BM_MAX_USAGE_COUNT, BM_TAG_VALID, BM_VALID, BUF_STATE_GET_USAGECOUNT, BUF_USAGECOUNT_MASK, BUF_USAGECOUNT_ONE, BufferDescriptorGetBuffer, BUFFERTAGS_EQUAL, CLEAR_BUFFERTAG, CurrentResourceOwner, elog(), ereport, errcode(), errmsg(), ERROR, buftag::forkNum, fprintf, GetLocalBufferDescriptor, GetLocalBufferStorage(), HASH_ENTER, HASH_FIND, HASH_REMOVE, hash_search(), LocalBufferLookupEnt::id, INIT_BUFFERTAG, InitLocalBuffers(), BufferUsage::local_blks_written, LocalBufHash, LocalBufHdrGetBlock, LocalRefCount, RelFileLocatorBackend::locator, MyBackendId, nextFreeLocalBuf, NLocBuffer, PageSetChecksumInplace(), pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), pgBufferUsage, RelFileLocator::relNumber, ResourceOwnerRememberBuffer(), buftag::rlocator, SMgrRelationData::smgr_rlocator, smgropen(), smgrwrite(), BufferDesc::state, and BufferDesc::tag.
Referenced by ReadBuffer_common().
uint32 LockBufHdr | ( | BufferDesc * | desc | ) |
Definition at line 4736 of file bufmgr.c.
References BM_LOCKED, finish_spin_delay(), init_local_spin_delay, perform_spin_delay(), pg_atomic_fetch_or_u32(), and BufferDesc::state.
Referenced by AbortBufferIO(), apw_dump_now(), BufferAlloc(), BufferGetLSNAtomic(), BufferSync(), ConditionalLockBufferForCleanup(), DropDatabaseBuffers(), DropRelFileLocatorBuffers(), DropRelFileLocatorsAllBuffers(), FindAndDropRelFileLocatorBuffers(), FlushBuffer(), FlushDatabaseBuffers(), FlushRelationBuffers(), FlushRelationsAllBuffers(), GetBufferFromRing(), InvalidateBuffer(), IsBufferCleanupOK(), LockBufferForCleanup(), MarkBufferDirtyHint(), pg_buffercache_pages(), ReadBuffer_common(), ReadRecentBuffer(), StartBufferIO(), StrategyGetBuffer(), SyncOneBuffer(), TerminateBufferIO(), UnlockBuffers(), UnpinBuffer(), and WaitIO().
void MarkLocalBufferDirty | ( | Buffer | buffer | ) |
Definition at line 286 of file localbuf.c.
References Assert(), BM_DIRTY, BufferIsLocal, fprintf, GetLocalBufferDescriptor, BufferUsage::local_blks_dirtied, LocalRefCount, pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), pgBufferUsage, and BufferDesc::state.
Referenced by MarkBufferDirty(), and MarkBufferDirtyHint().
PrefetchBufferResult PrefetchLocalBuffer | ( | SMgrRelation | smgr, |
ForkNumber | forkNum, | ||
BlockNumber | blockNum | ||
) |
Definition at line 64 of file localbuf.c.
References HASH_FIND, hash_search(), LocalBufferLookupEnt::id, INIT_BUFFERTAG, PrefetchBufferResult::initiated_io, InitLocalBuffers(), InvalidBuffer, LocalBufHash, RelFileLocatorBackend::locator, PrefetchBufferResult::recent_buffer, SMgrRelationData::smgr_rlocator, and smgrprefetch().
Referenced by PrefetchBuffer().
void ScheduleBufferTagForWriteback | ( | WritebackContext * | context, |
BufferTag * | tag | ||
) |
Definition at line 4883 of file bufmgr.c.
References Assert(), IssuePendingWritebacks(), WritebackContext::max_pending, WritebackContext::nr_pending, WritebackContext::pending_writebacks, PendingWriteback::tag, and WRITEBACK_MAX_PENDING_FLUSHES.
Referenced by BufferAlloc(), and SyncOneBuffer().
void StrategyFreeBuffer | ( | BufferDesc * | buf | ) |
Definition at line 363 of file freelist.c.
References buf, BufferStrategyControl::buffer_strategy_lock, BufferStrategyControl::firstFreeBuffer, FREENEXT_NOT_IN_LIST, BufferStrategyControl::lastFreeBuffer, SpinLockAcquire, SpinLockRelease, and StrategyControl.
Referenced by InvalidateBuffer().
BufferDesc* StrategyGetBuffer | ( | BufferAccessStrategy | strategy, |
uint32 * | buf_state | ||
) |
Definition at line 201 of file freelist.c.
References AddBufferToRing(), PROC_HDR::allProcs, Assert(), BufferStrategyControl::bgwprocno, buf, BUF_STATE_GET_REFCOUNT, BUF_STATE_GET_USAGECOUNT, BUF_USAGECOUNT_ONE, BufferStrategyControl::buffer_strategy_lock, ClockSweepTick(), elog(), ERROR, BufferStrategyControl::firstFreeBuffer, FREENEXT_NOT_IN_LIST, GetBufferDescriptor, GetBufferFromRing(), INT_ACCESS_ONCE, LockBufHdr(), NBuffers, BufferStrategyControl::numBufferAllocs, pg_atomic_fetch_add_u32(), ProcGlobal, PGPROC::procLatch, SetLatch(), SpinLockAcquire, SpinLockRelease, StrategyControl, and UnlockBufHdr.
Referenced by BufferAlloc().
void StrategyInitialize | ( | bool | init | ) |
Definition at line 474 of file freelist.c.
References Assert(), BufferStrategyControl::bgwprocno, BufferStrategyControl::buffer_strategy_lock, BufferStrategyControl::completePasses, BufferStrategyControl::firstFreeBuffer, init, InitBufTable(), BufferStrategyControl::lastFreeBuffer, NBuffers, BufferStrategyControl::nextVictimBuffer, NUM_BUFFER_PARTITIONS, BufferStrategyControl::numBufferAllocs, pg_atomic_init_u32(), ShmemInitStruct(), SpinLockInit, and StrategyControl.
Referenced by InitBufferPool().
void StrategyNotifyBgWriter | ( | int | bgwprocno | ) |
Definition at line 431 of file freelist.c.
References BufferStrategyControl::bgwprocno, BufferStrategyControl::buffer_strategy_lock, SpinLockAcquire, SpinLockRelease, and StrategyControl.
Referenced by BackgroundWriterMain().
bool StrategyRejectBuffer | ( | BufferAccessStrategy | strategy, |
BufferDesc * | buf | ||
) |
Definition at line 685 of file freelist.c.
References BAS_BULKREAD, BufferAccessStrategyData::btype, buf, BufferDescriptorGetBuffer, BufferAccessStrategyData::buffers, BufferAccessStrategyData::current, BufferAccessStrategyData::current_was_in_ring, and InvalidBuffer.
Referenced by BufferAlloc().
Size StrategyShmemSize | ( | void | ) |
Definition at line 453 of file freelist.c.
References add_size(), BufTableShmemSize(), MAXALIGN, NBuffers, and NUM_BUFFER_PARTITIONS.
Referenced by BufferShmemSize().
Definition at line 394 of file freelist.c.
References BufferStrategyControl::buffer_strategy_lock, BufferStrategyControl::completePasses, NBuffers, BufferStrategyControl::nextVictimBuffer, BufferStrategyControl::numBufferAllocs, pg_atomic_exchange_u32(), pg_atomic_read_u32(), SpinLockAcquire, SpinLockRelease, and StrategyControl.
Referenced by BgBufferSync().
void WritebackContextInit | ( | WritebackContext * | context, |
int * | max_pending | ||
) |
Definition at line 4871 of file bufmgr.c.
References Assert(), WritebackContext::max_pending, WritebackContext::nr_pending, and WRITEBACK_MAX_PENDING_FLUSHES.
Referenced by BackgroundWriterMain(), BufferSync(), and InitBufferPool().
|
extern |
Definition at line 24 of file buf_init.c.
Referenced by BufferAlloc(), and InitBufferPool().
|
extern |
Definition at line 21 of file buf_init.c.
Referenced by InitBufferPool().
|
extern |
Definition at line 23 of file buf_init.c.
Referenced by InitBufferPool().
|
extern |
Definition at line 25 of file buf_init.c.
Referenced by BufferSync(), and InitBufferPool().
|
extern |
Definition at line 43 of file localbuf.c.
Referenced by InitLocalBuffers().