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

Go to the source code of this file.

Data Structures

union  PgAioOpData
 
struct  PgAioTargetInfo
 
struct  PgAioHandleCallbacks
 

Macros

#define DEFAULT_IO_METHOD   IOMETHOD_WORKER
 
#define PGAIO_OP_COUNT   (PGAIO_OP_WRITEV + 1)
 
#define PGAIO_TID_COUNT   (PGAIO_TID_INVALID + 1)
 
#define PGAIO_HANDLE_MAX_CALLBACKS   4
 

Typedefs

typedef enum IoMethod IoMethod
 
typedef enum PgAioHandleFlags PgAioHandleFlags
 
typedef enum PgAioOp PgAioOp
 
typedef enum PgAioTargetID PgAioTargetID
 
typedef enum PgAioHandleCallbackID PgAioHandleCallbackID
 
typedef void(* PgAioHandleCallbackStage) (PgAioHandle *ioh, uint8 cb_flags)
 
typedef PgAioResult(* PgAioHandleCallbackComplete) (PgAioHandle *ioh, PgAioResult prior_result, uint8 cb_flags)
 
typedef void(* PgAioHandleCallbackReport) (PgAioResult result, const PgAioTargetData *target_data, int elevel)
 

Enumerations

enum  IoMethod { IOMETHOD_SYNC = 0 , IOMETHOD_WORKER }
 
enum  PgAioHandleFlags { PGAIO_HF_REFERENCES_LOCAL = 1 << 1 , PGAIO_HF_SYNCHRONOUS = 1 << 0 , PGAIO_HF_BUFFERED = 1 << 2 }
 
enum  PgAioOp { PGAIO_OP_INVALID = 0 , PGAIO_OP_READV , PGAIO_OP_WRITEV }
 
enum  PgAioTargetID { PGAIO_TID_INVALID = 0 }
 
enum  PgAioHandleCallbackID { PGAIO_HCB_INVALID }
 

Functions

PgAioHandlepgaio_io_acquire (struct ResourceOwnerData *resowner, PgAioReturn *ret)
 
PgAioHandlepgaio_io_acquire_nb (struct ResourceOwnerData *resowner, PgAioReturn *ret)
 
void pgaio_io_release (PgAioHandle *ioh)
 
void pgaio_io_release_resowner (struct dlist_node *ioh_node, bool on_error)
 
void pgaio_io_set_flag (PgAioHandle *ioh, PgAioHandleFlags flag)
 
int pgaio_io_get_id (PgAioHandle *ioh)
 
ProcNumber pgaio_io_get_owner (PgAioHandle *ioh)
 
void pgaio_io_get_wref (PgAioHandle *ioh, PgAioWaitRef *iow)
 
int pgaio_io_get_iovec (PgAioHandle *ioh, struct iovec **iov)
 
PgAioOp pgaio_io_get_op (PgAioHandle *ioh)
 
PgAioOpDatapgaio_io_get_op_data (PgAioHandle *ioh)
 
void pgaio_io_prep_readv (PgAioHandle *ioh, int fd, int iovcnt, uint64 offset)
 
void pgaio_io_prep_writev (PgAioHandle *ioh, int fd, int iovcnt, uint64 offset)
 
void pgaio_io_set_target (PgAioHandle *ioh, PgAioTargetID targetid)
 
bool pgaio_io_has_target (PgAioHandle *ioh)
 
PgAioTargetDatapgaio_io_get_target_data (PgAioHandle *ioh)
 
char * pgaio_io_get_target_description (PgAioHandle *ioh)
 
void pgaio_io_register_callbacks (PgAioHandle *ioh, PgAioHandleCallbackID cb_id, uint8 cb_data)
 
void pgaio_io_set_handle_data_64 (PgAioHandle *ioh, uint64 *data, uint8 len)
 
void pgaio_io_set_handle_data_32 (PgAioHandle *ioh, uint32 *data, uint8 len)
 
uint64pgaio_io_get_handle_data (PgAioHandle *ioh, uint8 *len)
 
void pgaio_wref_clear (PgAioWaitRef *iow)
 
bool pgaio_wref_valid (PgAioWaitRef *iow)
 
int pgaio_wref_get_id (PgAioWaitRef *iow)
 
void pgaio_wref_wait (PgAioWaitRef *iow)
 
bool pgaio_wref_check_done (PgAioWaitRef *iow)
 
void pgaio_result_report (PgAioResult result, const PgAioTargetData *target_data, int elevel)
 
void pgaio_enter_batchmode (void)
 
void pgaio_exit_batchmode (void)
 
void pgaio_submit_staged (void)
 
bool pgaio_have_staged (void)
 
void pgaio_closing_fd (int fd)
 

Variables

PGDLLIMPORT int io_method
 
PGDLLIMPORT int io_max_concurrency
 

Macro Definition Documentation

◆ DEFAULT_IO_METHOD

#define DEFAULT_IO_METHOD   IOMETHOD_WORKER

Definition at line 34 of file aio.h.

◆ PGAIO_HANDLE_MAX_CALLBACKS

#define PGAIO_HANDLE_MAX_CALLBACKS   4

Definition at line 248 of file aio.h.

◆ PGAIO_OP_COUNT

#define PGAIO_OP_COUNT   (PGAIO_OP_WRITEV + 1)

Definition at line 99 of file aio.h.

◆ PGAIO_TID_COUNT

#define PGAIO_TID_COUNT   (PGAIO_TID_INVALID + 1)

Definition at line 114 of file aio.h.

Typedef Documentation

◆ IoMethod

typedef enum IoMethod IoMethod

◆ PgAioHandleCallbackComplete

typedef PgAioResult(* PgAioHandleCallbackComplete) (PgAioHandle *ioh, PgAioResult prior_result, uint8 cb_flags)

Definition at line 190 of file aio.h.

◆ PgAioHandleCallbackID

◆ PgAioHandleCallbackReport

typedef void(* PgAioHandleCallbackReport) (PgAioResult result, const PgAioTargetData *target_data, int elevel)

Definition at line 191 of file aio.h.

◆ PgAioHandleCallbackStage

typedef void(* PgAioHandleCallbackStage) (PgAioHandle *ioh, uint8 cb_flags)

Definition at line 189 of file aio.h.

◆ PgAioHandleFlags

◆ PgAioOp

typedef enum PgAioOp PgAioOp

◆ PgAioTargetID

Enumeration Type Documentation

◆ IoMethod

enum IoMethod
Enumerator
IOMETHOD_SYNC 
IOMETHOD_WORKER 

Definition at line 27 of file aio.h.

28{
29 IOMETHOD_SYNC = 0,
31} IoMethod;
IoMethod
Definition: aio.h:28
@ IOMETHOD_WORKER
Definition: aio.h:30
@ IOMETHOD_SYNC
Definition: aio.h:29

◆ PgAioHandleCallbackID

Enumerator
PGAIO_HCB_INVALID 

Definition at line 183 of file aio.h.

184{
PgAioHandleCallbackID
Definition: aio.h:184
@ PGAIO_HCB_INVALID
Definition: aio.h:185

◆ PgAioHandleFlags

Enumerator
PGAIO_HF_REFERENCES_LOCAL 
PGAIO_HF_SYNCHRONOUS 
PGAIO_HF_BUFFERED 

Definition at line 40 of file aio.h.

41{
42 /*
43 * The IO references backend local memory.
44 *
45 * This needs to be set on an IO whenever the IO references process-local
46 * memory. Some IO methods do not support executing IO that references
47 * process local memory and thus need to fall back to executing IO
48 * synchronously for IOs with this flag set.
49 *
50 * Required for correctness.
51 */
53
54 /*
55 * Hint that IO will be executed synchronously.
56 *
57 * This can make it a bit cheaper to execute synchronous IO via the AIO
58 * interface, to avoid needing an AIO and non-AIO version of code.
59 *
60 * Advantageous to set, if applicable, but not required for correctness.
61 */
62 PGAIO_HF_SYNCHRONOUS = 1 << 0,
63
64 /*
65 * IO is using buffered IO, used to control heuristic in some IO methods.
66 *
67 * Advantageous to set, if applicable, but not required for correctness.
68 */
69 PGAIO_HF_BUFFERED = 1 << 2,
PgAioHandleFlags
Definition: aio.h:41
@ PGAIO_HF_SYNCHRONOUS
Definition: aio.h:62
@ PGAIO_HF_REFERENCES_LOCAL
Definition: aio.h:52
@ PGAIO_HF_BUFFERED
Definition: aio.h:69

◆ PgAioOp

enum PgAioOp
Enumerator
PGAIO_OP_INVALID 
PGAIO_OP_READV 
PGAIO_OP_WRITEV 

Definition at line 79 of file aio.h.

80{
81 /* intentionally the zero value, to help catch zeroed memory etc */
83
86
97} PgAioOp;
PgAioOp
Definition: aio.h:80
@ PGAIO_OP_WRITEV
Definition: aio.h:85
@ PGAIO_OP_INVALID
Definition: aio.h:82
@ PGAIO_OP_READV
Definition: aio.h:84

◆ PgAioTargetID

Enumerator
PGAIO_TID_INVALID 

Definition at line 108 of file aio.h.

109{
110 /* intentionally the zero value, to help catch zeroed memory etc */
PgAioTargetID
Definition: aio.h:109
@ PGAIO_TID_INVALID
Definition: aio.h:111

Function Documentation

◆ pgaio_closing_fd()

void pgaio_closing_fd ( int  fd)

Definition at line 1107 of file aio.c.

1108{
1109 /*
1110 * Might be called before AIO is initialized or in a subprocess that
1111 * doesn't use AIO.
1112 */
1113 if (!pgaio_my_backend)
1114 return;
1115
1116 /*
1117 * For now just submit all staged IOs - we could be more selective, but
1118 * it's probably not worth it.
1119 */
1121}
PgAioBackend * pgaio_my_backend
Definition: aio.c:79
void pgaio_submit_staged(void)
Definition: aio.c:1010

References pgaio_my_backend, and pgaio_submit_staged().

◆ pgaio_enter_batchmode()

void pgaio_enter_batchmode ( void  )

Definition at line 968 of file aio.c.

969{
971 elog(ERROR, "starting batch while batch already in progress");
973}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225

References elog, ERROR, PgAioBackend::in_batchmode, and pgaio_my_backend.

◆ pgaio_exit_batchmode()

void pgaio_exit_batchmode ( void  )

Definition at line 979 of file aio.c.

980{
982
985}
Assert(PointerIsAligned(start, uint64))

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

◆ pgaio_have_staged()

bool pgaio_have_staged ( void  )

◆ pgaio_io_acquire()

PgAioHandle * pgaio_io_acquire ( struct ResourceOwnerData resowner,
PgAioReturn ret 
)

Definition at line 165 of file aio.c.

166{
167 PgAioHandle *h;
168
169 while (true)
170 {
171 h = pgaio_io_acquire_nb(resowner, ret);
172
173 if (h != NULL)
174 return h;
175
176 /*
177 * Evidently all handles by this backend are in use. Just wait for
178 * some to complete.
179 */
181 }
182}
static void pgaio_io_wait_for_free(void)
Definition: aio.c:693
PgAioHandle * pgaio_io_acquire_nb(struct ResourceOwnerData *resowner, PgAioReturn *ret)
Definition: aio.c:191

References pgaio_io_acquire_nb(), and pgaio_io_wait_for_free().

◆ pgaio_io_acquire_nb()

PgAioHandle * pgaio_io_acquire_nb ( struct ResourceOwnerData resowner,
PgAioReturn ret 
)

Definition at line 191 of file aio.c.

192{
194 {
197 }
198
200 elog(ERROR, "API violation: Only one IO can be handed out");
201
203 {
205 PgAioHandle *ioh = dclist_container(PgAioHandle, node, ion);
206
207 Assert(ioh->state == PGAIO_HS_IDLE);
209
212
213 if (resowner)
215
216 if (ret)
217 {
218 ioh->report_return = ret;
220 }
221
222 return ioh;
223 }
224
225 return NULL;
226}
static void pgaio_io_update_state(PgAioHandle *ioh, PgAioHandleState new_state)
Definition: aio.c:366
static void pgaio_io_resowner_register(PgAioHandle *ioh)
Definition: aio.c:382
@ PGAIO_HS_IDLE
Definition: aio_internal.h:41
@ PGAIO_HS_HANDED_OUT
Definition: aio_internal.h:48
#define PGAIO_SUBMIT_BATCH_SIZE
Definition: aio_internal.h:28
@ PGAIO_RS_UNKNOWN
Definition: aio_types.h:76
ProcNumber MyProcNumber
Definition: globals.c:89
#define dclist_container(type, membername, ptr)
Definition: ilist.h:947
static bool dclist_is_empty(const dclist_head *head)
Definition: ilist.h:682
static dlist_node * dclist_pop_head_node(dclist_head *head)
Definition: ilist.h:789
dclist_head idle_ios
Definition: aio_internal.h:186
PgAioHandle * handed_out_io
Definition: aio_internal.h:195
int32 owner_procno
Definition: aio_internal.h:120
PgAioReturn * report_return
Definition: aio_internal.h:166
PgAioHandleState state
Definition: aio_internal.h:94
uint32 status
Definition: aio_types.h:95
PgAioResult result
Definition: aio_types.h:112

References Assert(), dclist_container, dclist_is_empty(), dclist_pop_head_node(), elog, ERROR, PgAioBackend::handed_out_io, PgAioBackend::idle_ios, MyProcNumber, PgAioBackend::num_staged_ios, PgAioHandle::owner_procno, PGAIO_HS_HANDED_OUT, PGAIO_HS_IDLE, pgaio_io_resowner_register(), pgaio_io_update_state(), pgaio_my_backend, PGAIO_RS_UNKNOWN, PGAIO_SUBMIT_BATCH_SIZE, pgaio_submit_staged(), PgAioHandle::report_return, PgAioReturn::result, PgAioHandle::state, and PgAioResult::status.

Referenced by pgaio_io_acquire().

◆ pgaio_io_get_handle_data()

uint64 * pgaio_io_get_handle_data ( PgAioHandle ioh,
uint8 len 
)

Definition at line 145 of file aio_callback.c.

146{
147 Assert(ioh->handle_data_len > 0);
148
149 *len = ioh->handle_data_len;
150
151 return &pgaio_ctl->handle_data[ioh->iovec_off];
152}
PgAioCtl * pgaio_ctl
Definition: aio.c:76
const void size_t len
uint64 * handle_data
Definition: aio_internal.h:238
uint8 handle_data_len
Definition: aio_internal.h:117
uint32 iovec_off
Definition: aio_internal.h:159

References Assert(), PgAioCtl::handle_data, PgAioHandle::handle_data_len, PgAioHandle::iovec_off, len, and pgaio_ctl.

◆ pgaio_io_get_id()

int pgaio_io_get_id ( PgAioHandle ioh)

Definition at line 322 of file aio.c.

323{
324 Assert(ioh >= pgaio_ctl->io_handles &&
326 return ioh - pgaio_ctl->io_handles;
327}
PgAioHandle * io_handles
Definition: aio_internal.h:241
uint32 io_handle_count
Definition: aio_internal.h:240

References Assert(), PgAioCtl::io_handle_count, PgAioCtl::io_handles, and pgaio_ctl.

Referenced by pgaio_io_wait_for_free(), and pgaio_worker_submission_queue_insert().

◆ pgaio_io_get_iovec()

int pgaio_io_get_iovec ( PgAioHandle ioh,
struct iovec **  iov 
)

Definition at line 42 of file aio_io.c.

43{
45
46 *iov = &pgaio_ctl->iovecs[ioh->iovec_off];
47
48 return PG_IOV_MAX;
49}
#define PG_IOV_MAX
Definition: pg_iovec.h:41
struct iovec * iovecs
Definition: aio_internal.h:229

References Assert(), PgAioHandle::iovec_off, PgAioCtl::iovecs, PG_IOV_MAX, pgaio_ctl, PGAIO_HS_HANDED_OUT, and PgAioHandle::state.

◆ pgaio_io_get_op()

PgAioOp pgaio_io_get_op ( PgAioHandle ioh)

Definition at line 52 of file aio_io.c.

53{
54 return ioh->op;
55}
PgAioOp op
Definition: aio_internal.h:100

References PgAioHandle::op.

◆ pgaio_io_get_op_data()

PgAioOpData * pgaio_io_get_op_data ( PgAioHandle ioh)

Definition at line 58 of file aio_io.c.

59{
60 return &ioh->op_data;
61}
PgAioOpData op_data
Definition: aio_internal.h:169

References PgAioHandle::op_data.

◆ pgaio_io_get_owner()

ProcNumber pgaio_io_get_owner ( PgAioHandle ioh)

Definition at line 335 of file aio.c.

336{
337 return ioh->owner_procno;
338}

References PgAioHandle::owner_procno.

◆ pgaio_io_get_target_data()

PgAioTargetData * pgaio_io_get_target_data ( PgAioHandle ioh)

Definition at line 70 of file aio_target.c.

71{
72 return &ioh->target_data;
73}
PgAioTargetData target_data
Definition: aio_internal.h:176

References PgAioHandle::target_data.

◆ pgaio_io_get_target_description()

char * pgaio_io_get_target_description ( PgAioHandle ioh)

Definition at line 81 of file aio_target.c.

82{
84}
static const PgAioTargetInfo * pgaio_target_info[]
Definition: aio_target.c:24
PgAioTargetID target
Definition: aio_internal.h:97
char *(* describe_identity)(const PgAioTargetData *sd)
Definition: aio.h:158

References PgAioTargetInfo::describe_identity, pgaio_target_info, PgAioHandle::target, and PgAioHandle::target_data.

◆ pgaio_io_get_wref()

void pgaio_io_get_wref ( PgAioHandle ioh,
PgAioWaitRef iow 
)

Definition at line 346 of file aio.c.

347{
349 ioh->state == PGAIO_HS_DEFINED ||
350 ioh->state == PGAIO_HS_STAGED);
351 Assert(ioh->generation != 0);
352
353 iow->aio_index = ioh - pgaio_ctl->io_handles;
354 iow->generation_upper = (uint32) (ioh->generation >> 32);
355 iow->generation_lower = (uint32) ioh->generation;
356}
@ PGAIO_HS_STAGED
Definition: aio_internal.h:61
@ PGAIO_HS_DEFINED
Definition: aio_internal.h:54
uint32_t uint32
Definition: c.h:502
uint64 generation
Definition: aio_internal.h:141
uint32 generation_upper
Definition: aio_types.h:45
uint32 aio_index
Definition: aio_types.h:35
uint32 generation_lower
Definition: aio_types.h:46

References PgAioWaitRef::aio_index, Assert(), PgAioHandle::generation, PgAioWaitRef::generation_lower, PgAioWaitRef::generation_upper, PgAioCtl::io_handles, pgaio_ctl, PGAIO_HS_DEFINED, PGAIO_HS_HANDED_OUT, PGAIO_HS_STAGED, and PgAioHandle::state.

◆ pgaio_io_has_target()

bool pgaio_io_has_target ( PgAioHandle ioh)

Definition at line 38 of file aio_target.c.

39{
40 return ioh->target != PGAIO_TID_INVALID;
41}

References PGAIO_TID_INVALID, and PgAioHandle::target.

Referenced by pgaio_io_before_prep(), and pgaio_io_stage().

◆ pgaio_io_prep_readv()

void pgaio_io_prep_readv ( PgAioHandle ioh,
int  fd,
int  iovcnt,
uint64  offset 
)

Definition at line 78 of file aio_io.c.

80{
82
83 ioh->op_data.read.fd = fd;
84 ioh->op_data.read.offset = offset;
85 ioh->op_data.read.iov_length = iovcnt;
86
88}
void pgaio_io_stage(PgAioHandle *ioh, PgAioOp op)
Definition: aio.c:397
static void pgaio_io_before_prep(PgAioHandle *ioh)
Definition: aio_io.c:156
static int fd(const char *x, int i)
Definition: preproc-init.c:105
uint64 offset
Definition: aio.h:131
int fd
Definition: aio.h:129
uint16 iov_length
Definition: aio.h:130
struct PgAioOpData::@122 read

References PgAioOpData::fd, fd(), PgAioOpData::iov_length, PgAioOpData::offset, PgAioHandle::op_data, pgaio_io_before_prep(), pgaio_io_stage(), PGAIO_OP_READV, and PgAioOpData::read.

◆ pgaio_io_prep_writev()

void pgaio_io_prep_writev ( PgAioHandle ioh,
int  fd,
int  iovcnt,
uint64  offset 
)

Definition at line 91 of file aio_io.c.

93{
95
96 ioh->op_data.write.fd = fd;
97 ioh->op_data.write.offset = offset;
98 ioh->op_data.write.iov_length = iovcnt;
99
101}
struct PgAioOpData::@123 write

References PgAioOpData::fd, fd(), PgAioOpData::iov_length, PgAioOpData::offset, PgAioHandle::op_data, pgaio_io_before_prep(), pgaio_io_stage(), PGAIO_OP_WRITEV, and PgAioOpData::write.

◆ pgaio_io_register_callbacks()

void pgaio_io_register_callbacks ( PgAioHandle ioh,
PgAioHandleCallbackID  cb_id,
uint8  cb_data 
)

Definition at line 78 of file aio_callback.c.

80{
81 const PgAioHandleCallbacksEntry *ce = &aio_handle_cbs[cb_id];
82
83 if (cb_id >= lengthof(aio_handle_cbs))
84 elog(ERROR, "callback %d is out of range", cb_id);
85 if (aio_handle_cbs[cb_id].cb->complete_shared == NULL &&
86 aio_handle_cbs[cb_id].cb->complete_local == NULL)
87 elog(ERROR, "callback %d does not have a completion callback", cb_id);
89 elog(PANIC, "too many callbacks, the max is %d",
91 ioh->callbacks[ioh->num_callbacks] = cb_id;
92 ioh->callbacks_data[ioh->num_callbacks] = cb_data;
93
95 "adding cb #%d, id %d/%s",
96 ioh->num_callbacks + 1,
97 cb_id, ce->name);
98
99 ioh->num_callbacks++;
100}
#define PGAIO_HANDLE_MAX_CALLBACKS
Definition: aio.h:248
static const PgAioHandleCallbacksEntry aio_handle_cbs[]
Definition: aio_callback.c:37
#define pgaio_debug_io(elevel, ioh, msg,...)
Definition: aio_internal.h:358
#define lengthof(array)
Definition: c.h:759
#define DEBUG3
Definition: elog.h:28
#define PANIC
Definition: elog.h:42
const PgAioHandleCallbacks *const cb
Definition: aio_callback.c:28
const char *const name
Definition: aio_callback.c:29
PgAioHandleCallbackComplete complete_local
Definition: aio.h:232
uint8 callbacks[PGAIO_HANDLE_MAX_CALLBACKS]
Definition: aio_internal.h:108
uint8 callbacks_data[PGAIO_HANDLE_MAX_CALLBACKS]
Definition: aio_internal.h:111
uint8 num_callbacks
Definition: aio_internal.h:105

References aio_handle_cbs, PgAioHandle::callbacks, PgAioHandle::callbacks_data, PgAioHandleCallbacksEntry::cb, PgAioHandleCallbacks::complete_local, DEBUG3, elog, ERROR, lengthof, PgAioHandleCallbacksEntry::name, PgAioHandle::num_callbacks, PANIC, pgaio_debug_io, and PGAIO_HANDLE_MAX_CALLBACKS.

◆ pgaio_io_release()

void pgaio_io_release ( PgAioHandle ioh)

Definition at line 234 of file aio.c.

235{
237 {
239 Assert(ioh->resowner);
240
242 pgaio_io_reclaim(ioh);
243 }
244 else
245 {
246 elog(ERROR, "release in unexpected state");
247 }
248}
static void pgaio_io_reclaim(PgAioHandle *ioh)
Definition: aio.c:621
struct ResourceOwnerData * resowner
Definition: aio_internal.h:137

References Assert(), elog, ERROR, PgAioBackend::handed_out_io, PGAIO_HS_HANDED_OUT, pgaio_io_reclaim(), pgaio_my_backend, PgAioHandle::resowner, and PgAioHandle::state.

◆ pgaio_io_release_resowner()

void pgaio_io_release_resowner ( struct dlist_node ioh_node,
bool  on_error 
)

Definition at line 254 of file aio.c.

255{
256 PgAioHandle *ioh = dlist_container(PgAioHandle, resowner_node, ioh_node);
257
258 Assert(ioh->resowner);
259
261 ioh->resowner = NULL;
262
263 switch (ioh->state)
264 {
265 case PGAIO_HS_IDLE:
266 elog(ERROR, "unexpected");
267 break;
270
272 {
274 if (!on_error)
275 elog(WARNING, "leaked AIO handle");
276 }
277
278 pgaio_io_reclaim(ioh);
279 break;
280 case PGAIO_HS_DEFINED:
281 case PGAIO_HS_STAGED:
282 if (!on_error)
283 elog(WARNING, "AIO handle was not submitted");
285 break;
290 /* this is expected to happen */
291 break;
292 }
293
294 /*
295 * Need to unregister the reporting of the IO's result, the memory it's
296 * referencing likely has gone away.
297 */
298 if (ioh->report_return)
299 ioh->report_return = NULL;
300}
@ PGAIO_HS_COMPLETED_SHARED
Definition: aio_internal.h:77
@ PGAIO_HS_SUBMITTED
Definition: aio_internal.h:64
@ PGAIO_HS_COMPLETED_IO
Definition: aio_internal.h:67
@ PGAIO_HS_COMPLETED_LOCAL
Definition: aio_internal.h:84
#define WARNING
Definition: elog.h:36
#define dlist_container(type, membername, ptr)
Definition: ilist.h:593
void ResourceOwnerForgetAioHandle(ResourceOwner owner, struct dlist_node *ioh_node)
Definition: resowner.c:1110
dlist_node resowner_node
Definition: aio_internal.h:138

References Assert(), dlist_container, elog, ERROR, PgAioBackend::handed_out_io, PGAIO_HS_COMPLETED_IO, PGAIO_HS_COMPLETED_LOCAL, PGAIO_HS_COMPLETED_SHARED, PGAIO_HS_DEFINED, PGAIO_HS_HANDED_OUT, PGAIO_HS_IDLE, PGAIO_HS_STAGED, PGAIO_HS_SUBMITTED, pgaio_io_reclaim(), pgaio_my_backend, pgaio_submit_staged(), PgAioHandle::report_return, ResourceOwnerForgetAioHandle(), PgAioHandle::resowner, PgAioHandle::resowner_node, PgAioHandle::state, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

◆ pgaio_io_set_flag()

void pgaio_io_set_flag ( PgAioHandle ioh,
PgAioHandleFlags  flag 
)

Definition at line 310 of file aio.c.

311{
313
314 ioh->flags |= flag;
315}
char * flag(int b)
Definition: test-ctype.c:33

References Assert(), flag(), PgAioHandle::flags, PGAIO_HS_HANDED_OUT, and PgAioHandle::state.

◆ pgaio_io_set_handle_data_32()

void pgaio_io_set_handle_data_32 ( PgAioHandle ioh,
uint32 data,
uint8  len 
)

Definition at line 130 of file aio_callback.c.

131{
133 Assert(ioh->handle_data_len == 0);
135
136 for (int i = 0; i < len; i++)
138 ioh->handle_data_len = len;
139}
int i
Definition: isn.c:74
const void * data

References Assert(), data, PgAioCtl::handle_data, PgAioHandle::handle_data_len, i, PgAioHandle::iovec_off, len, PG_IOV_MAX, pgaio_ctl, PGAIO_HS_HANDED_OUT, and PgAioHandle::state.

◆ pgaio_io_set_handle_data_64()

void pgaio_io_set_handle_data_64 ( PgAioHandle ioh,
uint64 data,
uint8  len 
)

Definition at line 113 of file aio_callback.c.

114{
116 Assert(ioh->handle_data_len == 0);
118
119 for (int i = 0; i < len; i++)
121 ioh->handle_data_len = len;
122}

References Assert(), data, PgAioCtl::handle_data, PgAioHandle::handle_data_len, i, PgAioHandle::iovec_off, len, PG_IOV_MAX, pgaio_ctl, PGAIO_HS_HANDED_OUT, and PgAioHandle::state.

◆ pgaio_io_set_target()

void pgaio_io_set_target ( PgAioHandle ioh,
PgAioTargetID  targetid 
)

Definition at line 61 of file aio_target.c.

62{
65
66 ioh->target = targetid;
67}

References Assert(), PGAIO_HS_HANDED_OUT, PGAIO_TID_INVALID, PgAioHandle::state, and PgAioHandle::target.

◆ pgaio_result_report()

void pgaio_result_report ( PgAioResult  result,
const PgAioTargetData target_data,
int  elevel 
)

Definition at line 162 of file aio_callback.c.

163{
164 PgAioHandleCallbackID cb_id = result.id;
165 const PgAioHandleCallbacksEntry *ce = &aio_handle_cbs[cb_id];
166
167 Assert(result.status != PGAIO_RS_UNKNOWN);
168 Assert(result.status != PGAIO_RS_OK);
169
170 if (ce->cb->report == NULL)
171 elog(ERROR, "callback %d/%s does not have report callback",
172 result.id, ce->name);
173
174 ce->cb->report(result, target_data, elevel);
175}
@ PGAIO_RS_OK
Definition: aio_types.h:77
PgAioHandleCallbackReport report
Definition: aio.h:239
uint32 id
Definition: aio_types.h:92

References aio_handle_cbs, Assert(), PgAioHandleCallbacksEntry::cb, elog, ERROR, PgAioResult::id, PgAioHandleCallbacksEntry::name, PGAIO_RS_OK, PGAIO_RS_UNKNOWN, PgAioHandleCallbacks::report, and PgAioResult::status.

◆ pgaio_submit_staged()

void pgaio_submit_staged ( void  )

Definition at line 1010 of file aio.c.

1011{
1012 int total_submitted = 0;
1013 int did_submit;
1014
1016 return;
1017
1018
1020
1023
1025
1026 total_submitted += did_submit;
1027
1028 Assert(total_submitted == did_submit);
1029
1031
1033 "aio: submitted %d IOs",
1034 total_submitted);
1035}
const IoMethodOps * pgaio_method_ops
Definition: aio.c:88
#define pgaio_debug(elevel, msg,...)
Definition: aio_internal.h:345
#define DEBUG4
Definition: elog.h:27
#define START_CRIT_SECTION()
Definition: miscadmin.h:149
#define END_CRIT_SECTION()
Definition: miscadmin.h:151
int(* submit)(uint16 num_staged_ios, PgAioHandle **staged_ios)
Definition: aio_internal.h:285
PgAioHandle * staged_ios[PGAIO_SUBMIT_BATCH_SIZE]
Definition: aio_internal.h:204

References Assert(), DEBUG4, END_CRIT_SECTION, PgAioBackend::num_staged_ios, pgaio_debug, pgaio_method_ops, pgaio_my_backend, PgAioBackend::staged_ios, START_CRIT_SECTION, and IoMethodOps::submit.

Referenced by pgaio_closing_fd(), pgaio_error_cleanup(), pgaio_exit_batchmode(), pgaio_io_acquire_nb(), pgaio_io_release_resowner(), pgaio_io_stage(), and pgaio_io_wait_for_free().

◆ pgaio_wref_check_done()

bool pgaio_wref_check_done ( PgAioWaitRef iow)

Definition at line 897 of file aio.c.

898{
899 uint64 ref_generation;
901 bool am_owner;
902 PgAioHandle *ioh;
903
904 ioh = pgaio_io_from_wref(iow, &ref_generation);
905
906 if (pgaio_io_was_recycled(ioh, ref_generation, &state))
907 return true;
908
909 if (state == PGAIO_HS_IDLE)
910 return true;
911
912 am_owner = ioh->owner_procno == MyProcNumber;
913
916 {
917 if (am_owner)
918 pgaio_io_reclaim(ioh);
919 return true;
920 }
921
922 /*
923 * XXX: It likely would be worth checking in with the io method, to give
924 * the IO method a chance to check if there are completion events queued.
925 */
926
927 return false;
928}
static PgAioHandle * pgaio_io_from_wref(PgAioWaitRef *iow, uint64 *ref_generation)
Definition: aio.c:785
bool pgaio_io_was_recycled(PgAioHandle *ioh, uint64 ref_generation, PgAioHandleState *state)
Definition: aio.c:523
PgAioHandleState
Definition: aio_internal.h:39
uint64_t uint64
Definition: c.h:503
Definition: regguts.h:323

References MyProcNumber, PgAioHandle::owner_procno, PGAIO_HS_COMPLETED_LOCAL, PGAIO_HS_COMPLETED_SHARED, PGAIO_HS_IDLE, pgaio_io_from_wref(), pgaio_io_reclaim(), and pgaio_io_was_recycled().

◆ pgaio_wref_clear()

void pgaio_wref_clear ( PgAioWaitRef iow)

Definition at line 856 of file aio.c.

857{
859}
#define PG_UINT32_MAX
Definition: c.h:561

References PgAioWaitRef::aio_index, and PG_UINT32_MAX.

◆ pgaio_wref_get_id()

int pgaio_wref_get_id ( PgAioWaitRef iow)

Definition at line 872 of file aio.c.

873{
875 return iow->aio_index;
876}
bool pgaio_wref_valid(PgAioWaitRef *iow)
Definition: aio.c:863

References PgAioWaitRef::aio_index, Assert(), and pgaio_wref_valid().

◆ pgaio_wref_valid()

bool pgaio_wref_valid ( PgAioWaitRef iow)

Definition at line 863 of file aio.c.

864{
865 return iow->aio_index != PG_UINT32_MAX;
866}

References PgAioWaitRef::aio_index, and PG_UINT32_MAX.

Referenced by pgaio_wref_get_id().

◆ pgaio_wref_wait()

void pgaio_wref_wait ( PgAioWaitRef iow)

Definition at line 883 of file aio.c.

884{
885 uint64 ref_generation;
886 PgAioHandle *ioh;
887
888 ioh = pgaio_io_from_wref(iow, &ref_generation);
889
890 pgaio_io_wait(ioh, ref_generation);
891}
static void pgaio_io_wait(PgAioHandle *ioh, uint64 ref_generation)
Definition: aio.c:536

References pgaio_io_from_wref(), and pgaio_io_wait().

Variable Documentation

◆ io_max_concurrency

PGDLLIMPORT int io_max_concurrency
extern

◆ io_method

PGDLLIMPORT int io_method
extern

Definition at line 72 of file aio.c.

Referenced by pgaio_workers_enabled().