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 153 of file aio_init.c.

154{
155 bool found;
156 uint32 io_handle_off = 0;
157 uint32 iovec_off = 0;
158 uint32 per_backend_iovecs = io_max_concurrency * io_max_combine_limit;
159
160 pgaio_ctl = (PgAioCtl *)
161 ShmemInitStruct("AioCtl", AioCtlShmemSize(), &found);
162
163 if (found)
164 goto out;
165
166 memset(pgaio_ctl, 0, AioCtlShmemSize());
167
169 pgaio_ctl->iovec_count = AioProcs() * per_backend_iovecs;
170
172 ShmemInitStruct("AioBackend", AioBackendShmemSize(), &found);
173
175 ShmemInitStruct("AioHandle", AioHandleShmemSize(), &found);
176
177 pgaio_ctl->iovecs = (struct iovec *)
178 ShmemInitStruct("AioHandleIOV", AioHandleIOVShmemSize(), &found);
180 ShmemInitStruct("AioHandleData", AioHandleDataShmemSize(), &found);
181
182 for (int procno = 0; procno < AioProcs(); procno++)
183 {
184 PgAioBackend *bs = &pgaio_ctl->backend_state[procno];
185
186 bs->io_handle_off = io_handle_off;
187 io_handle_off += io_max_concurrency;
188
189 dclist_init(&bs->idle_ios);
190 memset(bs->staged_ios, 0, sizeof(PgAioHandle *) * PGAIO_SUBMIT_BATCH_SIZE);
192
193 /* initialize per-backend IOs */
194 for (int i = 0; i < io_max_concurrency; i++)
195 {
197
198 ioh->generation = 1;
199 ioh->owner_procno = procno;
200 ioh->iovec_off = iovec_off;
201 ioh->handle_data_len = 0;
202 ioh->report_return = NULL;
203 ioh->resowner = NULL;
204 ioh->num_callbacks = 0;
206 ioh->flags = 0;
207
209
210 dclist_push_tail(&bs->idle_ios, &ioh->node);
211 iovec_off += io_max_combine_limit;
212 }
213 }
214
215out:
216 /* Initialize IO method specific resources. */
219}
int io_max_concurrency
Definition: aio.c:73
PgAioCtl * pgaio_ctl
Definition: aio.c:76
const IoMethodOps * pgaio_method_ops
Definition: aio.c:88
static Size AioHandleIOVShmemSize(void)
Definition: aio_init.c:74
static Size AioHandleDataShmemSize(void)
Definition: aio_init.c:83
static Size AioHandleShmemSize(void)
Definition: aio_init.c:59
static Size AioBackendShmemSize(void)
Definition: aio_init.c:53
static uint32 AioProcs(void)
Definition: aio_init.c:42
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:76
int io_max_combine_limit
Definition: bufmgr.c:168
uint64_t uint64
Definition: c.h:503
uint32_t uint32
Definition: c.h:502
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:74
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:382
void(* shmem_init)(bool first_time)
Definition: aio_internal.h:263
uint32 io_handle_off
Definition: aio_internal.h:183
dclist_head in_flight_ios
Definition: aio_internal.h:214
dclist_head idle_ios
Definition: aio_internal.h:186
PgAioHandle * staged_ios[PGAIO_SUBMIT_BATCH_SIZE]
Definition: aio_internal.h:204
uint32 iovec_count
Definition: aio_internal.h:228
struct iovec * iovecs
Definition: aio_internal.h:229
PgAioHandle * io_handles
Definition: aio_internal.h:241
uint32 io_handle_count
Definition: aio_internal.h:240
uint64 * handle_data
Definition: aio_internal.h:238
PgAioBackend * backend_state
Definition: aio_internal.h:221
struct ResourceOwnerData * resowner
Definition: aio_internal.h:137
int32 owner_procno
Definition: aio_internal.h:120
PgAioResult distilled_result
Definition: aio_internal.h:151
dlist_node node
Definition: aio_internal.h:135
uint8 handle_data_len
Definition: aio_internal.h:117
PgAioReturn * report_return
Definition: aio_internal.h:166
uint32 iovec_off
Definition: aio_internal.h:159
uint64 generation
Definition: aio_internal.h:141
uint8 num_callbacks
Definition: aio_internal.h:105
ConditionVariable cv
Definition: aio_internal.h:148
uint32 status
Definition: aio_types.h:95

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 117 of file aio_init.c.

118{
119 Size sz = 0;
120
121 /*
122 * We prefer to report this value's source as PGC_S_DYNAMIC_DEFAULT.
123 * However, if the DBA explicitly set io_max_concurrency = -1 in the
124 * config file, then PGC_S_DYNAMIC_DEFAULT will fail to override that and
125 * we must force the matter with PGC_S_OVERRIDE.
126 */
127 if (io_max_concurrency == -1)
128 {
129 char buf[32];
130
131 snprintf(buf, sizeof(buf), "%d", AioChooseMaxConcurrency());
132 SetConfigOption("io_max_concurrency", buf, PGC_POSTMASTER,
134 if (io_max_concurrency == -1) /* failed to apply it? */
135 SetConfigOption("io_max_concurrency", buf, PGC_POSTMASTER,
137 }
138
139 sz = add_size(sz, AioCtlShmemSize());
140 sz = add_size(sz, AioBackendShmemSize());
141 sz = add_size(sz, AioHandleShmemSize());
144
145 /* Reserve space for method specific resources. */
148
149 return sz;
150}
static int AioChooseMaxConcurrency(void)
Definition: aio_init.c:101
size_t Size
Definition: c.h:576
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4332
@ 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:488
size_t(* shmem_size)(void)
Definition: aio_internal.h:257

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 1080 of file aio.c.

1081{
1082 /*
1083 * We should never be in batch mode at transactional boundaries. In case
1084 * an error was thrown while in batch mode, pgaio_error_cleanup() should
1085 * have exited batchmode.
1086 *
1087 * In case we are in batchmode somehow, make sure to submit all staged
1088 * IOs, other backends may need them to complete to continue.
1089 */
1091 {
1093 elog(WARNING, "open AIO batch at end of (sub-)transaction");
1094 }
1095
1096 /*
1097 * As we aren't in batchmode, there shouldn't be any unsubmitted IOs.
1098 */
1100}
PgAioBackend * pgaio_my_backend
Definition: aio.c:79
void pgaio_error_cleanup(void)
Definition: aio.c:1052
#define WARNING
Definition: elog.h:36
#define elog(elevel,...)
Definition: elog.h:225
Assert(PointerIsAligned(start, uint64))
uint16 num_staged_ios
Definition: aio_internal.h:203

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 1052 of file aio.c.

1053{
1054 /*
1055 * It is possible that code errored out after pgaio_enter_batchmode() but
1056 * before pgaio_exit_batchmode() was called. In that case we need to
1057 * submit the IO now.
1058 */
1060 {
1062
1064 }
1065
1066 /*
1067 * As we aren't in batchmode, there shouldn't be any unsubmitted IOs.
1068 */
1070}
void pgaio_submit_staged(void)
Definition: aio.c:1010

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 222 of file aio_init.c.

223{
224 /* shouldn't be initialized twice */
226
228 return;
229
230 if (MyProc == NULL || MyProcNumber >= AioProcs())
231 elog(ERROR, "aio requires a normal PGPROC");
232
234
237
239}
void pgaio_shutdown(int code, Datum arg)
Definition: aio.c:1127
#define ERROR
Definition: elog.h:39
ProcNumber MyProcNumber
Definition: globals.c:89
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:268

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 520 of file method_worker.c.

521{
522 return io_method == IOMETHOD_WORKER;
523}
int io_method
Definition: aio.c:72
@ IOMETHOD_WORKER
Definition: aio.h:30

References io_method, and IOMETHOD_WORKER.

Referenced by maybe_adjust_io_workers().