Commit 737e6144 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

Add support for io_uring min capacity

Summary: Add support for io_uring min capacity. This should allow us to create io_uring instances even memory is fragmented and the kernel cannot allocate contiguous physical memory for capacity CQ entries (SQ is usually much smaller).

Reviewed By: kevin-vigor

Differential Revision: D26252442

fbshipit-source-id: f4e3bd4f00d21321b77d4e1452400689dbca1073
parent 7e4c8713
...@@ -408,14 +408,32 @@ IoUringBackend::IoUringBackend(Options options) ...@@ -408,14 +408,32 @@ IoUringBackend::IoUringBackend(Options options)
} }
SQGroupInfoRegistry::FDCreateFunc func = [&](struct io_uring_params& params) { SQGroupInfoRegistry::FDCreateFunc func = [&](struct io_uring_params& params) {
// allocate entries both for poll add and cancel while (true) {
if (::io_uring_queue_init_params( // allocate entries both for poll add and cancel
2 * options_.maxSubmit, &ioRing_, &params)) { if (::io_uring_queue_init_params(
LOG(ERROR) << "io_uring_queue_init_params(" << 2 * options_.maxSubmit 2 * options_.maxSubmit, &ioRing_, &params)) {
<< "," << params.cq_entries << ") " options.capacity /= 2;
<< "failed errno = " << errno << ":\"" if (options.minCapacity && (options.capacity >= options.minCapacity)) {
<< folly::errnoStr(errno) << "\" " << this; LOG(INFO) << "io_uring_queue_init_params(" << 2 * options_.maxSubmit
throw NotAvailable("io_uring_queue_init error"); << "," << params.cq_entries << ") "
<< "failed errno = " << errno << ":\""
<< folly::errnoStr(errno) << "\" " << this
<< " retrying with capacity = " << options.capacity;
params_.cq_entries = options.capacity;
numEntries_ = options.capacity;
} else {
LOG(ERROR) << "io_uring_queue_init_params(" << 2 * options_.maxSubmit
<< "," << params.cq_entries << ") "
<< "failed errno = " << errno << ":\""
<< folly::errnoStr(errno) << "\" " << this;
throw NotAvailable("io_uring_queue_init error");
}
} else {
// success - break
break;
}
} }
return ioRing_.ring_fd; return ioRing_.ring_fd;
......
...@@ -62,6 +62,12 @@ class IoUringBackend : public EventBaseBackendBase { ...@@ -62,6 +62,12 @@ class IoUringBackend : public EventBaseBackendBase {
return *this; return *this;
} }
Options& setMinCapacity(size_t v) {
minCapacity = v;
return *this;
}
Options& setMaxSubmit(size_t v) { Options& setMaxSubmit(size_t v) {
maxSubmit = v; maxSubmit = v;
...@@ -117,6 +123,7 @@ class IoUringBackend : public EventBaseBackendBase { ...@@ -117,6 +123,7 @@ class IoUringBackend : public EventBaseBackendBase {
} }
size_t capacity{0}; size_t capacity{0};
size_t minCapacity{0};
size_t maxSubmit{128}; size_t maxSubmit{128};
size_t maxGet{std::numeric_limits<size_t>::max()}; size_t maxGet{std::numeric_limits<size_t>::max()};
bool useRegisteredFds{false}; bool useRegisteredFds{false};
......
...@@ -477,6 +477,32 @@ void testAsyncUDPRecvmsg(bool useRegisteredFds) { ...@@ -477,6 +477,32 @@ void testAsyncUDPRecvmsg(bool useRegisteredFds) {
} }
} // namespace } // namespace
TEST(IoUringBackend, FailCreateNoRetry) {
bool bSuccess = true;
try {
folly::IoUringBackend::Options options;
options.setCapacity(256 * 1024);
options.setMinCapacity(0);
folly::IoUringBackend backend(options);
} catch (const folly::IoUringBackend::NotAvailable&) {
bSuccess = false;
}
CHECK(!bSuccess);
}
TEST(IoUringBackend, SuccessCreateRetry) {
bool bSuccess = true;
try {
folly::IoUringBackend::Options options;
options.setCapacity(256 * 1024);
options.setMinCapacity(1024);
folly::IoUringBackend backend(options);
} catch (const folly::IoUringBackend::NotAvailable&) {
bSuccess = false;
}
CHECK(bSuccess);
}
TEST(IoUringBackend, AsyncUDPRecvmsgNoRegisterFd) { TEST(IoUringBackend, AsyncUDPRecvmsgNoRegisterFd) {
testAsyncUDPRecvmsg(false); testAsyncUDPRecvmsg(false);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment