24 #define INT_ACCESS_ONCE(var) ((int)(*((volatile int *)&(var))))
122 uint32 originalVictim = victim;
139 expected = originalVictim + 1;
209 if (strategy != NULL)
305 if (strategy != NULL)
307 *buf_state = local_buf_state;
337 if (strategy != NULL)
339 *buf_state = local_buf_state;
343 else if (--trycounter == 0)
353 elog(
ERROR,
"no unpinned buffers available");
374 if (
buf->freeNext < 0)
401 result = nextVictimBuffer %
NBuffers;
411 *complete_passes += nextVictimBuffer /
NBuffers;
561 ring_size_kb = 16 * 1024;
568 elog(
ERROR,
"unrecognized buffer access strategy: %d",
589 Assert(ring_size_kb >= 0);
592 ring_buffers = ring_size_kb / (BLCKSZ / 1024);
595 if (ring_buffers == 0)
607 ring_buffers *
sizeof(
Buffer));
610 strategy->
btype = btype;
626 if (strategy == NULL)
649 if (strategy == NULL)
652 switch (strategy->
btype)
684 if (strategy != NULL)
729 *buf_state = local_buf_state;
763 switch (strategy->
btype)
782 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
static BufferDesc * GetBufferDescriptor(uint32 id)
static void UnlockBufHdr(BufferDesc *desc, uint32 buf_state)
#define BUF_STATE_GET_USAGECOUNT(state)
#define BUF_USAGECOUNT_ONE
#define BUF_STATE_GET_REFCOUNT(state)
#define FREENEXT_NOT_IN_LIST
static Buffer BufferDescriptorGetBuffer(const BufferDesc *bdesc)
void InitBufTable(int size)
Size BufTableShmemSize(int size)
uint32 LockBufHdr(BufferDesc *desc)
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
struct BufferAccessStrategyData BufferAccessStrategyData
int GetAccessStrategyPinLimit(BufferAccessStrategy strategy)
int StrategySyncStart(uint32 *complete_passes, uint32 *num_buf_alloc)
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
bool have_free_buffer(void)
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)
BufferDesc * StrategyGetBuffer(BufferAccessStrategy strategy, uint32 *buf_state, bool *from_ring)
int GetAccessStrategyBufferCount(BufferAccessStrategy strategy)
void FreeAccessStrategy(BufferAccessStrategy strategy)
#define INT_ACCESS_ONCE(var)
void StrategyNotifyBgWriter(int bgwprocno)
IOContext IOContextForStrategy(BufferAccessStrategy strategy)
Size StrategyShmemSize(void)
void StrategyFreeBuffer(BufferDesc *buf)
bool StrategyRejectBuffer(BufferAccessStrategy strategy, BufferDesc *buf, bool from_ring)
static BufferDesc * GetBufferFromRing(BufferAccessStrategy strategy, uint32 *buf_state)
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)
static pg_noinline void Size size
#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