PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
aio_subsys.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

Size AioShmemSize (void)
 
void AioShmemInit (void)
 
void pgaio_init_backend (void)
 
void pgaio_error_cleanup (void)
 
void AtEOXact_Aio (bool is_commit)
 
bool pgaio_workers_enabled (void)
 

Function Documentation

◆ 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;
154 uint32 per_backend_iovecs = io_max_concurrency * io_max_combine_limit;
155
156 pgaio_ctl = (PgAioCtl *)
157 ShmemInitStruct("AioCtl", AioCtlShmemSize(), &found);
158
159 if (found)
160 goto out;
161
162 memset(pgaio_ctl, 0, AioCtlShmemSize());
163
165 pgaio_ctl->iovec_count = AioProcs() * per_backend_iovecs;
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 {
180 PgAioBackend *bs = &pgaio_ctl->backend_state[procno];
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);
188
189 /* initialize per-backend IOs */
190 for (int i = 0; i < io_max_concurrency; i++)
191 {
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;
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}
int io_max_concurrency
Definition: aio.c:75
PgAioCtl * pgaio_ctl
Definition: aio.c:78
const IoMethodOps * pgaio_method_ops
Definition: aio.c:93
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 uint32 AioProcs(void)
Definition: aio_init.c:38
static Size AioCtlShmemSize(void)
Definition: aio_init.c:31
#define PGAIO_SUBMIT_BATCH_SIZE
Definition: aio_internal.h:28
@ PGAIO_RS_UNKNOWN
Definition: aio_types.h:80
int io_max_combine_limit
Definition: bufmgr.c:172
uint64_t uint64
Definition: c.h:539
uint32_t uint32
Definition: c.h:538
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:387
void(* shmem_init)(bool first_time)
Definition: aio_internal.h:283
uint32 io_handle_off
Definition: aio_internal.h:194
dclist_head in_flight_ios
Definition: aio_internal.h:225
dclist_head idle_ios
Definition: aio_internal.h:197
PgAioHandle * staged_ios[PGAIO_SUBMIT_BATCH_SIZE]
Definition: aio_internal.h:215
uint32 iovec_count
Definition: aio_internal.h:239
struct iovec * iovecs
Definition: aio_internal.h:240
PgAioHandle * io_handles
Definition: aio_internal.h:252
uint32 io_handle_count
Definition: aio_internal.h:251
uint64 * handle_data
Definition: aio_internal.h:249
PgAioBackend * backend_state
Definition: aio_internal.h:232
struct ResourceOwnerData * resowner
Definition: aio_internal.h:148
int32 owner_procno
Definition: aio_internal.h:131
PgAioResult distilled_result
Definition: aio_internal.h:162
dlist_node node
Definition: aio_internal.h:146
uint8 handle_data_len
Definition: aio_internal.h:128
PgAioReturn * report_return
Definition: aio_internal.h:177
uint32 iovec_off
Definition: aio_internal.h:170
uint64 generation
Definition: aio_internal.h:152
uint8 num_callbacks
Definition: aio_internal.h:116
ConditionVariable cv
Definition: aio_internal.h:159
uint32 status
Definition: aio_types.h:108

References AioBackendShmemSize(), AioCtlShmemSize(), AioHandleDataShmemSize(), AioHandleIOVShmemSize(), AioHandleShmemSize(), AioProcs(), PgAioCtl::backend_state, ConditionVariableInit(), PgAioHandle::cv, dclist_init(), dclist_push_tail(), PgAioHandle::distilled_result, PgAioHandle::flags, PgAioHandle::generation, PgAioCtl::handle_data, PgAioHandle::handle_data_len, i, PgAioBackend::idle_ios, PgAioBackend::in_flight_ios, PgAioCtl::io_handle_count, PgAioBackend::io_handle_off, PgAioCtl::io_handles, io_max_combine_limit, io_max_concurrency, PgAioCtl::iovec_count, PgAioHandle::iovec_off, PgAioCtl::iovecs, PgAioHandle::node, PgAioHandle::num_callbacks, PgAioHandle::owner_procno, pgaio_ctl, pgaio_method_ops, PGAIO_RS_UNKNOWN, PGAIO_SUBMIT_BATCH_SIZE, PgAioHandle::report_return, PgAioHandle::resowner, IoMethodOps::shmem_init, ShmemInitStruct(), PgAioBackend::staged_ios, and PgAioResult::status.

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
135 sz = add_size(sz, AioCtlShmemSize());
136 sz = add_size(sz, AioBackendShmemSize());
137 sz = add_size(sz, AioHandleShmemSize());
140
141 /* Reserve space for method specific resources. */
144
145 return sz;
146}
static int AioChooseMaxConcurrency(void)
Definition: aio_init.c:97
size_t Size
Definition: c.h:610
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4338
@ PGC_S_DYNAMIC_DEFAULT
Definition: guc.h:114
@ PGC_S_OVERRIDE
Definition: guc.h:123
@ PGC_POSTMASTER
Definition: guc.h:74
static char * buf
Definition: pg_test_fsync.c:72
#define snprintf
Definition: port.h:239
Size add_size(Size s1, Size s2)
Definition: shmem.c:493
size_t(* shmem_size)(void)
Definition: aio_internal.h:277

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

Referenced by CalculateShmemSize().

◆ AtEOXact_Aio()

void AtEOXact_Aio ( bool  is_commit)

Definition at line 1190 of file aio.c.

1191{
1192 /*
1193 * We should never be in batch mode at transactional boundaries. In case
1194 * an error was thrown while in batch mode, pgaio_error_cleanup() should
1195 * have exited batchmode.
1196 *
1197 * In case we are in batchmode somehow, make sure to submit all staged
1198 * IOs, other backends may need them to complete to continue.
1199 */
1201 {
1203 elog(WARNING, "open AIO batch at end of (sub-)transaction");
1204 }
1205
1206 /*
1207 * As we aren't in batchmode, there shouldn't be any unsubmitted IOs.
1208 */
1210}
PgAioBackend * pgaio_my_backend
Definition: aio.c:81
void pgaio_error_cleanup(void)
Definition: aio.c:1162
#define WARNING
Definition: elog.h:36
#define elog(elevel,...)
Definition: elog.h:226
Assert(PointerIsAligned(start, uint64))
uint16 num_staged_ios
Definition: aio_internal.h:214

References Assert(), elog, PgAioBackend::in_batchmode, PgAioBackend::num_staged_ios, pgaio_error_cleanup(), pgaio_my_backend, and WARNING.

Referenced by AbortSubTransaction(), AbortTransaction(), CommitTransaction(), pgaio_shutdown(), and PrepareTransaction().

◆ pgaio_error_cleanup()

void pgaio_error_cleanup ( void  )

Definition at line 1162 of file aio.c.

1163{
1164 /*
1165 * It is possible that code errored out after pgaio_enter_batchmode() but
1166 * before pgaio_exit_batchmode() was called. In that case we need to
1167 * submit the IO now.
1168 */
1170 {
1172
1174 }
1175
1176 /*
1177 * As we aren't in batchmode, there shouldn't be any unsubmitted IOs.
1178 */
1180}
void pgaio_submit_staged(void)
Definition: aio.c:1120

References Assert(), PgAioBackend::in_batchmode, PgAioBackend::num_staged_ios, pgaio_my_backend, and pgaio_submit_staged().

Referenced by AbortSubTransaction(), AbortTransaction(), AtEOXact_Aio(), AutoVacLauncherMain(), BackgroundWriterMain(), CheckpointerMain(), pgarch_archiveXlog(), WalSndErrorCleanup(), WalSummarizerMain(), and WalWriterMain().

◆ 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}
void pgaio_shutdown(int code, Datum arg)
Definition: aio.c:1285
#define ERROR
Definition: elog.h:39
ProcNumber MyProcNumber
Definition: globals.c:90
void before_shmem_exit(pg_on_exit_callback function, Datum arg)
Definition: ipc.c:337
@ B_IO_WORKER
Definition: miscadmin.h:363
BackendType MyBackendType
Definition: miscinit.c:64
PGPROC * MyProc
Definition: proc.c:66
void(* init_backend)(void)
Definition: aio_internal.h:288

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

Referenced by BaseInit().

◆ pgaio_workers_enabled()

bool pgaio_workers_enabled ( void  )

Definition at line 591 of file method_worker.c.

592{
593 return io_method == IOMETHOD_WORKER;
594}
int io_method
Definition: aio.c:74
@ IOMETHOD_WORKER
Definition: aio.h:35

References io_method, and IOMETHOD_WORKER.

Referenced by maybe_adjust_io_workers().