Skip to content

Commit

Permalink
Default value of libaio wrapper
Browse files Browse the repository at this point in the history
Signed-off-by: Coldwings <coldwings@me.com>
  • Loading branch information
Coldwings committed Jan 16, 2024
1 parent 406fc9b commit 2f55e06
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
18 changes: 11 additions & 7 deletions io/aio-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; i<n; ++i)
{
auto piocb = (libaiocb*)events[i].obj;
Expand All @@ -166,7 +166,7 @@ namespace photon
VALUE(piocb->u.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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion io/aio-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion photon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions photon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -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.
Expand Down

0 comments on commit 2f55e06

Please sign in to comment.