Commit 5b164159 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook GitHub Bot

Avoid calling ::io_uring_register_files_update again in case of failure

Summary: Avoid calling ::io_uring_register_files_update again in case of failure

Reviewed By: danobi

Differential Revision: D20847977

fbshipit-source-id: 9dedecb4e815b3bb0bd41b0ba908a0c2496a67d5
parent 56ce4f44
......@@ -50,21 +50,30 @@ int IoUringBackend::FdRegistry::init() {
IoUringBackend::FdRegistrationRecord* IoUringBackend::FdRegistry::alloc(
int fd) {
if (FOLLY_UNLIKELY(free_.empty())) {
if (FOLLY_UNLIKELY(err_ || free_.empty())) {
return nullptr;
}
auto& ret = free_.front();
auto& record = free_.front();
// now we have an idx
if (::io_uring_register_files_update(&ioRing_, ret.idx_, &fd, 1) != 1) {
int ret = ::io_uring_register_files_update(&ioRing_, record.idx_, &fd, 1);
if (ret != 1) {
// set the err_ flag so we do not retry again
// this usually happens when we hit the file desc limit
// and retrying this operation for every request is expensive
err_ = true;
LOG(ERROR) << "io_uring_register_files(1) "
<< "failed errno = " << errno << ":\"" << folly::errnoStr(errno)
<< "\" " << this;
return nullptr;
}
ret.fd_ = fd;
ret.count_ = 1;
record.fd_ = fd;
record.count_ = 1;
free_.pop_front();
return &ret;
return &record;
}
bool IoUringBackend::FdRegistry::free(
......
......@@ -63,6 +63,7 @@ class IoUringBackend : public PollIoBackend {
int init();
size_t update();
bool err_{false};
struct io_uring& ioRing_;
std::vector<int> files_;
size_t inUse_;
......
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