diff --git a/io/aio-wrapper.cpp b/io/aio-wrapper.cpp index 6a33c6ec..29654095 100644 --- a/io/aio-wrapper.cpp +++ b/io/aio-wrapper.cpp @@ -38,10 +38,10 @@ limitations under the License. namespace photon { - const uint64_t IODEPTH = 2048; + constexpr static int IODEPTH_MAX = 2048; struct libaio_ctx_t { - int evfd = -1, running = 0; + int evfd = -1, running = 0, iodepth = 32; io_context_t aio_ctx = {0}; thread* polling_thread = nullptr; condition_variable cond; @@ -152,8 +152,8 @@ namespace photon static void resume_libaio_requesters() { retry: - struct io_event events[IODEPTH]; - int n = HAVE_N_TRY(my_io_getevents, (0, IODEPTH, events)); + struct io_event events[IODEPTH_MAX]; + int n = HAVE_N_TRY(my_io_getevents, (0, IODEPTH_MAX, events)); for (int i=0; iu.c.buf), VALUE(piocb->u.c.resfd)); thread_interrupt((thread *)events[i].data, EOK); } - if (n == IODEPTH) + if (n == IODEPTH_MAX) { thread_yield(); goto retry; @@ -347,6 +347,7 @@ namespace photon if (!libaio_ctx) return 0; LOG_INFO("reset libaio by reset handle"); + auto iodepth = libaio_ctx->iodepth; close(libaio_ctx->evfd); libaio_ctx->evfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (libaio_ctx->evfd < 0) { @@ -355,7 +356,8 @@ namespace photon } io_destroy(libaio_ctx->aio_ctx); libaio_ctx->aio_ctx = {0}; - int ret = io_setup(IODEPTH, &libaio_ctx->aio_ctx); + int ret = io_setup(iodepth < IODEPTH_MAX ? iodepth : IODEPTH_MAX, + &libaio_ctx->aio_ctx); if (ret < 0) { LOG_ERROR("failed to create aio context by io_setup() ", ERRNO(), VALUE(ret)); exit(-1); @@ -376,7 +378,8 @@ namespace photon if (ctx->evfd < 0) LOG_ERRNO_RETURN(0, -1, "failed to create eventfd"); - int ret = io_setup(iodepth < IODEPTH ? iodepth : IODEPTH, &ctx->aio_ctx); + int ret = io_setup(iodepth < IODEPTH_MAX ? iodepth : IODEPTH_MAX, + &ctx->aio_ctx); if (ret < 0) { LOG_ERROR("failed to create aio context by io_setup() ", ERRNO(), VALUE(ret)); @@ -388,6 +391,7 @@ namespace photon assert(ctx->polling_thread); libaio_ctx = ctx.release(); libaio_ctx->running = 1; + libaio_ctx->iodepth = iodepth; if (reset_handler == nullptr) { reset_handler = new AioResetHandle(); } diff --git a/io/aio-wrapper.h b/io/aio-wrapper.h index 1f0e660f..3e18d3ae 100644 --- a/io/aio-wrapper.h +++ b/io/aio-wrapper.h @@ -24,7 +24,7 @@ namespace photon { extern "C" { - int libaio_wrapper_init(int iodepth = 2048); + int libaio_wrapper_init(int iodepth = 32); int libaio_wrapper_fini(); // `fd` must be opened with O_DIRECT, and the buffers must be aligned diff --git a/photon.cpp b/photon.cpp index 331538c8..5d7dd566 100644 --- a/photon.cpp +++ b/photon.cpp @@ -53,7 +53,7 @@ int init(uint64_t event_engine, uint64_t io_engine, const PhotonOptions& options use_pooled_stack_allocator(); } if (options.bypass_threadpool) { - set_bypass_threadpool(options.bypass_threadpool); + set_bypass_threadpool(true); } if (vcpu_init() < 0) diff --git a/photon.h b/photon.h index 440841cb..963afa2e 100644 --- a/photon.h +++ b/photon.h @@ -49,7 +49,7 @@ const uint64_t INIT_IO_DEFAULT = INIT_IO_LIBCURL; #undef SHIFT struct PhotonOptions { - int libaio_ctx = 2048; + int libaio_ctx = 32; bool use_pooled_stack_allocator = false; bool bypass_threadpool = false; }; @@ -61,7 +61,7 @@ struct PhotonOptions { */ int init(uint64_t event_engine = INIT_EVENT_DEFAULT, uint64_t io_engine = INIT_IO_DEFAULT, - const PhotonOptions& options = PhotonOptions()); + const PhotonOptions& options = {}); /** * @brief Destroy/join ancillary threads, and finish the main thread.