24#define INT_ACCESS_ONCE(var) ((int)(*((volatile int *)&(var))))
114 uint32 originalVictim = victim;
131 expected = originalVictim + 1;
186 if (strategy != NULL)
245 local_buf_state = old_buf_state;
255 if (--trycounter == 0)
264 elog(
ERROR,
"no unpinned buffers available");
296 if (strategy != NULL)
298 *buf_state = local_buf_state;
328 result = nextVictimBuffer %
NBuffers;
338 *complete_passes += nextVictimBuffer /
NBuffers;
502 ring_max_kb =
Max(ring_size_kb, ring_max_kb);
515 ring_size_kb += (BLCKSZ / 1024) *
518 if (ring_size_kb > ring_max_kb)
519 ring_size_kb = ring_max_kb;
523 ring_size_kb = 16 * 1024;
530 elog(
ERROR,
"unrecognized buffer access strategy: %d",
551 Assert(ring_size_kb >= 0);
554 ring_buffers = ring_size_kb / (BLCKSZ / 1024);
557 if (ring_buffers == 0)
569 ring_buffers *
sizeof(
Buffer));
572 strategy->
btype = btype;
588 if (strategy == NULL)
611 if (strategy == NULL)
614 switch (strategy->
btype)
646 if (strategy != NULL)
688 local_buf_state = old_buf_state;
716 *buf_state = local_buf_state;
752 switch (strategy->
btype)
771 elog(
ERROR,
"unrecognized BufferAccessStrategyType: %d", strategy->
btype);
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
static void pg_atomic_init_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint32 pg_atomic_fetch_add_u32(volatile pg_atomic_uint32 *ptr, int32 add_)
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
struct BufferAccessStrategyData * BufferAccessStrategy
#define BUF_STATE_GET_USAGECOUNT(state)
#define BUF_USAGECOUNT_ONE
#define BUF_STATE_GET_REFCOUNT(state)
static BufferDesc * GetBufferDescriptor(uint32 id)
static Buffer BufferDescriptorGetBuffer(const BufferDesc *bdesc)
void InitBufTable(int size)
Size BufTableShmemSize(int size)
pg_noinline uint32 WaitBufHdrUnlocked(BufferDesc *buf)
int effective_io_concurrency
void TrackNewBufferPin(Buffer buf)
#define FLEXIBLE_ARRAY_MEMBER
struct BufferAccessStrategyData BufferAccessStrategyData
int GetAccessStrategyPinLimit(BufferAccessStrategy strategy)
int StrategySyncStart(uint32 *complete_passes, uint32 *num_buf_alloc)
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
static BufferStrategyControl * StrategyControl
static uint32 ClockSweepTick(void)
BufferAccessStrategy GetAccessStrategyWithSize(BufferAccessStrategyType btype, int ring_size_kb)
void StrategyInitialize(bool init)
static void AddBufferToRing(BufferAccessStrategy strategy, BufferDesc *buf)
int GetAccessStrategyBufferCount(BufferAccessStrategy strategy)
void FreeAccessStrategy(BufferAccessStrategy strategy)
#define INT_ACCESS_ONCE(var)
void StrategyNotifyBgWriter(int bgwprocno)
IOContext IOContextForStrategy(BufferAccessStrategy strategy)
BufferDesc * StrategyGetBuffer(BufferAccessStrategy strategy, uint32 *buf_state, bool *from_ring)
Size StrategyShmemSize(void)
bool StrategyRejectBuffer(BufferAccessStrategy strategy, BufferDesc *buf, bool from_ring)
static BufferDesc * GetBufferFromRing(BufferAccessStrategy strategy, uint32 *buf_state)
Assert(PointerIsAligned(start, uint64))
void SetLatch(Latch *latch)
#define NUM_BUFFER_PARTITIONS
void pfree(void *pointer)
void * palloc0(Size size)
Size add_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
#define SpinLockInit(lock)
#define SpinLockRelease(lock)
#define SpinLockAcquire(lock)
BufferAccessStrategyType btype
Buffer buffers[FLEXIBLE_ARRAY_MEMBER]
pg_atomic_uint32 nextVictimBuffer
pg_atomic_uint32 numBufferAllocs
slock_t buffer_strategy_lock