PostgreSQL Source Code git master
Loading...
Searching...
No Matches
aio_init.c File Reference
#include "postgres.h"
#include "miscadmin.h"
#include "storage/aio.h"
#include "storage/aio_internal.h"
#include "storage/aio_subsys.h"
#include "storage/bufmgr.h"
#include "storage/io_worker.h"
#include "storage/ipc.h"
#include "storage/proc.h"
#include "storage/shmem.h"
#include "utils/guc.h"
Include dependency graph for aio_init.c:

Go to the source code of this file.

Functions

static Size AioCtlShmemSize (void)
 
static uint32 AioProcs (void)
 
static Size AioBackendShmemSize (void)
 
static Size AioHandleShmemSize (void)
 
static Size AioHandleIOVShmemSize (void)
 
static Size AioHandleDataShmemSize (void)
 
static int AioChooseMaxConcurrency (void)
 
Size AioShmemSize (void)
 
void AioShmemInit (void)
 
void pgaio_init_backend (void)
 

Function Documentation

◆ AioBackendShmemSize()

static Size AioBackendShmemSize ( void  )
static

Definition at line 49 of file aio_init.c.

50{
51 return mul_size(AioProcs(), sizeof(PgAioBackend));
52}
static uint32 AioProcs(void)
Definition aio_init.c:38
Size mul_size(Size s1, Size s2)
Definition shmem.c:510

References AioProcs(), and mul_size().

Referenced by AioShmemInit(), and AioShmemSize().

◆ AioChooseMaxConcurrency()

static int AioChooseMaxConcurrency ( void  )
static

Definition at line 97 of file aio_init.c.

98{
101
102 /* Similar logic to LimitAdditionalPins() */
105
107
108 /* apply upper limit */
109 return Min(max_proportional_pins, 64);
110}
#define Min(x, y)
Definition c.h:997
#define Max(x, y)
Definition c.h:991
uint32_t uint32
Definition c.h:546
int NBuffers
Definition globals.c:142
int MaxBackends
Definition globals.c:146
static int fb(int x)
#define NUM_AUXILIARY_PROCS
Definition proc.h:469

References fb(), Max, MaxBackends, Min, NBuffers, and NUM_AUXILIARY_PROCS.

Referenced by AioShmemSize().

◆ AioCtlShmemSize()

static Size AioCtlShmemSize ( void  )
static

Definition at line 31 of file aio_init.c.

32{
33 /* pgaio_ctl itself */
34 return sizeof(PgAioCtl);
35}

Referenced by AioShmemInit(), and AioShmemSize().

◆ AioHandleDataShmemSize()

static Size AioHandleDataShmemSize ( void  )
static

Definition at line 79 of file aio_init.c.

80{
81 /* each buffer referenced by an iovec can have associated data */
82 return mul_size(sizeof(uint64),
85}
int io_max_concurrency
Definition aio.c:75
int io_max_combine_limit
Definition bufmgr.c:201
uint64_t uint64
Definition c.h:547

References AioProcs(), io_max_combine_limit, io_max_concurrency, and mul_size().

Referenced by AioShmemInit(), and AioShmemSize().

◆ AioHandleIOVShmemSize()

static Size AioHandleIOVShmemSize ( void  )
static

Definition at line 70 of file aio_init.c.

71{
72 /* each IO handle can have up to io_max_combine_limit iovec objects */
73 return mul_size(sizeof(struct iovec),
76}

References AioProcs(), fb(), io_max_combine_limit, io_max_concurrency, and mul_size().

Referenced by AioShmemInit(), and AioShmemSize().

◆ AioHandleShmemSize()

static Size AioHandleShmemSize ( void  )
static

Definition at line 55 of file aio_init.c.

56{
57 Size sz;
58
59 /* verify AioChooseMaxConcurrency() did its thing */
61
62 /* io handles */
65
66 return sz;
67}
#define Assert(condition)
Definition c.h:873
size_t Size
Definition c.h:619

References AioProcs(), Assert, fb(), io_max_concurrency, and mul_size().

Referenced by AioShmemInit(), and AioShmemSize().

◆ AioProcs()

static uint32 AioProcs ( void  )
static

Definition at line 38 of file aio_init.c.

39{
40 /*
41 * While AIO workers don't need their own AIO context, we can't currently
42 * guarantee that nothing gets assigned to an IO worker's ProcNumber if we
43 * just subtracted MAX_IO_WORKERS.
44 */
46}

References MaxBackends, and NUM_AUXILIARY_PROCS.

Referenced by AioBackendShmemSize(), AioHandleDataShmemSize(), AioHandleIOVShmemSize(), AioHandleShmemSize(), AioShmemInit(), and pgaio_init_backend().

◆ AioShmemInit()

void AioShmemInit ( void  )

Definition at line 149 of file aio_init.c.

150{
151 bool found;
152 uint32 io_handle_off = 0;
153 uint32 iovec_off = 0;
155
156 pgaio_ctl = (PgAioCtl *)
157 ShmemInitStruct("AioCtl", AioCtlShmemSize(), &found);
158
159 if (found)
160 goto out;
161
163
166
168 ShmemInitStruct("AioBackend", AioBackendShmemSize(), &found);
169
171 ShmemInitStruct("AioHandle", AioHandleShmemSize(), &found);
172
173 pgaio_ctl->iovecs = (struct iovec *)
174 ShmemInitStruct("AioHandleIOV", AioHandleIOVShmemSize(), &found);
176 ShmemInitStruct("AioHandleData", AioHandleDataShmemSize(), &found);
177
178 for (int procno = 0; procno < AioProcs(); procno++)
179 {
181
182 bs->io_handle_off = io_handle_off;
183 io_handle_off += io_max_concurrency;
184
185 dclist_init(&bs->idle_ios);
186 memset(bs->staged_ios, 0, sizeof(PgAioHandle *) * PGAIO_SUBMIT_BATCH_SIZE);
187 dclist_init(&bs->in_flight_ios);
188
189 /* initialize per-backend IOs */
190 for (int i = 0; i < io_max_concurrency; i++)
191 {
192 PgAioHandle *ioh = &pgaio_ctl->io_handles[bs->io_handle_off + i];
193
194 ioh->generation = 1;
195 ioh->owner_procno = procno;
196 ioh->iovec_off = iovec_off;
197 ioh->handle_data_len = 0;
198 ioh->report_return = NULL;
199 ioh->resowner = NULL;
200 ioh->num_callbacks = 0;
201 ioh->distilled_result.status = PGAIO_RS_UNKNOWN;
202 ioh->flags = 0;
203
205
206 dclist_push_tail(&bs->idle_ios, &ioh->node);
207 iovec_off += io_max_combine_limit;
208 }
209 }
210
211out:
212 /* Initialize IO method specific resources. */
215}
PgAioCtl * pgaio_ctl
Definition aio.c:78
const IoMethodOps * pgaio_method_ops
Definition aio.c:96
static Size AioHandleIOVShmemSize(void)
Definition aio_init.c:70
static Size AioHandleDataShmemSize(void)
Definition aio_init.c:79
static Size AioHandleShmemSize(void)
Definition aio_init.c:55
static Size AioBackendShmemSize(void)
Definition aio_init.c:49
static Size AioCtlShmemSize(void)
Definition aio_init.c:31
#define PGAIO_SUBMIT_BATCH_SIZE
@ PGAIO_RS_UNKNOWN
Definition aio_types.h:80
void ConditionVariableInit(ConditionVariable *cv)
static void dclist_push_tail(dclist_head *head, dlist_node *node)
Definition ilist.h:709
static void dclist_init(dclist_head *head)
Definition ilist.h:671
int i
Definition isn.c:77
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition shmem.c:389
void(* shmem_init)(bool first_time)
uint32 io_handle_off
uint32 iovec_count
struct iovec * iovecs
PgAioHandle * io_handles
uint32 io_handle_count
uint64 * handle_data
PgAioBackend * backend_state
uint64 generation

References AioBackendShmemSize(), AioCtlShmemSize(), AioHandleDataShmemSize(), AioHandleIOVShmemSize(), AioHandleShmemSize(), AioProcs(), PgAioCtl::backend_state, ConditionVariableInit(), dclist_init(), dclist_push_tail(), fb(), PgAioHandle::generation, PgAioCtl::handle_data, i, PgAioCtl::io_handle_count, PgAioBackend::io_handle_off, PgAioCtl::io_handles, io_max_combine_limit, io_max_concurrency, PgAioCtl::iovec_count, PgAioCtl::iovecs, pgaio_ctl, pgaio_method_ops, PGAIO_RS_UNKNOWN, PGAIO_SUBMIT_BATCH_SIZE, IoMethodOps::shmem_init, and ShmemInitStruct().

Referenced by CreateOrAttachShmemStructs().

◆ AioShmemSize()

Size AioShmemSize ( void  )

Definition at line 113 of file aio_init.c.

114{
115 Size sz = 0;
116
117 /*
118 * We prefer to report this value's source as PGC_S_DYNAMIC_DEFAULT.
119 * However, if the DBA explicitly set io_max_concurrency = -1 in the
120 * config file, then PGC_S_DYNAMIC_DEFAULT will fail to override that and
121 * we must force the matter with PGC_S_OVERRIDE.
122 */
123 if (io_max_concurrency == -1)
124 {
125 char buf[32];
126
127 snprintf(buf, sizeof(buf), "%d", AioChooseMaxConcurrency());
128 SetConfigOption("io_max_concurrency", buf, PGC_POSTMASTER,
130 if (io_max_concurrency == -1) /* failed to apply it? */
131 SetConfigOption("io_max_concurrency", buf, PGC_POSTMASTER,
133 }
134
140
141 /* Reserve space for method specific resources. */
144
145 return sz;
146}
static int AioChooseMaxConcurrency(void)
Definition aio_init.c:97
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition guc.c:4196
@ PGC_S_DYNAMIC_DEFAULT
Definition guc.h:114
@ PGC_S_OVERRIDE
Definition guc.h:123
@ PGC_POSTMASTER
Definition guc.h:74
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define snprintf
Definition port.h:260
Size add_size(Size s1, Size s2)
Definition shmem.c:495
size_t(* shmem_size)(void)

References add_size(), AioBackendShmemSize(), AioChooseMaxConcurrency(), AioCtlShmemSize(), AioHandleDataShmemSize(), AioHandleIOVShmemSize(), AioHandleShmemSize(), buf, fb(), io_max_concurrency, pgaio_method_ops, PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT, PGC_S_OVERRIDE, SetConfigOption(), IoMethodOps::shmem_size, and snprintf.

Referenced by CalculateShmemSize().

◆ pgaio_init_backend()

void pgaio_init_backend ( void  )

Definition at line 218 of file aio_init.c.

219{
220 /* shouldn't be initialized twice */
222
224 return;
225
226 if (MyProc == NULL || MyProcNumber >= AioProcs())
227 elog(ERROR, "aio requires a normal PGPROC");
228
230
233
235}
PgAioBackend * pgaio_my_backend
Definition aio.c:81
void pgaio_shutdown(int code, Datum arg)
Definition aio.c:1288
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
ProcNumber MyProcNumber
Definition globals.c:90
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition ipc.c:344
@ B_IO_WORKER
Definition miscadmin.h:364
BackendType MyBackendType
Definition miscinit.c:64
PGPROC * MyProc
Definition proc.c:67
void(* init_backend)(void)

References AioProcs(), Assert, B_IO_WORKER, PgAioCtl::backend_state, before_shmem_exit(), elog, ERROR, fb(), IoMethodOps::init_backend, MyBackendType, MyProc, MyProcNumber, pgaio_ctl, pgaio_method_ops, pgaio_my_backend, and pgaio_shutdown().

Referenced by BaseInit().