PostgreSQL Source Code git master
|
#include "postgres.h"
#include "access/parallel.h"
#include "executor/instrument.h"
#include "pgstat.h"
#include "storage/aio.h"
#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
#include "storage/fd.h"
#include "utils/guc_hooks.h"
#include "utils/memdebug.h"
#include "utils/memutils.h"
#include "utils/resowner.h"
Go to the source code of this file.
Data Structures | |
struct | LocalBufferLookupEnt |
Macros | |
#define | LocalBufHdrGetBlock(bufHdr) LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)] |
Variables | |
int | NLocBuffer = 0 |
BufferDesc * | LocalBufferDescriptors = NULL |
Block * | LocalBufferBlockPointers = NULL |
int32 * | LocalRefCount = NULL |
static int | nextFreeLocalBufId = 0 |
static HTAB * | LocalBufHash = NULL |
static int | NLocalPinnedBuffers = 0 |
#define LocalBufHdrGetBlock | ( | bufHdr | ) | LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)] |
Definition at line 41 of file localbuf.c.
void AtEOXact_LocalBuffers | ( | bool | isCommit | ) |
Definition at line 993 of file localbuf.c.
References CheckForLocalBufferLeaks().
Referenced by AtEOXact_Buffers().
void AtProcExit_LocalBuffers | ( | void | ) |
Definition at line 1004 of file localbuf.c.
References CheckForLocalBufferLeaks().
Referenced by AtProcExit_Buffers().
bool check_temp_buffers | ( | int * | newval, |
void ** | extra, | ||
GucSource | source | ||
) |
Definition at line 868 of file localbuf.c.
References GUC_check_errdetail, newval, NLocBuffer, PGC_S_TEST, and source.
|
static |
Definition at line 960 of file localbuf.c.
References Assert(), b, DebugPrintBufferRefcount(), elog, i, LocalRefCount, NLocBuffer, pfree(), and WARNING.
Referenced by AtEOXact_LocalBuffers(), and AtProcExit_LocalBuffers().
void DropRelationAllLocalBuffers | ( | RelFileLocator | rlocator | ) |
Definition at line 693 of file localbuf.c.
References BM_TAG_VALID, BufTagMatchesRelFileLocator(), GetLocalBufferDescriptor(), i, InvalidateLocalBuffer(), NLocBuffer, pg_atomic_read_u32(), BufferDesc::state, and BufferDesc::tag.
Referenced by DropRelationsAllBuffers().
void DropRelationLocalBuffers | ( | RelFileLocator | rlocator, |
ForkNumber | forkNum, | ||
BlockNumber | firstDelBlock | ||
) |
Definition at line 663 of file localbuf.c.
References buftag::blockNum, BM_TAG_VALID, BufTagGetForkNum(), BufTagMatchesRelFileLocator(), GetLocalBufferDescriptor(), i, InvalidateLocalBuffer(), NLocBuffer, pg_atomic_read_u32(), BufferDesc::state, and BufferDesc::tag.
Referenced by DropRelationBuffers().
BlockNumber ExtendBufferedRelLocal | ( | BufferManagerRelation | bmr, |
ForkNumber | fork, | ||
uint32 | flags, | ||
uint32 | extend_by, | ||
BlockNumber | extend_upto, | ||
Buffer * | buffers, | ||
uint32 * | extended_by | ||
) |
Definition at line 345 of file localbuf.c.
References Assert(), BM_DIRTY, BM_JUST_DIRTIED, BM_TAG_VALID, BM_VALID, buf, BUF_USAGECOUNT_ONE, BufferDescriptorGetBuffer(), CurrentResourceOwner, ereport, errcode(), errmsg(), ERROR, GetLocalBufferDescriptor(), GetLocalVictimBuffer(), HASH_ENTER, hash_search(), i, LocalBufferLookupEnt::id, InitBufferTag(), InitLocalBuffers(), InvalidBlockNumber, IOCONTEXT_NORMAL, IOOBJECT_TEMP_RELATION, IOOP_EXTEND, LimitAdditionalLocalPins(), BufferUsage::local_blks_written, LocalBufHash, LocalBufHdrGetBlock, RelFileLocatorBackend::locator, MaxBlockNumber, MemSet, pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), pgBufferUsage, pgstat_count_io_op_time(), pgstat_prepare_io_time(), PinLocalBuffer(), relpath, ResourceOwnerEnlarge(), BufferManagerRelation::smgr, SMgrRelationData::smgr_rlocator, smgrnblocks(), smgrzeroextend(), StartLocalBufferIO(), BufferDesc::state, BufferDesc::tag, track_io_timing, and UnpinLocalBuffer().
Referenced by ExtendBufferedRelCommon().
void FlushLocalBuffer | ( | BufferDesc * | bufHdr, |
SMgrRelation | reln | ||
) |
Definition at line 182 of file localbuf.c.
References Assert(), buftag::blockNum, BufferDescriptorGetBuffer(), BufTagGetForkNum(), BufTagGetRelFileLocator(), elog, ERROR, IOCONTEXT_NORMAL, IOOBJECT_TEMP_RELATION, IOOP_WRITE, BufferUsage::local_blks_written, LocalBufHdrGetBlock, LocalRefCount, MyProcNumber, PageSetChecksumInplace(), pgBufferUsage, pgstat_count_io_op_time(), pgstat_prepare_io_time(), smgropen(), smgrwrite(), StartLocalBufferIO(), BufferDesc::tag, TerminateLocalBufferIO(), and track_io_timing.
Referenced by FlushRelationBuffers(), GetLocalVictimBuffer(), and invalidate_rel_block().
uint32 GetAdditionalLocalPinLimit | ( | void | ) |
Definition at line 314 of file localbuf.c.
References Assert(), NLocalPinnedBuffers, and num_temp_buffers.
Referenced by read_stream_start_pending_read().
|
static |
Definition at line 892 of file localbuf.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), Max, MaxAllocSize, MemoryContextAlloc(), Min, NLocBuffer, PG_IO_ALIGN_SIZE, TopMemoryContext, TYPEALIGN, and VALGRIND_MAKE_MEM_DEFINED.
Referenced by GetLocalVictimBuffer().
uint32 GetLocalPinLimit | ( | void | ) |
Definition at line 306 of file localbuf.c.
References num_temp_buffers.
Referenced by read_stream_begin_impl().
|
static |
Definition at line 223 of file localbuf.c.
References BM_DIRTY, BM_TAG_VALID, BUF_STATE_GET_REFCOUNT, BUF_STATE_GET_USAGECOUNT, BUF_USAGECOUNT_ONE, BufferDescriptorGetBuffer(), CurrentResourceOwner, ereport, errcode(), errmsg(), ERROR, FlushLocalBuffer(), GetLocalBufferDescriptor(), GetLocalBufferStorage(), InvalidateLocalBuffer(), IOCONTEXT_NORMAL, IOOBJECT_TEMP_RELATION, IOOP_EVICT, LocalBufHdrGetBlock, LocalRefCount, nextFreeLocalBufId, NLocBuffer, pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), pgstat_count_io_op(), PinLocalBuffer(), ResourceOwnerEnlarge(), and BufferDesc::state.
Referenced by ExtendBufferedRelLocal(), and LocalBufferAlloc().
|
static |
Definition at line 719 of file localbuf.c.
References buf, calloc, elog, HASHCTL::entrysize, ereport, errcode(), errmsg(), ERROR, FATAL, GetLocalBufferDescriptor(), HASH_BLOBS, hash_create(), HASH_ELEM, i, IsParallelWorker, HASHCTL::keysize, LocalBufferBlockPointers, LocalBufferDescriptors, LocalBufHash, LocalRefCount, nextFreeLocalBufId, NLocBuffer, num_temp_buffers, and pgaio_wref_clear().
Referenced by ExtendBufferedRelLocal(), LocalBufferAlloc(), and PrefetchLocalBuffer().
void InvalidateLocalBuffer | ( | BufferDesc * | bufHdr, |
bool | check_unreferenced | ||
) |
Definition at line 603 of file localbuf.c.
References Assert(), buftag::blockNum, BUF_STATE_GET_REFCOUNT, BufferDescriptorGetBuffer(), BufTagGetForkNum(), BufTagGetRelFileLocator(), ClearBufferTag(), elog, ERROR, HASH_REMOVE, hash_search(), BufferDesc::io_wref, LocalBufHash, LocalRefCount, MyProcNumber, pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), pgaio_wref_valid(), pgaio_wref_wait(), relpathbackend, BufferDesc::state, and BufferDesc::tag.
Referenced by DropRelationAllLocalBuffers(), DropRelationLocalBuffers(), GetLocalVictimBuffer(), invalidate_rel_block(), and modify_rel_block().
void LimitAdditionalLocalPins | ( | uint32 * | additional_pins | ) |
Definition at line 322 of file localbuf.c.
References NLocalPinnedBuffers, and num_temp_buffers.
Referenced by ExtendBufferedRelLocal().
BufferDesc * LocalBufferAlloc | ( | SMgrRelation | smgr, |
ForkNumber | forkNum, | ||
BlockNumber | blockNum, | ||
bool * | foundPtr | ||
) |
Definition at line 118 of file localbuf.c.
References Assert(), BM_TAG_VALID, BUF_FLAG_MASK, BUF_USAGECOUNT_MASK, BUF_USAGECOUNT_ONE, BufferTagsEqual(), CurrentResourceOwner, elog, ERROR, GetLocalBufferDescriptor(), GetLocalVictimBuffer(), HASH_ENTER, HASH_FIND, hash_search(), LocalBufferLookupEnt::id, InitBufferTag(), InitLocalBuffers(), LocalBufHash, RelFileLocatorBackend::locator, pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), PinLocalBuffer(), ResourceOwnerEnlarge(), SMgrRelationData::smgr_rlocator, BufferDesc::state, and BufferDesc::tag.
Referenced by PinBufferForBlock().
void MarkLocalBufferDirty | ( | Buffer | buffer | ) |
Definition at line 489 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().
bool PinLocalBuffer | ( | BufferDesc * | buf_hdr, |
bool | adjust_usagecount | ||
) |
Definition at line 796 of file localbuf.c.
References BM_MAX_USAGE_COUNT, BM_VALID, BUF_REFCOUNT_ONE, BUF_STATE_GET_USAGECOUNT, BUF_USAGECOUNT_ONE, BufferDescriptorGetBuffer(), CurrentResourceOwner, LocalBufHdrGetBlock, LocalRefCount, NLocalPinnedBuffers, pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), ResourceOwnerRememberBuffer(), BufferDesc::state, and VALGRIND_MAKE_MEM_DEFINED.
Referenced by ExtendBufferedRelLocal(), FlushRelationBuffers(), GetLocalVictimBuffer(), LocalBufferAlloc(), and ReadRecentBuffer().
PrefetchBufferResult PrefetchLocalBuffer | ( | SMgrRelation | smgr, |
ForkNumber | forkNum, | ||
BlockNumber | blockNum | ||
) |
Definition at line 71 of file localbuf.c.
References HASH_FIND, hash_search(), LocalBufferLookupEnt::id, InitBufferTag(), PrefetchBufferResult::initiated_io, InitLocalBuffers(), InvalidBuffer, IO_DIRECT_DATA, io_direct_flags, LocalBufHash, RelFileLocatorBackend::locator, PrefetchBufferResult::recent_buffer, SMgrRelationData::smgr_rlocator, and smgrprefetch().
Referenced by PrefetchBuffer().
bool StartLocalBufferIO | ( | BufferDesc * | bufHdr, |
bool | forInput, | ||
bool | nowait | ||
) |
Definition at line 521 of file localbuf.c.
References BM_DIRTY, BM_VALID, BufferDesc::io_wref, pg_atomic_read_u32(), pgaio_wref_valid(), pgaio_wref_wait(), and BufferDesc::state.
Referenced by buffer_call_start_io(), ExtendBufferedRelLocal(), FlushLocalBuffer(), read_rel_block_ll(), ReadBuffersCanStartIOOnce(), and ZeroAndLockBuffer().
void TerminateLocalBufferIO | ( | BufferDesc * | bufHdr, |
bool | clear_dirty, | ||
uint32 | set_flag_bits, | ||
bool | release_aio | ||
) |
Definition at line 560 of file localbuf.c.
References Assert(), BUF_REFCOUNT_ONE, BUF_STATE_GET_REFCOUNT, BufferDesc::io_wref, pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), pgaio_wref_clear(), and BufferDesc::state.
Referenced by buffer_call_terminate_io(), buffer_readv_complete_one(), FlushLocalBuffer(), and ZeroAndLockBuffer().
void UnpinLocalBuffer | ( | Buffer | buffer | ) |
Definition at line 832 of file localbuf.c.
References CurrentResourceOwner, ResourceOwnerForgetBuffer(), and UnpinLocalBufferNoOwner().
Referenced by ExtendBufferedRelLocal(), FlushRelationBuffers(), ReleaseAndReadBuffer(), and ReleaseBuffer().
void UnpinLocalBufferNoOwner | ( | Buffer | buffer | ) |
Definition at line 839 of file localbuf.c.
References Assert(), BUF_REFCOUNT_ONE, BUF_STATE_GET_REFCOUNT, BufferIsLocal, GetLocalBufferDescriptor(), LocalBufHdrGetBlock, LocalRefCount, NLocalPinnedBuffers, pg_atomic_read_u32(), pg_atomic_unlocked_write_u32(), BufferDesc::state, and VALGRIND_MAKE_MEM_NOACCESS.
Referenced by ResOwnerReleaseBufferPin(), and UnpinLocalBuffer().
Block* LocalBufferBlockPointers = NULL |
Definition at line 47 of file localbuf.c.
Referenced by BufferGetBlock(), and InitLocalBuffers().
BufferDesc* LocalBufferDescriptors = NULL |
Definition at line 46 of file localbuf.c.
Referenced by GetLocalBufferDescriptor(), and InitLocalBuffers().
|
static |
Definition at line 52 of file localbuf.c.
Referenced by ExtendBufferedRelLocal(), InitLocalBuffers(), InvalidateLocalBuffer(), LocalBufferAlloc(), and PrefetchLocalBuffer().
int32* LocalRefCount = NULL |
Definition at line 48 of file localbuf.c.
Referenced by CheckBufferIsPinnedOnce(), CheckForLocalBufferLeaks(), ConditionalLockBufferForCleanup(), DebugPrintBufferRefcount(), FlushLocalBuffer(), GetLocalVictimBuffer(), IncrBufferRefCount(), InitLocalBuffers(), InvalidateLocalBuffer(), IsBufferCleanupOK(), MarkLocalBufferDirty(), PinLocalBuffer(), and UnpinLocalBufferNoOwner().
|
static |
Definition at line 50 of file localbuf.c.
Referenced by GetLocalVictimBuffer(), and InitLocalBuffers().
|
static |
Definition at line 55 of file localbuf.c.
Referenced by GetAdditionalLocalPinLimit(), LimitAdditionalLocalPins(), PinLocalBuffer(), and UnpinLocalBufferNoOwner().
int NLocBuffer = 0 |
Definition at line 44 of file localbuf.c.
Referenced by BufferIsValid(), check_temp_buffers(), CheckForLocalBufferLeaks(), DropRelationAllLocalBuffers(), DropRelationLocalBuffers(), FlushRelationBuffers(), GetLocalBufferStorage(), GetLocalVictimBuffer(), hashbuild(), and InitLocalBuffers().