39 #define LocalBufHdrGetBlock(bufHdr) \
40 LocalBufferBlockPointers[-((bufHdr)->buf_id + 2)]
150 bufid = -victim_buffer - 1;
156 elog(
ERROR,
"local buffer hash table corrupted");
162 bufHdr->
tag = newTag;
216 else if (--trycounter == 0)
218 (
errcode(ERRCODE_INSUFFICIENT_RESOURCES),
219 errmsg(
"no empty local buffer available")));
276 elog(
ERROR,
"local buffer hash table corrupted");
293 if (*additional_pins <= 1)
302 if (*additional_pins >= max_pins)
303 *additional_pins = max_pins;
338 MemSet((
char *) buf_block, 0, BLCKSZ);
350 Assert(first_block <= extend_upto);
352 Assert((uint64) first_block + extend_by <= extend_upto);
358 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
359 errmsg(
"cannot extend relation %s beyond %u blocks",
371 victim_buf_id = -buffers[
i] - 1;
401 victim_buf_hdr->
tag = tag;
407 hresult->
id = victim_buf_id;
417 io_start, extend_by);
432 *extended_by = extend_by;
453 fprintf(stderr,
"LB DIRTY %d\n", buffer);
503 elog(
ERROR,
"block %u of %s is still referenced (local %u)",
514 elog(
ERROR,
"local buffer hash table corrupted");
548 elog(
ERROR,
"block %u of %s is still referenced (local %u)",
558 elog(
ERROR,
"local buffer hash table corrupted");
591 (
errcode(ERRCODE_INVALID_TRANSACTION_STATE),
592 errmsg(
"cannot access temporary tables during a parallel operation")));
600 (
errcode(ERRCODE_OUT_OF_MEMORY),
601 errmsg(
"out of memory")));
606 for (
i = 0;
i < nbufs;
i++)
616 buf->buf_id = -
i - 2;
636 elog(
ERROR,
"could not initialize local buffer hash table");
652 int bufid = -buffer - 1;
659 if (adjust_usagecount &&
676 int buffid = -buffer - 1;
699 GUC_check_errdetail(
"\"temp_buffers\" cannot be changed after any temporary tables have been accessed in the session.");
717 static char *cur_block = NULL;
718 static int next_buf_in_block = 0;
719 static int num_bufs_in_block = 0;
720 static int total_bufs_allocated = 0;
727 if (next_buf_in_block >= num_bufs_in_block)
737 if (LocalBufferContext == NULL)
740 "LocalBufferContext",
744 num_bufs =
Max(num_bufs_in_block * 2, 16);
755 next_buf_in_block = 0;
756 num_bufs_in_block = num_bufs;
760 this_buf = cur_block + next_buf_in_block * BLCKSZ;
762 total_bufs_allocated++;
764 return (
Block) this_buf;
775 #ifdef USE_ASSERT_CHECKING
778 int RefCountErrors = 0;
791 Assert(RefCountErrors == 0);
static void pg_atomic_unlocked_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
#define InvalidBlockNumber
#define BufferIsLocal(buffer)
#define BM_MAX_USAGE_COUNT
static void InitBufferTag(BufferTag *tag, const RelFileLocator *rlocator, ForkNumber forkNum, BlockNumber blockNum)
#define BUF_USAGECOUNT_MASK
static ForkNumber BufTagGetForkNum(const BufferTag *tag)
static BufferDesc * GetLocalBufferDescriptor(uint32 id)
static bool BufferTagsEqual(const BufferTag *tag1, const BufferTag *tag2)
static bool BufTagMatchesRelFileLocator(const BufferTag *tag, const RelFileLocator *rlocator)
#define BUF_STATE_GET_USAGECOUNT(state)
static void ClearBufferTag(BufferTag *tag)
#define BUF_USAGECOUNT_ONE
static RelFileLocator BufTagGetRelFileLocator(const BufferTag *tag)
static Buffer BufferDescriptorGetBuffer(const BufferDesc *bdesc)
void PrintBufferLeakWarning(Buffer buffer)
void PageSetChecksumInplace(Page page, BlockNumber blkno)
#define TYPEALIGN(ALIGNVAL, LEN)
#define MemSet(start, val, len)
elog(ERROR, "%s: %s", p2, msg)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define GUC_check_errdetail
#define IsParallelWorker()
BufferUsage pgBufferUsage
Assert(fmt[strlen(fmt) - 1] !='\n')
void UnpinLocalBuffer(Buffer buffer)
BufferDesc * LocalBufferAlloc(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum, bool *foundPtr)
static HTAB * LocalBufHash
static int NLocalPinnedBuffers
void AtEOXact_LocalBuffers(bool isCommit)
#define LocalBufHdrGetBlock(bufHdr)
static void CheckForLocalBufferLeaks(void)
void DropRelationLocalBuffers(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber firstDelBlock)
static Block GetLocalBufferStorage(void)
static void LimitAdditionalLocalPins(uint32 *additional_pins)
static int nextFreeLocalBufId
bool check_temp_buffers(int *newval, void **extra, GucSource source)
void AtProcExit_LocalBuffers(void)
bool PinLocalBuffer(BufferDesc *buf_hdr, bool adjust_usagecount)
static void InitLocalBuffers(void)
static Buffer GetLocalVictimBuffer(void)
void MarkLocalBufferDirty(Buffer buffer)
void DropRelationAllLocalBuffers(RelFileLocator rlocator)
PrefetchBufferResult PrefetchLocalBuffer(SMgrRelation smgr, ForkNumber forkNum, BlockNumber blockNum)
BlockNumber ExtendBufferedRelLocal(BufferManagerRelation bmr, ForkNumber fork, uint32 flags, uint32 extend_by, BlockNumber extend_upto, Buffer *buffers, uint32 *extended_by)
Block * LocalBufferBlockPointers
BufferDesc * LocalBufferDescriptors
MemoryContext TopMemoryContext
void * MemoryContextAlloc(MemoryContext context, Size size)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
static rewind_source * source
void pgstat_count_io_op_time(IOObject io_object, IOContext io_context, IOOp io_op, instr_time start_time, uint32 cnt)
instr_time pgstat_prepare_io_time(void)
void pgstat_count_io_op(IOObject io_object, IOContext io_context, IOOp io_op)
#define relpath(rlocator, forknum)
#define relpathbackend(rlocator, backend, forknum)
void ResourceOwnerForgetBuffer(ResourceOwner owner, Buffer buffer)
ResourceOwner CurrentResourceOwner
void ResourceOwnerEnlargeBuffers(ResourceOwner owner)
void ResourceOwnerRememberBuffer(ResourceOwner owner, Buffer buffer)
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
bool smgrprefetch(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum)
void smgrwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, const void *buffer, bool skipFsync)
SMgrRelation smgropen(RelFileLocator rlocator, BackendId backend)
void smgrzeroextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, int nblocks, bool skipFsync)
struct SMgrRelationData * smgr
RelFileLocatorBackend smgr_rlocator