PostgreSQL Source Code git master
Loading...
Searching...
No Matches
buf_init.c File Reference
#include "postgres.h"
#include "storage/aio.h"
#include "storage/buf_internals.h"
#include "storage/bufmgr.h"
#include "storage/proclist.h"
Include dependency graph for buf_init.c:

Go to the source code of this file.

Functions

void BufferManagerShmemInit (void)
 
Size BufferManagerShmemSize (void)
 

Variables

BufferDescPaddedBufferDescriptors
 
charBufferBlocks
 
ConditionVariableMinimallyPaddedBufferIOCVArray
 
WritebackContext BackendWritebackContext
 
CkptSortItemCkptBufferIds
 

Function Documentation

◆ BufferManagerShmemInit()

void BufferManagerShmemInit ( void  )

Definition at line 69 of file buf_init.c.

70{
71 bool foundBufs,
75
76 /* Align descriptors to a cacheline boundary. */
78 ShmemInitStruct("Buffer Descriptors",
79 NBuffers * sizeof(BufferDescPadded),
80 &foundDescs);
81
82 /* Align buffer pool on IO page size boundary. */
83 BufferBlocks = (char *)
85 ShmemInitStruct("Buffer Blocks",
87 &foundBufs));
88
89 /* Align condition variables to cacheline boundary. */
91 ShmemInitStruct("Buffer IO Condition Variables",
93 &foundIOCV);
94
95 /*
96 * The array used to sort to-be-checkpointed buffer ids is located in
97 * shared memory, to avoid having to allocate significant amounts of
98 * memory at runtime. As that'd be in the middle of a checkpoint, or when
99 * the checkpointer is restarted, memory allocation failures would be
100 * painful.
101 */
103 ShmemInitStruct("Checkpoint BufferIds",
105
107 {
108 /* should find all of these, or none of them */
110 /* note: this path is only taken in EXEC_BACKEND case */
111 }
112 else
113 {
114 int i;
115
116 /*
117 * Initialize all the buffer headers.
118 */
119 for (i = 0; i < NBuffers; i++)
120 {
122
123 ClearBufferTag(&buf->tag);
124
125 pg_atomic_init_u64(&buf->state, 0);
126 buf->wait_backend_pgprocno = INVALID_PROC_NUMBER;
127
128 buf->buf_id = i;
129
130 pgaio_wref_clear(&buf->io_wref);
131
132 proclist_init(&buf->lock_waiters);
134 }
135 }
136
137 /* Init other shared buffer-management stuff */
139
140 /* Initialize per-backend file flush context */
143}
void pgaio_wref_clear(PgAioWaitRef *iow)
Definition aio.c:964
static void pg_atomic_init_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition atomics.h:453
CkptSortItem * CkptBufferIds
Definition buf_init.c:26
char * BufferBlocks
Definition buf_init.c:23
WritebackContext BackendWritebackContext
Definition buf_init.c:25
ConditionVariableMinimallyPadded * BufferIOCVArray
Definition buf_init.c:24
BufferDescPadded * BufferDescriptors
Definition buf_init.c:22
static ConditionVariable * BufferDescriptorGetIOCV(const BufferDesc *bdesc)
static void ClearBufferTag(BufferTag *tag)
static BufferDesc * GetBufferDescriptor(uint32 id)
void WritebackContextInit(WritebackContext *context, int *max_pending)
Definition bufmgr.c:7267
int backend_flush_after
Definition bufmgr.c:209
#define TYPEALIGN(ALIGNVAL, LEN)
Definition c.h:819
#define Assert(condition)
Definition c.h:873
size_t Size
Definition c.h:619
void ConditionVariableInit(ConditionVariable *cv)
void StrategyInitialize(bool init)
Definition freelist.c:401
int NBuffers
Definition globals.c:142
int i
Definition isn.c:77
#define PG_IO_ALIGN_SIZE
static char buf[DEFAULT_XLOG_SEG_SIZE]
static int fb(int x)
static void proclist_init(proclist_head *list)
Definition proclist.h:29
#define INVALID_PROC_NUMBER
Definition procnumber.h:26
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition shmem.c:378

References Assert, backend_flush_after, BackendWritebackContext, buf, BufferBlocks, BufferDescriptorGetIOCV(), BufferDescriptors, BufferIOCVArray, CkptBufferIds, ClearBufferTag(), ConditionVariableInit(), fb(), GetBufferDescriptor(), i, INVALID_PROC_NUMBER, NBuffers, pg_atomic_init_u64(), PG_IO_ALIGN_SIZE, pgaio_wref_clear(), proclist_init(), ShmemInitStruct(), StrategyInitialize(), TYPEALIGN, and WritebackContextInit().

Referenced by CreateOrAttachShmemStructs().

◆ BufferManagerShmemSize()

Size BufferManagerShmemSize ( void  )

Definition at line 152 of file buf_init.c.

153{
154 Size size = 0;
155
156 /* size of buffer descriptors */
157 size = add_size(size, mul_size(NBuffers, sizeof(BufferDescPadded)));
158 /* to allow aligning buffer descriptors */
159 size = add_size(size, PG_CACHE_LINE_SIZE);
160
161 /* size of data pages, plus alignment padding */
162 size = add_size(size, PG_IO_ALIGN_SIZE);
163 size = add_size(size, mul_size(NBuffers, BLCKSZ));
164
165 /* size of stuff controlled by freelist.c */
166 size = add_size(size, StrategyShmemSize());
167
168 /* size of I/O condition variables */
169 size = add_size(size, mul_size(NBuffers,
171 /* to allow aligning the above */
172 size = add_size(size, PG_CACHE_LINE_SIZE);
173
174 /* size of checkpoint sort array in bufmgr.c */
175 size = add_size(size, mul_size(NBuffers, sizeof(CkptSortItem)));
176
177 return size;
178}
Size StrategyShmemSize(void)
Definition freelist.c:380
#define PG_CACHE_LINE_SIZE
Size add_size(Size s1, Size s2)
Definition shmem.c:482
Size mul_size(Size s1, Size s2)
Definition shmem.c:497

References add_size(), fb(), mul_size(), NBuffers, PG_CACHE_LINE_SIZE, PG_IO_ALIGN_SIZE, and StrategyShmemSize().

Referenced by CalculateShmemSize().

Variable Documentation

◆ BackendWritebackContext

WritebackContext BackendWritebackContext

Definition at line 25 of file buf_init.c.

Referenced by BufferManagerShmemInit(), and GetVictimBuffer().

◆ BufferBlocks

char* BufferBlocks

Definition at line 23 of file buf_init.c.

Referenced by BufferGetBlock(), and BufferManagerShmemInit().

◆ BufferDescriptors

BufferDescPadded* BufferDescriptors

Definition at line 22 of file buf_init.c.

Referenced by BufferManagerShmemInit(), and GetBufferDescriptor().

◆ BufferIOCVArray

Definition at line 24 of file buf_init.c.

Referenced by BufferDescriptorGetIOCV(), and BufferManagerShmemInit().

◆ CkptBufferIds

CkptSortItem* CkptBufferIds

Definition at line 26 of file buf_init.c.

Referenced by BufferManagerShmemInit(), and BufferSync().