PostgreSQL Source Code: src/include/storage/aio.h File Reference (original) (raw)

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")
PgAioHandle * pgaio_io_acquire (struct ResourceOwnerData *resowner, PgAioReturn *ret)
PgAioHandle * pgaio_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)
PgAioOpData * pgaio_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)
PgAioTargetData * pgaio_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)
uint64 * pgaio_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)

DEFAULT_IO_METHOD

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

PGAIO_OP_COUNT

PGAIO_TID_COUNT

IoMethod

PgAioHandleCallbackComplete

PgAioHandleCallbackID

PgAioHandleCallbackReport

PgAioHandleCallbackStage

PgAioHandleFlags

PgAioOp

PgAioTargetID

IoMethod

Enumerator
IOMETHOD_SYNC
IOMETHOD_WORKER

Definition at line 32 of file aio.h.

33{

36#ifdef IOMETHOD_IO_URING_ENABLED

37 IOMETHOD_IO_URING,

38#endif

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

@ PGAIO_HCB_LOCAL_BUFFER_READV

@ PGAIO_HCB_SHARED_BUFFER_READV

PgAioHandleFlags

Enumerator
PGAIO_HF_REFERENCES_LOCAL
PGAIO_HF_SYNCHRONOUS
PGAIO_HF_BUFFERED

Definition at line 48 of file aio.h.

49{

50

51

52

53

54

55

56

57

58

59

61

62

63

64

65

66

67

68

69

71

72

73

74

75

76

@ PGAIO_HF_REFERENCES_LOCAL

PgAioOp

Enumerator
PGAIO_OP_INVALID
PGAIO_OP_READV
PGAIO_OP_WRITEV

Definition at line 87 of file aio.h.

PgAioTargetID

Enumerator
PGAIO_TID_INVALID
PGAIO_TID_SMGR

Definition at line 116 of file aio.h.

pgaio_closing_fd()

void pgaio_closing_fd ( int fd )

Definition at line 1200 of file aio.c.

1201{

1202

1203

1204

1205

1207 return;

1208

1209

1210

1211

1212

1214 {

1216 "submitting %d IOs before FD %d gets closed",

1219 }

1220

1221

1222

1223

1224

1226 {

1227

1228

1229

1230

1231

1232

1234 {

1238

1240 {

1242

1244

1246 break;

1247 else

1248 ioh = NULL;

1249 }

1250

1251 if (!ioh)

1252 break;

1253

1255 "waiting for IO before FD %d gets closed, %d in-flight IOs",

1257

1258

1260 }

1261 }

1262}

PgAioBackend * pgaio_my_backend

const IoMethodOps * pgaio_method_ops

void pgaio_submit_staged(void)

static void pgaio_io_wait(PgAioHandle *ioh, uint64 ref_generation)

#define pgaio_debug(elevel, msg,...)

#define pgaio_debug_io(elevel, ioh, msg,...)

bool pgaio_io_uses_fd(PgAioHandle *ioh, int fd)

#define dclist_container(type, membername, ptr)

static uint32 dclist_count(const dclist_head *head)

static bool dclist_is_empty(const dclist_head *head)

#define dclist_foreach(iter, lhead)

static int fd(const char *x, int i)

bool wait_on_fd_before_close

dclist_head in_flight_ios

References dlist_iter::cur, dclist_container, dclist_count(), dclist_foreach, dclist_is_empty(), DEBUG2, fd(), PgAioHandle::generation, 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 )

pgaio_exit_batchmode()

void pgaio_exit_batchmode ( void )

pgaio_have_staged()

bool pgaio_have_staged ( void )

pgaio_io_acquire()

pgaio_io_acquire_nb()

Definition at line 185 of file aio.c.

186{

188

190 {

193 }

194

196 elog(ERROR, "API violation: Only one IO can be handed out");

197

198

199

200

201

203

205 {

207

209

212

215

216 if (resowner)

218

219 if (ret)

220 {

223 }

224 }

225

227

228 return ioh;

229}

static void pgaio_io_update_state(PgAioHandle *ioh, PgAioHandleState new_state)

static void pgaio_io_resowner_register(PgAioHandle *ioh)

#define PGAIO_SUBMIT_BATCH_SIZE

static dlist_node * dclist_pop_head_node(dclist_head *head)

#define RESUME_INTERRUPTS()

#define HOLD_INTERRUPTS()

PgAioHandle * handed_out_io

PgAioReturn * report_return

References Assert(), dclist_container, dclist_is_empty(), dclist_pop_head_node(), elog, ERROR, PgAioBackend::handed_out_io, HOLD_INTERRUPTS, 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, RESUME_INTERRUPTS, PgAioHandle::state, and PgAioResult::status.

Referenced by AsyncReadBuffers(), and pgaio_io_acquire().

pgaio_io_get_handle_data()

pgaio_io_get_id()

pgaio_io_get_iovec()

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

pgaio_io_get_op()

pgaio_io_get_op_data()

pgaio_io_get_owner()

pgaio_io_get_target_data()

pgaio_io_get_target_description()

char * pgaio_io_get_target_description ( PgAioHandle * ioh )

pgaio_io_get_wref()

Definition at line 363 of file aio.c.

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.

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

pgaio_io_has_target()

pgaio_io_register_callbacks()

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

98 elog(PANIC, "too many callbacks, the max is %d",

102

104 "adding cb #%d, id %d/%s",

106 cb_id, ce->name);

107

109}

#define PGAIO_HANDLE_MAX_CALLBACKS

static const PgAioHandleCallbacksEntry aio_handle_cbs[]

const PgAioHandleCallbacks *const cb

PgAioHandleCallbackComplete complete_local

uint8 callbacks[PGAIO_HANDLE_MAX_CALLBACKS]

uint8 callbacks_data[PGAIO_HANDLE_MAX_CALLBACKS]

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

Definition at line 237 of file aio.c.

238{

240 {

243

245

246

247

248

249

250

252 }

253 else

254 {

255 elog(ERROR, "release in unexpected state");

256 }

257}

static void pgaio_io_reclaim(PgAioHandle *ioh)

struct ResourceOwnerData * resowner

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

264{

266

268

269

270

271

272

274

277

278 switch (ioh->state)

279 {

282 break;

285

287 {

289 if (!on_error)

291 }

292

294 break;

297 if (!on_error)

298 elog(WARNING, "AIO handle was not submitted");

300 break;

305

306 break;

307 }

308

309

310

311

312

315

317}

@ PGAIO_HS_COMPLETED_SHARED

@ PGAIO_HS_COMPLETED_LOCAL

#define dlist_container(type, membername, ptr)

void ResourceOwnerForgetAioHandle(ResourceOwner owner, struct dlist_node *ioh_node)

References Assert(), dlist_container, elog, ERROR, 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(), PgAioHandle::report_return, ResourceOwnerForgetAioHandle(), PgAioHandle::resowner, PgAioHandle::resowner_node, RESUME_INTERRUPTS, PgAioHandle::state, and WARNING.

Referenced by ResourceOwnerReleaseInternal().

pgaio_io_set_flag()

pgaio_io_set_handle_data_32()

Definition at line 140 of file aio_callback.c.

141{

146

147 for (int i = 0; i < len; i++)

150}

References Assert(), data, PgAioCtl::handle_data, PgAioHandle::handle_data_len, i, io_max_combine_limit, 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()

Definition at line 122 of file aio_callback.c.

123{

128

129 for (int i = 0; i < len; i++)

132}

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

pgaio_io_set_target()

pgaio_io_start_readv()

pgaio_io_start_writev()

pgaio_result_report()

Definition at line 173 of file aio_callback.c.

174{

177

180

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}

PgAioHandleCallbackReport report

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

1104{

1105 int total_submitted = 0;

1106 int did_submit;

1107

1109 return;

1110

1111

1113

1116

1118

1119 total_submitted += did_submit;

1120

1121 Assert(total_submitted == did_submit);

1122

1124

1126 "aio: submitted %d IOs",

1127 total_submitted);

1128}

#define START_CRIT_SECTION()

#define END_CRIT_SECTION()

int(* submit)(uint16 num_staged_ios, PgAioHandle **staged_ios)

PgAioHandle * staged_ios[PGAIO_SUBMIT_BATCH_SIZE]

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

Definition at line 985 of file aio.c.

986{

987 uint64 ref_generation;

989 bool am_owner;

991

993

995 return true;

996

998 return true;

999

1001

1004 {

1005

1006

1007

1008

1009

1010 if (am_owner)

1012 return true;

1013 }

1014

1015

1016

1017

1018

1019

1020 return false;

1021}

static PgAioHandle * pgaio_io_from_wref(PgAioWaitRef *iow, uint64 *ref_generation)

bool pgaio_io_was_recycled(PgAioHandle *ioh, uint64 ref_generation, PgAioHandleState *state)

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

pgaio_wref_get_id()

pgaio_wref_valid()

pgaio_wref_wait()

StaticAssertDecl()

io_max_concurrency

io_method