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_SMGR + 1)
 
#define PGAIO_HCB_MAX   PGAIO_HCB_LOCAL_BUFFER_READV
 
#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 , PGAIO_TID_SMGR }
 
enum  PgAioHandleCallbackID { PGAIO_HCB_INVALID = 0 , PGAIO_HCB_MD_READV , PGAIO_HCB_SHARED_BUFFER_READV , PGAIO_HCB_LOCAL_BUFFER_READV }
 

Functions

 StaticAssertDecl (PGAIO_HCB_MAX<=(1<< PGAIO_RESULT_ID_BITS), "PGAIO_HCB_MAX is too big for PGAIO_RESULT_ID_BITS")
 
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_start_readv (PgAioHandle *ioh, int fd, int iovcnt, uint64 offset)
 
void pgaio_io_start_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 42 of file aio.h.

◆ PGAIO_HANDLE_MAX_CALLBACKS

#define PGAIO_HANDLE_MAX_CALLBACKS   4

Definition at line 267 of file aio.h.

◆ PGAIO_HCB_MAX

#define PGAIO_HCB_MAX   PGAIO_HCB_LOCAL_BUFFER_READV

Definition at line 203 of file aio.h.

◆ PGAIO_OP_COUNT

#define PGAIO_OP_COUNT   (PGAIO_OP_WRITEV + 1)

Definition at line 107 of file aio.h.

◆ PGAIO_TID_COUNT

#define PGAIO_TID_COUNT   (PGAIO_TID_SMGR + 1)

Definition at line 123 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 209 of file aio.h.

◆ PgAioHandleCallbackID

◆ PgAioHandleCallbackReport

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

Definition at line 210 of file aio.h.

◆ PgAioHandleCallbackStage

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

Definition at line 208 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 32 of file aio.h.

33{
34 IOMETHOD_SYNC = 0,
36#ifdef IOMETHOD_IO_URING_ENABLED
37 IOMETHOD_IO_URING,
38#endif
39} IoMethod;
IoMethod
Definition: aio.h:33
@ IOMETHOD_WORKER
Definition: aio.h:35
@ IOMETHOD_SYNC
Definition: aio.h:34

◆ PgAioHandleCallbackID

Enumerator
PGAIO_HCB_INVALID 
PGAIO_HCB_MD_READV 
PGAIO_HCB_SHARED_BUFFER_READV 
PGAIO_HCB_LOCAL_BUFFER_READV 

Definition at line 192 of file aio.h.

193{
195
197
199
PgAioHandleCallbackID
Definition: aio.h:193
@ PGAIO_HCB_MD_READV
Definition: aio.h:196
@ PGAIO_HCB_LOCAL_BUFFER_READV
Definition: aio.h:200
@ PGAIO_HCB_SHARED_BUFFER_READV
Definition: aio.h:198
@ PGAIO_HCB_INVALID
Definition: aio.h:194

◆ PgAioHandleFlags

Enumerator
PGAIO_HF_REFERENCES_LOCAL 
PGAIO_HF_SYNCHRONOUS 
PGAIO_HF_BUFFERED 

Definition at line 48 of file aio.h.

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

◆ PgAioOp

enum PgAioOp
Enumerator
PGAIO_OP_INVALID 
PGAIO_OP_READV 
PGAIO_OP_WRITEV 

Definition at line 87 of file aio.h.

88{
89 /* intentionally the zero value, to help catch zeroed memory etc */
91
94
105} PgAioOp;
PgAioOp
Definition: aio.h:88
@ PGAIO_OP_WRITEV
Definition: aio.h:93
@ PGAIO_OP_INVALID
Definition: aio.h:90
@ PGAIO_OP_READV
Definition: aio.h:92

◆ PgAioTargetID

Enumerator
PGAIO_TID_INVALID 
PGAIO_TID_SMGR 

Definition at line 116 of file aio.h.

117{
118 /* intentionally the zero value, to help catch zeroed memory etc */
PgAioTargetID
Definition: aio.h:117
@ PGAIO_TID_SMGR
Definition: aio.h:120
@ PGAIO_TID_INVALID
Definition: aio.h:119

Function Documentation

◆ pgaio_closing_fd()

void pgaio_closing_fd ( int  fd)

Definition at line 1117 of file aio.c.

1118{
1119 /*
1120 * Might be called before AIO is initialized or in a subprocess that
1121 * doesn't use AIO.
1122 */
1123 if (!pgaio_my_backend)
1124 return;
1125
1126 /*
1127 * For now just submit all staged IOs - we could be more selective, but
1128 * it's probably not worth it.
1129 */
1131
1132 /*
1133 * If requested by the IO method, wait for all IOs that use the
1134 * to-be-closed FD.
1135 */
1137 {
1138 /*
1139 * As waiting for one IO to complete may complete multiple IOs, we
1140 * can't just use a mutable list iterator. The maximum number of
1141 * in-flight IOs is fairly small, so just restart the loop after
1142 * waiting for an IO.
1143 */
1145 {
1146 dlist_iter iter;
1147 PgAioHandle *ioh = NULL;
1148
1150 {
1151 ioh = dclist_container(PgAioHandle, node, iter.cur);
1152
1153 if (pgaio_io_uses_fd(ioh, fd))
1154 break;
1155 else
1156 ioh = NULL;
1157 }
1158
1159 if (!ioh)
1160 break;
1161
1162 /* see comment in pgaio_io_wait_for_free() about raciness */
1163 pgaio_io_wait(ioh, ioh->generation);
1164 }
1165 }
1166}
PgAioBackend * pgaio_my_backend
Definition: aio.c:84
const IoMethodOps * pgaio_method_ops
Definition: aio.c:96
void pgaio_submit_staged(void)
Definition: aio.c:1020
static void pgaio_io_wait(PgAioHandle *ioh, uint64 ref_generation)
Definition: aio.c:544
bool pgaio_io_uses_fd(PgAioHandle *ioh, int fd)
Definition: aio_io.c:197
#define dclist_container(type, membername, ptr)
Definition: ilist.h:947
static bool dclist_is_empty(const dclist_head *head)
Definition: ilist.h:682
#define dclist_foreach(iter, lhead)
Definition: ilist.h:970
static int fd(const char *x, int i)
Definition: preproc-init.c:105
bool wait_on_fd_before_close
Definition: aio_internal.h:262
dclist_head in_flight_ios
Definition: aio_internal.h:219
uint64 generation
Definition: aio_internal.h:146
dlist_node * cur
Definition: ilist.h:179

References dlist_iter::cur, dclist_container, dclist_foreach, dclist_is_empty(), fd(), PgAioHandle::generation, PgAioBackend::in_flight_ios, pgaio_io_uses_fd(), pgaio_io_wait(), pgaio_method_ops, pgaio_my_backend, pgaio_submit_staged(), and IoMethodOps::wait_on_fd_before_close.

Referenced by CloseTransientFile(), FileClose(), FreeDesc(), and LruDelete().

◆ pgaio_enter_batchmode()

void pgaio_enter_batchmode ( void  )

Definition at line 978 of file aio.c.

979{
981 elog(ERROR, "starting batch while batch already in progress");
983}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226

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

Referenced by batch_start(), read_rel_block_ll(), and read_stream_look_ahead().

◆ pgaio_exit_batchmode()

void pgaio_exit_batchmode ( void  )

Definition at line 989 of file aio.c.

990{
992
995}
Assert(PointerIsAligned(start, uint64))

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

Referenced by batch_end(), read_rel_block_ll(), and read_stream_look_ahead().

◆ pgaio_have_staged()

bool pgaio_have_staged ( void  )

◆ pgaio_io_acquire()

PgAioHandle * pgaio_io_acquire ( struct ResourceOwnerData resowner,
PgAioReturn ret 
)

Definition at line 173 of file aio.c.

174{
175 PgAioHandle *h;
176
177 while (true)
178 {
179 h = pgaio_io_acquire_nb(resowner, ret);
180
181 if (h != NULL)
182 return h;
183
184 /*
185 * Evidently all handles by this backend are in use. Just wait for
186 * some to complete.
187 */
189 }
190}
static void pgaio_io_wait_for_free(void)
Definition: aio.c:701
PgAioHandle * pgaio_io_acquire_nb(struct ResourceOwnerData *resowner, PgAioReturn *ret)
Definition: aio.c:199

References pgaio_io_acquire_nb(), and pgaio_io_wait_for_free().

Referenced by AsyncReadBuffers(), handle_get(), handle_get_and_error(), handle_get_release(), handle_get_twice(), and read_rel_block_ll().

◆ pgaio_io_acquire_nb()

PgAioHandle * pgaio_io_acquire_nb ( struct ResourceOwnerData resowner,
PgAioReturn ret 
)

Definition at line 199 of file aio.c.

200{
202 {
205 }
206
208 elog(ERROR, "API violation: Only one IO can be handed out");
209
211 {
213 PgAioHandle *ioh = dclist_container(PgAioHandle, node, ion);
214
215 Assert(ioh->state == PGAIO_HS_IDLE);
217
220
221 if (resowner)
223
224 if (ret)
225 {
226 ioh->report_return = ret;
228 }
229
230 return ioh;
231 }
232
233 return NULL;
234}
static void pgaio_io_update_state(PgAioHandle *ioh, PgAioHandleState new_state)
Definition: aio.c:374
static void pgaio_io_resowner_register(PgAioHandle *ioh)
Definition: aio.c:390
@ PGAIO_HS_IDLE
Definition: aio_internal.h:46
@ PGAIO_HS_HANDED_OUT
Definition: aio_internal.h:53
#define PGAIO_SUBMIT_BATCH_SIZE
Definition: aio_internal.h:28
@ PGAIO_RS_UNKNOWN
Definition: aio_types.h:80
ProcNumber MyProcNumber
Definition: globals.c:91
static dlist_node * dclist_pop_head_node(dclist_head *head)
Definition: ilist.h:789
dclist_head idle_ios
Definition: aio_internal.h:191
PgAioHandle * handed_out_io
Definition: aio_internal.h:200
int32 owner_procno
Definition: aio_internal.h:125
PgAioReturn * report_return
Definition: aio_internal.h:171
PgAioHandleState state
Definition: aio_internal.h:99
uint32 status
Definition: aio_types.h:108
PgAioResult result
Definition: aio_types.h:132

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 AsyncReadBuffers(), and pgaio_io_acquire().

◆ pgaio_io_get_handle_data()

uint64 * pgaio_io_get_handle_data ( PgAioHandle ioh,
uint8 len 
)

Definition at line 154 of file aio_callback.c.

155{
156 Assert(ioh->handle_data_len > 0);
157
158 *len = ioh->handle_data_len;
159
160 return &pgaio_ctl->handle_data[ioh->iovec_off];
161}
PgAioCtl * pgaio_ctl
Definition: aio.c:81
const void size_t len
uint64 * handle_data
Definition: aio_internal.h:243
uint8 handle_data_len
Definition: aio_internal.h:122
uint32 iovec_off
Definition: aio_internal.h:164

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

Referenced by buffer_readv_complete(), and buffer_stage_common().

◆ pgaio_io_get_id()

int pgaio_io_get_id ( PgAioHandle ioh)

Definition at line 330 of file aio.c.

331{
332 Assert(ioh >= pgaio_ctl->io_handles &&
334 return ioh - pgaio_ctl->io_handles;
335}
PgAioHandle * io_handles
Definition: aio_internal.h:246
uint32 io_handle_count
Definition: aio_internal.h:245

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

Referenced by pg_get_aios(), 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:234

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

Referenced by mdstartreadv().

◆ 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:105

References PgAioHandle::op.

Referenced by smgr_aio_reopen().

◆ 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:174

References PgAioHandle::op_data.

Referenced by smgr_aio_reopen().

◆ pgaio_io_get_owner()

ProcNumber pgaio_io_get_owner ( PgAioHandle ioh)

Definition at line 343 of file aio.c.

344{
345 return ioh->owner_procno;
346}

References PgAioHandle::owner_procno.

Referenced by buffer_readv_complete(), and smgr_aio_reopen().

◆ pgaio_io_get_target_data()

PgAioTargetData * pgaio_io_get_target_data ( PgAioHandle ioh)

◆ pgaio_io_get_target_description()

char * pgaio_io_get_target_description ( PgAioHandle ioh)

Definition at line 83 of file aio_target.c.

84{
86}
static const PgAioTargetInfo * pgaio_target_info[]
Definition: aio_target.c:25
PgAioTargetID target
Definition: aio_internal.h:102
char *(* describe_identity)(const PgAioTargetData *sd)
Definition: aio.h:167

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

Referenced by pg_get_aios().

◆ pgaio_io_get_wref()

void pgaio_io_get_wref ( PgAioHandle ioh,
PgAioWaitRef iow 
)

◆ pgaio_io_has_target()

bool pgaio_io_has_target ( PgAioHandle ioh)

Definition at line 40 of file aio_target.c.

41{
42 return ioh->target != PGAIO_TID_INVALID;
43}

References PGAIO_TID_INVALID, and PgAioHandle::target.

Referenced by pgaio_io_before_start(), and pgaio_io_stage().

◆ pgaio_io_register_callbacks()

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

Definition at line 86 of file aio_callback.c.

88{
89 const PgAioHandleCallbacksEntry *ce = &aio_handle_cbs[cb_id];
90
91 Assert(cb_id <= PGAIO_HCB_MAX);
92 if (cb_id >= lengthof(aio_handle_cbs))
93 elog(ERROR, "callback %d is out of range", cb_id);
94 if (aio_handle_cbs[cb_id].cb->complete_shared == NULL &&
95 aio_handle_cbs[cb_id].cb->complete_local == NULL)
96 elog(ERROR, "callback %d does not have a completion callback", cb_id);
98 elog(PANIC, "too many callbacks, the max is %d",
100 ioh->callbacks[ioh->num_callbacks] = cb_id;
101 ioh->callbacks_data[ioh->num_callbacks] = cb_data;
102
104 "adding cb #%d, id %d/%s",
105 ioh->num_callbacks + 1,
106 cb_id, ce->name);
107
108 ioh->num_callbacks++;
109}
#define PGAIO_HANDLE_MAX_CALLBACKS
Definition: aio.h:267
#define PGAIO_HCB_MAX
Definition: aio.h:203
static const PgAioHandleCallbacksEntry aio_handle_cbs[]
Definition: aio_callback.c:39
#define pgaio_debug_io(elevel, ioh, msg,...)
Definition: aio_internal.h:389
#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:30
const char *const name
Definition: aio_callback.c:31
PgAioHandleCallbackComplete complete_local
Definition: aio.h:251
uint8 callbacks[PGAIO_HANDLE_MAX_CALLBACKS]
Definition: aio_internal.h:113
uint8 callbacks_data[PGAIO_HANDLE_MAX_CALLBACKS]
Definition: aio_internal.h:116
uint8 num_callbacks
Definition: aio_internal.h:110

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

Referenced by AsyncReadBuffers(), mdstartreadv(), and read_rel_block_ll().

◆ pgaio_io_release()

void pgaio_io_release ( PgAioHandle ioh)

Definition at line 242 of file aio.c.

243{
245 {
247 Assert(ioh->resowner);
248
250 pgaio_io_reclaim(ioh);
251 }
252 else
253 {
254 elog(ERROR, "release in unexpected state");
255 }
256}
static void pgaio_io_reclaim(PgAioHandle *ioh)
Definition: aio.c:629
struct ResourceOwnerData * resowner
Definition: aio_internal.h:142

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

Referenced by AsyncReadBuffers(), handle_get_release(), and handle_release_last().

◆ pgaio_io_release_resowner()

void pgaio_io_release_resowner ( struct dlist_node ioh_node,
bool  on_error 
)

Definition at line 262 of file aio.c.

263{
264 PgAioHandle *ioh = dlist_container(PgAioHandle, resowner_node, ioh_node);
265
266 Assert(ioh->resowner);
267
269 ioh->resowner = NULL;
270
271 switch (ioh->state)
272 {
273 case PGAIO_HS_IDLE:
274 elog(ERROR, "unexpected");
275 break;
278
280 {
282 if (!on_error)
283 elog(WARNING, "leaked AIO handle");
284 }
285
286 pgaio_io_reclaim(ioh);
287 break;
288 case PGAIO_HS_DEFINED:
289 case PGAIO_HS_STAGED:
290 if (!on_error)
291 elog(WARNING, "AIO handle was not submitted");
293 break;
298 /* this is expected to happen */
299 break;
300 }
301
302 /*
303 * Need to unregister the reporting of the IO's result, the memory it's
304 * referencing likely has gone away.
305 */
306 if (ioh->report_return)
307 ioh->report_return = NULL;
308}
@ PGAIO_HS_COMPLETED_SHARED
Definition: aio_internal.h:82
@ PGAIO_HS_SUBMITTED
Definition: aio_internal.h:69
@ PGAIO_HS_COMPLETED_IO
Definition: aio_internal.h:72
@ PGAIO_HS_COMPLETED_LOCAL
Definition: aio_internal.h:89
#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:143

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

319{
321
322 ioh->flags |= flag;
323}
char * flag(int b)
Definition: test-ctype.c:33

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

Referenced by AsyncReadBuffers(), mdstartreadv(), and read_rel_block_ll().

◆ pgaio_io_set_handle_data_32()

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

Definition at line 139 of file aio_callback.c.

140{
142 Assert(ioh->handle_data_len == 0);
144
145 for (int i = 0; i < len; i++)
147 ioh->handle_data_len = len;
148}
int i
Definition: isn.c:77
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.

Referenced by AsyncReadBuffers(), and read_rel_block_ll().

◆ pgaio_io_set_handle_data_64()

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

Definition at line 122 of file aio_callback.c.

123{
125 Assert(ioh->handle_data_len == 0);
127
128 for (int i = 0; i < len; i++)
130 ioh->handle_data_len = len;
131}

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 63 of file aio_target.c.

64{
67
68 ioh->target = targetid;
69}

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

Referenced by pgaio_io_set_target_smgr().

◆ pgaio_io_start_readv()

void pgaio_io_start_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:405
static void pgaio_io_before_start(PgAioHandle *ioh)
Definition: aio_io.c:156
uint64 offset
Definition: aio.h:140
int fd
Definition: aio.h:138
uint16 iov_length
Definition: aio.h:139
struct PgAioOpData::@122 read

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

Referenced by FileStartReadV().

◆ pgaio_io_start_writev()

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

◆ pgaio_result_report()

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

Definition at line 171 of file aio_callback.c.

172{
173 PgAioHandleCallbackID cb_id = result.id;
174 const PgAioHandleCallbacksEntry *ce = &aio_handle_cbs[cb_id];
175
176 Assert(result.status != PGAIO_RS_UNKNOWN);
177 Assert(result.status != PGAIO_RS_OK);
178
179 if (ce->cb->report == NULL)
180 elog(ERROR, "callback %d/%s does not have report callback",
181 result.id, ce->name);
182
183 ce->cb->report(result, target_data, elevel);
184}
@ PGAIO_RS_OK
Definition: aio_types.h:81
PgAioHandleCallbackReport report
Definition: aio.h:258
uint32 id
Definition: aio_types.h:105

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

Referenced by buffer_readv_complete(), buffer_readv_complete_one(), md_readv_complete(), ProcessReadBuffersResult(), and read_rel_block_ll().

◆ pgaio_submit_staged()

void pgaio_submit_staged ( void  )

Definition at line 1020 of file aio.c.

1021{
1022 int total_submitted = 0;
1023 int did_submit;
1024
1026 return;
1027
1028
1030
1033
1035
1036 total_submitted += did_submit;
1037
1038 Assert(total_submitted == did_submit);
1039
1041
1043 "aio: submitted %d IOs",
1044 total_submitted);
1045}
#define pgaio_debug(elevel, msg,...)
Definition: aio_internal.h:376
#define DEBUG4
Definition: elog.h:27
#define START_CRIT_SECTION()
Definition: miscadmin.h:150
#define END_CRIT_SECTION()
Definition: miscadmin.h:152
int(* submit)(uint16 num_staged_ios, PgAioHandle **staged_ios)
Definition: aio_internal.h:302
PgAioHandle * staged_ios[PGAIO_SUBMIT_BATCH_SIZE]
Definition: aio_internal.h:209

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 AsyncReadBuffers(), pgaio_closing_fd(), pgaio_error_cleanup(), pgaio_exit_batchmode(), pgaio_io_acquire_nb(), pgaio_io_release_resowner(), pgaio_io_stage(), pgaio_io_wait_for_free(), and ReadBuffersCanStartIO().

◆ pgaio_wref_check_done()

bool pgaio_wref_check_done ( PgAioWaitRef iow)

Definition at line 907 of file aio.c.

908{
909 uint64 ref_generation;
911 bool am_owner;
912 PgAioHandle *ioh;
913
914 ioh = pgaio_io_from_wref(iow, &ref_generation);
915
916 if (pgaio_io_was_recycled(ioh, ref_generation, &state))
917 return true;
918
919 if (state == PGAIO_HS_IDLE)
920 return true;
921
922 am_owner = ioh->owner_procno == MyProcNumber;
923
926 {
927 if (am_owner)
928 pgaio_io_reclaim(ioh);
929 return true;
930 }
931
932 /*
933 * XXX: It likely would be worth checking in with the io method, to give
934 * the IO method a chance to check if there are completion events queued.
935 */
936
937 return false;
938}
static PgAioHandle * pgaio_io_from_wref(PgAioWaitRef *iow, uint64 *ref_generation)
Definition: aio.c:793
bool pgaio_io_was_recycled(PgAioHandle *ioh, uint64 ref_generation, PgAioHandleState *state)
Definition: aio.c:531
PgAioHandleState
Definition: aio_internal.h:44
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().

Referenced by WaitReadBuffers().

◆ pgaio_wref_clear()

void pgaio_wref_clear ( PgAioWaitRef iow)

◆ pgaio_wref_get_id()

int pgaio_wref_get_id ( PgAioWaitRef iow)

Definition at line 882 of file aio.c.

883{
885 return iow->aio_index;
886}
bool pgaio_wref_valid(PgAioWaitRef *iow)
Definition: aio.c:873

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

◆ pgaio_wref_valid()

bool pgaio_wref_valid ( PgAioWaitRef iow)

◆ pgaio_wref_wait()

void pgaio_wref_wait ( PgAioWaitRef iow)

Definition at line 893 of file aio.c.

894{
895 uint64 ref_generation;
896 PgAioHandle *ioh;
897
898 ioh = pgaio_io_from_wref(iow, &ref_generation);
899
900 pgaio_io_wait(ioh, ref_generation);
901}

References pgaio_io_from_wref(), and pgaio_io_wait().

Referenced by InvalidateLocalBuffer(), read_rel_block_ll(), StartLocalBufferIO(), WaitIO(), and WaitReadBuffers().

◆ StaticAssertDecl()

StaticAssertDecl ( PGAIO_HCB_MAX<=  1<< PGAIO_RESULT_ID_BITS,
"PGAIO_HCB_MAX is too big for PGAIO_RESULT_ID_BITS  
)

Variable Documentation

◆ io_max_concurrency

PGDLLIMPORT int io_max_concurrency
extern

◆ io_method

PGDLLIMPORT int io_method
extern