PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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)
 
charpgaio_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

◆ PgAioHandleCallbackComplete

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

◆ PgAioTargetID

Enumeration Type Documentation

◆ 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
38#endif
39} IoMethod;
IoMethod
Definition aio.h:33
@ IOMETHOD_WORKER
Definition aio.h:35
@ IOMETHOD_SYNC
Definition aio.h:34
static int fb(int x)

◆ 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

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)
extern

Definition at line 1220 of file aio.c.

1221{
1222 /*
1223 * Might be called before AIO is initialized or in a subprocess that
1224 * doesn't use AIO.
1225 */
1226 if (!pgaio_my_backend)
1227 return;
1228
1229 /*
1230 * For now just submit all staged IOs - we could be more selective, but
1231 * it's probably not worth it.
1232 */
1234 {
1236 "submitting %d IOs before FD %d gets closed",
1239 }
1240
1241 /*
1242 * If requested by the IO method, wait for all IOs that use the
1243 * to-be-closed FD.
1244 */
1246 {
1247 /*
1248 * As waiting for one IO to complete may complete multiple IOs, we
1249 * can't just use a mutable list iterator. The maximum number of
1250 * in-flight IOs is fairly small, so just restart the loop after
1251 * waiting for an IO.
1252 */
1254 {
1255 dlist_iter iter;
1256 PgAioHandle *ioh = NULL;
1257 uint64 generation;
1258
1260 {
1261 ioh = dclist_container(PgAioHandle, node, iter.cur);
1262
1263 generation = ioh->generation;
1264
1265 if (pgaio_io_uses_fd(ioh, fd))
1266 break;
1267 else
1268 ioh = NULL;
1269 }
1270
1271 if (!ioh)
1272 break;
1273
1275 "waiting for IO before FD %d gets closed, %u in-flight IOs",
1277
1278 /* see comment in pgaio_io_wait_for_free() about raciness */
1279 pgaio_io_wait(ioh, generation);
1280 }
1281 }
1282}
PgAioBackend * pgaio_my_backend
Definition aio.c:81
const IoMethodOps * pgaio_method_ops
Definition aio.c:96
void pgaio_submit_staged(void)
Definition aio.c:1123
static void pgaio_io_wait(PgAioHandle *ioh, uint64 ref_generation)
Definition aio.c:579
#define pgaio_debug(elevel, msg,...)
#define pgaio_debug_io(elevel, ioh, msg,...)
bool pgaio_io_uses_fd(PgAioHandle *ioh, int fd)
Definition aio_io.c:197
uint64_t uint64
Definition c.h:547
#define DEBUG2
Definition elog.h:29
#define dclist_container(type, membername, ptr)
Definition ilist.h:947
static uint32 dclist_count(const dclist_head *head)
Definition ilist.h:932
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)
bool wait_on_fd_before_close
dclist_head in_flight_ios
uint16 num_staged_ios
dlist_node * cur
Definition ilist.h:179

References dlist_iter::cur, dclist_container, dclist_count(), dclist_foreach, dclist_is_empty(), DEBUG2, fb(), fd(), PgAioBackend::in_flight_ios, PgAioBackend::num_staged_ios, pgaio_debug, pgaio_debug_io, 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  )
extern

Definition at line 1081 of file aio.c.

1082{
1084 elog(ERROR, "starting batch while batch already in progress");
1086}
#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  )
extern

Definition at line 1092 of file aio.c.

1093{
1095
1098}
#define Assert(condition)
Definition c.h:873

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  )
extern

◆ pgaio_io_acquire()

PgAioHandle * pgaio_io_acquire ( struct ResourceOwnerData resowner,
PgAioReturn ret 
)
extern

Definition at line 162 of file aio.c.

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

References fb(), 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 
)
extern

Definition at line 188 of file aio.c.

189{
191
193 {
196 }
197
199 elog(ERROR, "API violation: Only one IO can be handed out");
200
201 /*
202 * Probably not needed today, as interrupts should not process this IO,
203 * but...
204 */
206
208 {
210
212
213 Assert(ioh->state == PGAIO_HS_IDLE);
214 Assert(ioh->owner_procno == MyProcNumber);
215
218
219 if (resowner)
221
222 if (ret)
223 {
224 ioh->report_return = ret;
226 }
227 }
228
230
231 return ioh;
232}
static void pgaio_io_update_state(PgAioHandle *ioh, PgAioHandleState new_state)
Definition aio.c:386
static void pgaio_io_resowner_register(PgAioHandle *ioh, struct ResourceOwnerData *resowner)
Definition aio.c:409
@ PGAIO_HS_IDLE
@ PGAIO_HS_HANDED_OUT
#define PGAIO_SUBMIT_BATCH_SIZE
@ PGAIO_RS_UNKNOWN
Definition aio_types.h:80
ProcNumber MyProcNumber
Definition globals.c:90
static dlist_node * dclist_pop_head_node(dclist_head *head)
Definition ilist.h:789
#define RESUME_INTERRUPTS()
Definition miscadmin.h:136
#define HOLD_INTERRUPTS()
Definition miscadmin.h:134
dclist_head idle_ios
PgAioHandle * handed_out_io
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, fb(), PgAioBackend::handed_out_io, HOLD_INTERRUPTS, PgAioBackend::idle_ios, MyProcNumber, PgAioBackend::num_staged_ios, 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(), PgAioReturn::result, RESUME_INTERRUPTS, 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 
)
extern

Definition at line 156 of file aio_callback.c.

157{
158 Assert(ioh->handle_data_len > 0);
159
160 *len = ioh->handle_data_len;
161
162 return &pgaio_ctl->handle_data[ioh->iovec_off];
163}
PgAioCtl * pgaio_ctl
Definition aio.c:78
const void size_t len
uint64 * handle_data

References Assert, fb(), PgAioCtl::handle_data, len, and pgaio_ctl.

Referenced by buffer_readv_complete(), and buffer_stage_common().

◆ pgaio_io_get_id()

int pgaio_io_get_id ( PgAioHandle ioh)
extern

◆ pgaio_io_get_iovec()

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

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:47
struct iovec * iovecs

References Assert, fb(), PgAioCtl::iovecs, PG_IOV_MAX, pgaio_ctl, and PGAIO_HS_HANDED_OUT.

Referenced by mdstartreadv().

◆ pgaio_io_get_op()

PgAioOp pgaio_io_get_op ( PgAioHandle ioh)
extern

Definition at line 52 of file aio_io.c.

53{
54 return ioh->op;
55}

References fb().

Referenced by smgr_aio_reopen().

◆ pgaio_io_get_op_data()

PgAioOpData * pgaio_io_get_op_data ( PgAioHandle ioh)
extern

Definition at line 58 of file aio_io.c.

59{
60 return &ioh->op_data;
61}

References fb().

Referenced by smgr_aio_reopen().

◆ pgaio_io_get_owner()

ProcNumber pgaio_io_get_owner ( PgAioHandle ioh)
extern

Definition at line 355 of file aio.c.

356{
357 return ioh->owner_procno;
358}

References fb(), and 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)
extern

Definition at line 73 of file aio_target.c.

74{
75 return &ioh->target_data;
76}

References fb().

Referenced by buffer_readv_complete(), md_readv_complete(), pgaio_io_set_target_smgr(), shared_buffer_readv_complete_local(), and smgr_aio_reopen().

◆ pgaio_io_get_target_description()

char * pgaio_io_get_target_description ( PgAioHandle ioh)
extern

Definition at line 84 of file aio_target.c.

85{
86 /* disallow INVALID, there wouldn't be a description */
87 Assert(ioh->target > PGAIO_TID_INVALID && ioh->target < PGAIO_TID_COUNT);
88
89 return pgaio_target_info[ioh->target]->describe_identity(&ioh->target_data);
90}
#define PGAIO_TID_COUNT
Definition aio.h:123
static const PgAioTargetInfo * pgaio_target_info[]
Definition aio_target.c:25
char *(* describe_identity)(const PgAioTargetData *sd)
Definition aio.h:167

References Assert, PgAioTargetInfo::describe_identity, fb(), pgaio_target_info, PGAIO_TID_COUNT, and PGAIO_TID_INVALID.

Referenced by pg_get_aios().

◆ pgaio_io_get_wref()

void pgaio_io_get_wref ( PgAioHandle ioh,
PgAioWaitRef iow 
)
extern

Definition at line 366 of file aio.c.

367{
368 Assert(ioh->state == PGAIO_HS_HANDED_OUT ||
369 ioh->state == PGAIO_HS_DEFINED ||
370 ioh->state == PGAIO_HS_STAGED);
371 Assert(ioh->generation != 0);
372
373 iow->aio_index = ioh - pgaio_ctl->io_handles;
374 iow->generation_upper = (uint32) (ioh->generation >> 32);
375 iow->generation_lower = (uint32) ioh->generation;
376}
@ PGAIO_HS_STAGED
@ PGAIO_HS_DEFINED
uint32_t uint32
Definition c.h:546
uint64 generation

References Assert, fb(), PgAioHandle::generation, PgAioCtl::io_handles, pgaio_ctl, PGAIO_HS_DEFINED, PGAIO_HS_HANDED_OUT, and PGAIO_HS_STAGED.

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

◆ pgaio_io_has_target()

bool pgaio_io_has_target ( PgAioHandle ioh)
extern

Definition at line 40 of file aio_target.c.

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

References fb(), and PGAIO_TID_INVALID.

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 
)
extern

Definition at line 86 of file aio_callback.c.

88{
90
93 elog(ERROR, "callback %d is out of range", cb_id);
94 if (aio_handle_cbs[cb_id].cb->complete_shared == NULL &&
96 elog(ERROR, "callback %d does not have a completion callback", cb_id);
97 if (ioh->num_callbacks >= PGAIO_HANDLE_MAX_CALLBACKS)
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[]
#define lengthof(array)
Definition c.h:803
#define DEBUG3
Definition elog.h:28
#define PANIC
Definition elog.h:42
const PgAioHandleCallbacks *const cb
PgAioHandleCallbackComplete complete_local
Definition aio.h:251

References aio_handle_cbs, Assert, PgAioHandleCallbacksEntry::cb, PgAioHandleCallbacks::complete_local, DEBUG3, elog, ERROR, fb(), lengthof, 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)
extern

Definition at line 240 of file aio.c.

241{
243 {
244 Assert(ioh->state == PGAIO_HS_HANDED_OUT);
245 Assert(ioh->resowner);
246
248
249 /*
250 * Note that no interrupts are processed between the handed_out_io
251 * check and the call to reclaim - that's important as otherwise an
252 * interrupt could have already reclaimed the handle.
253 */
255 }
256 else
257 {
258 elog(ERROR, "release in unexpected state");
259 }
260}
static void pgaio_io_reclaim(PgAioHandle *ioh)
Definition aio.c:675

References Assert, elog, ERROR, fb(), PgAioBackend::handed_out_io, PGAIO_HS_HANDED_OUT, pgaio_io_reclaim(), and pgaio_my_backend.

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 
)
extern

Definition at line 266 of file aio.c.

267{
269
270 Assert(ioh->resowner);
271
272 /*
273 * Otherwise an interrupt, in the middle of releasing the IO, could end up
274 * trying to wait for the IO, leading to state confusion.
275 */
277
278 ResourceOwnerForgetAioHandle(ioh->resowner, &ioh->resowner_node);
279 ioh->resowner = NULL;
280
281 switch ((PgAioHandleState) ioh->state)
282 {
283 case PGAIO_HS_IDLE:
284 elog(ERROR, "unexpected");
285 break;
288
290 {
292 if (!on_error)
293 elog(WARNING, "leaked AIO handle");
294 }
295
297 break;
298 case PGAIO_HS_DEFINED:
299 case PGAIO_HS_STAGED:
300 if (!on_error)
301 elog(WARNING, "AIO handle was not submitted");
303 break;
308 /* this is expected to happen */
309 break;
310 }
311
312 /*
313 * Need to unregister the reporting of the IO's result, the memory it's
314 * referencing likely has gone away.
315 */
316 if (ioh->report_return)
317 ioh->report_return = NULL;
318
320}
PgAioHandleState
@ PGAIO_HS_COMPLETED_SHARED
@ PGAIO_HS_SUBMITTED
@ PGAIO_HS_COMPLETED_IO
@ PGAIO_HS_COMPLETED_LOCAL
#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:1107

References Assert, dlist_container, elog, ERROR, fb(), PgAioBackend::handed_out_io, HOLD_INTERRUPTS, 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(), ResourceOwnerForgetAioHandle(), RESUME_INTERRUPTS, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

◆ pgaio_io_set_flag()

void pgaio_io_set_flag ( PgAioHandle ioh,
PgAioHandleFlags  flag 
)
extern

Definition at line 330 of file aio.c.

331{
332 Assert(ioh->state == PGAIO_HS_HANDED_OUT);
333
334 ioh->flags |= flag;
335}
char * flag(int b)
Definition test-ctype.c:33

References Assert, fb(), flag(), and PGAIO_HS_HANDED_OUT.

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 
)
extern

Definition at line 140 of file aio_callback.c.

141{
142 Assert(ioh->state == PGAIO_HS_HANDED_OUT);
143 Assert(ioh->handle_data_len == 0);
146
147 for (int i = 0; i < len; i++)
148 pgaio_ctl->handle_data[ioh->iovec_off + i] = data[i];
149 ioh->handle_data_len = len;
150}
int io_max_combine_limit
Definition bufmgr.c:201
int i
Definition isn.c:77
const void * data

References Assert, data, fb(), PgAioCtl::handle_data, i, io_max_combine_limit, len, PG_IOV_MAX, pgaio_ctl, and PGAIO_HS_HANDED_OUT.

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 
)
extern

Definition at line 122 of file aio_callback.c.

123{
124 Assert(ioh->state == PGAIO_HS_HANDED_OUT);
125 Assert(ioh->handle_data_len == 0);
128
129 for (int i = 0; i < len; i++)
130 pgaio_ctl->handle_data[ioh->iovec_off + i] = data[i];
131 ioh->handle_data_len = len;
132}

References Assert, data, fb(), PgAioCtl::handle_data, i, io_max_combine_limit, len, PG_IOV_MAX, pgaio_ctl, and PGAIO_HS_HANDED_OUT.

◆ pgaio_io_set_target()

void pgaio_io_set_target ( PgAioHandle ioh,
PgAioTargetID  targetid 
)
extern

Definition at line 64 of file aio_target.c.

65{
67 Assert(ioh->target == PGAIO_TID_INVALID);
68
69 ioh->target = targetid;
70}

References Assert, fb(), PGAIO_HS_HANDED_OUT, and PGAIO_TID_INVALID.

Referenced by pgaio_io_set_target_smgr().

◆ pgaio_io_start_readv()

void pgaio_io_start_readv ( PgAioHandle ioh,
int  fd,
int  iovcnt,
uint64  offset 
)
extern

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:424
static void pgaio_io_before_start(PgAioHandle *ioh)
Definition aio_io.c:156

References fb(), fd(), pgaio_io_before_start(), pgaio_io_stage(), and PGAIO_OP_READV.

Referenced by FileStartReadV().

◆ pgaio_io_start_writev()

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

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}

References fb(), fd(), pgaio_io_before_start(), pgaio_io_stage(), and PGAIO_OP_WRITEV.

◆ pgaio_result_report()

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

Definition at line 173 of file aio_callback.c.

174{
177
178 Assert(result.status != PGAIO_RS_UNKNOWN);
179 Assert(result.status != PGAIO_RS_OK);
180
181 if (ce->cb->report == NULL)
182 elog(ERROR, "callback %d/%s does not have report callback",
183 result.id, ce->name);
184
185 ce->cb->report(result, target_data, elevel);
186}
@ PGAIO_RS_OK
Definition aio_types.h:81
uint32 id
Definition aio_types.h:105

References aio_handle_cbs, Assert, elog, ERROR, fb(), PgAioResult::id, PGAIO_RS_OK, PGAIO_RS_UNKNOWN, 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  )
extern

Definition at line 1123 of file aio.c.

1124{
1125 int total_submitted = 0;
1126 int did_submit;
1127
1129 return;
1130
1131
1133
1136
1138
1140
1142
1144
1146 "aio: submitted %d IOs",
1148}
#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)
PgAioHandle * staged_ios[PGAIO_SUBMIT_BATCH_SIZE]

References Assert, DEBUG4, END_CRIT_SECTION, fb(), 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)
extern

Definition at line 1005 of file aio.c.

1006{
1009 bool am_owner;
1011
1013
1015 return true;
1016
1017 if (state == PGAIO_HS_IDLE)
1018 return true;
1019
1020 am_owner = ioh->owner_procno == MyProcNumber;
1021
1024 {
1025 /*
1026 * Note that no interrupts are processed between
1027 * pgaio_io_was_recycled() and this check - that's important as
1028 * otherwise an interrupt could have already reclaimed the handle.
1029 */
1030 if (am_owner)
1032 return true;
1033 }
1034
1035 /*
1036 * XXX: It likely would be worth checking in with the io method, to give
1037 * the IO method a chance to check if there are completion events queued.
1038 */
1039
1040 return false;
1041}
static PgAioHandle * pgaio_io_from_wref(PgAioWaitRef *iow, uint64 *ref_generation)
Definition aio.c:891
bool pgaio_io_was_recycled(PgAioHandle *ioh, uint64 ref_generation, PgAioHandleState *state)
Definition aio.c:559

References fb(), MyProcNumber, 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)
extern

Definition at line 964 of file aio.c.

965{
966 iow->aio_index = PG_UINT32_MAX;
967}
#define PG_UINT32_MAX
Definition c.h:604

References fb(), and PG_UINT32_MAX.

Referenced by AsyncReadBuffers(), BufferManagerShmemInit(), InitLocalBuffers(), StartReadBuffersImpl(), TerminateBufferIO(), and TerminateLocalBufferIO().

◆ pgaio_wref_get_id()

int pgaio_wref_get_id ( PgAioWaitRef iow)
extern

Definition at line 980 of file aio.c.

981{
983 return iow->aio_index;
984}
bool pgaio_wref_valid(PgAioWaitRef *iow)
Definition aio.c:971

References Assert, fb(), and pgaio_wref_valid().

◆ pgaio_wref_valid()

bool pgaio_wref_valid ( PgAioWaitRef iow)
extern

Definition at line 971 of file aio.c.

972{
973 return iow->aio_index != PG_UINT32_MAX;
974}

References fb(), and PG_UINT32_MAX.

Referenced by InvalidateLocalBuffer(), pgaio_wref_get_id(), ProcessReadBuffersResult(), StartLocalBufferIO(), WaitIO(), and WaitReadBuffers().

◆ pgaio_wref_wait()

void pgaio_wref_wait ( PgAioWaitRef iow)
extern

◆ StaticAssertDecl()

StaticAssertDecl ( )

Variable Documentation

◆ io_max_concurrency

◆ io_method

PGDLLIMPORT int io_method
extern