1/*-------------------------------------------------------------------------
4 * AIO - Subsystem Initialization
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/backend/storage/aio/aio_init.c
12 *-------------------------------------------------------------------------
33 /* pgaio_ctl itself */
41 * While AIO workers don't need their own AIO context, we can't currently
42 * guarantee nothing gets assigned to the a ProcNumber for an IO worker if
43 * we just subtracted MAX_IO_WORKERS.
59 /* verify AioChooseMaxConcurrency() did its thing */
72 /* each IO handle can have up to io_max_combine_limit iovec objects */
73 return mul_size(
sizeof(
struct iovec),
81 /* each buffer referenced by an iovec can have associated data */
88 * Choose a suitable value for io_max_concurrency.
90 * It's unlikely that we could have more IOs in flight than buffers that we
91 * would be allowed to pin.
93 * On the upper end, apply a cap too - just because shared_buffers is large,
94 * it doesn't make sense have millions of buffers undergo IO concurrently.
100 int max_proportional_pins;
102 /* Similar logic to LimitAdditionalPins() */
104 max_proportional_pins =
NBuffers / max_backends;
106 max_proportional_pins =
Max(max_proportional_pins, 1);
108 /* apply upper limit */
109 return Min(max_proportional_pins, 64);
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.
141 /* Reserve space for method specific resources. */
178 for (
int procno = 0; procno <
AioProcs(); procno++)
189 /* initialize per-backend IOs */
212 /* Initialize IO method specific resources. */
220 /* shouldn't be initialized twice */
227 elog(
ERROR,
"aio requires a normal PGPROC");
PgAioBackend * pgaio_my_backend
const IoMethodOps * pgaio_method_ops
void pgaio_shutdown(int code, Datum arg)
static Size AioHandleIOVShmemSize(void)
void pgaio_init_backend(void)
static Size AioHandleDataShmemSize(void)
static Size AioHandleShmemSize(void)
static Size AioBackendShmemSize(void)
static int AioChooseMaxConcurrency(void)
static uint32 AioProcs(void)
static Size AioCtlShmemSize(void)
#define PGAIO_SUBMIT_BATCH_SIZE
void ConditionVariableInit(ConditionVariable *cv)
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Assert(PointerIsAligned(start, uint64))
static void dclist_push_tail(dclist_head *head, dlist_node *node)
static void dclist_init(dclist_head *head)
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
BackendType MyBackendType
#define NUM_AUXILIARY_PROCS
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
size_t(* shmem_size)(void)
void(* shmem_init)(bool first_time)
void(* init_backend)(void)
dclist_head in_flight_ios
PgAioHandle * staged_ios[PGAIO_SUBMIT_BATCH_SIZE]
PgAioBackend * backend_state
struct ResourceOwnerData * resowner
PgAioResult distilled_result
PgAioReturn * report_return