Commit 0923f2bd authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Fix mem leak when running in overflow mode

Summary: Fix mem leak when running in overflow mode

Reviewed By: danobi

Differential Revision: D19333236

fbshipit-source-id: f8a93113d095cb227808c9c8e5704112c7f5c4fb
parent 26f1c45b
......@@ -78,6 +78,25 @@ IoUringBackend::~IoUringBackend() {
void IoUringBackend::cleanup() {
if (ioRing_.ring_fd > 0) {
// release the active events
while (!activeEvents_.empty()) {
auto* ioCb = &activeEvents_.front();
activeEvents_.pop_front();
releaseIoCb(ioCb);
}
// wait for the outstanding events to finish
while (numIoCbInUse()) {
struct io_uring_cqe* cqe = nullptr;
::io_uring_wait_cqe(&ioRing_, &cqe);
if (cqe) {
IoSqe* sqe = reinterpret_cast<IoSqe*>(io_uring_cqe_get_data(cqe));
releaseIoCb(sqe);
::io_uring_cqe_seen(&ioRing_, cqe);
}
}
// exit now
::io_uring_queue_exit(&ioRing_);
ioRing_.ring_fd = -1;
}
......
......@@ -181,14 +181,21 @@ PollIoBackend::IoCb* PollIoBackend::allocIoCb() {
if (FOLLY_LIKELY(freeHead_ != nullptr)) {
auto* ret = freeHead_;
freeHead_ = freeHead_->next_;
numIoCbInUse_++;
return ret;
}
// alloc a new IoCb
return allocNewIoCb();
auto* ret = allocNewIoCb();
if (FOLLY_LIKELY(!!ret)) {
numIoCbInUse_++;
}
return ret;
}
void PollIoBackend::releaseIoCb(PollIoBackend::IoCb* aioIoCb) {
numIoCbInUse_--;
if (FOLLY_LIKELY(aioIoCb->poolAlloc_)) {
aioIoCb->event_ = nullptr;
aioIoCb->next_ = freeHead_;
......
......@@ -190,6 +190,10 @@ class PollIoBackend : public EventBaseBackendBase {
int eb_event_modify_inserted(Event& event, IoCb* ioCb);
FOLLY_ALWAYS_INLINE size_t numIoCbInUse() const {
return numIoCbInUse_;
}
size_t capacity_;
size_t numEntries_;
IoCb* timerEntry_{nullptr};
......@@ -218,5 +222,7 @@ class PollIoBackend : public EventBaseBackendBase {
bool processTimers_{false};
size_t numInsertedEvents_{0};
IoCbList activeEvents_;
// number of IoCb instances in use
size_t numIoCbInUse_{0};
};
} // namespace folly
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