Skip to content

Commit

Permalink
retrying EAGAIN from io_setup in vhost-server (#2143)
Browse files Browse the repository at this point in the history
* retrying EAGAIN from io_setup in vhost-server
  • Loading branch information
sharpeye committed Sep 27, 2024
1 parent c13e5a0 commit 423cd5e
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion cloud/blockstore/vhost-server/backend_aio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cloud/storage/core/libs/common/thread.h>
#include <cloud/storage/core/libs/diagnostics/logging.h>

#include <util/stream/file.h>
#include <util/system/sanitizers.h>

#include <libaio.h>
Expand Down Expand Up @@ -154,6 +155,8 @@ class TAioBackend final: public IBackend
TSimpleStats& queueStats);

void CompletionThreadFunc();

void IoSetup();
};

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -168,6 +171,33 @@ TAioBackend::TAioBackend(
Log = Logging->CreateLog("AIO");
}

void TAioBackend::IoSetup()
{
const auto waitTime = TDuration::MilliSeconds(100);
const int maxIterations = 1000;

int iterations = 0;
int error = 0;

for (; iterations != maxIterations; ++iterations) {
error = io_setup(BatchSize, &Io);
if (error != -EAGAIN) {
break;
}

const auto aioNr = TIFStream("/proc/sys/fs/aio-nr").ReadLine();
const auto aioMaxNr = TIFStream("/proc/sys/fs/aio-max-nr").ReadLine();

STORAGE_WARN(
"retrying EAGAIN from io_setup, BatchSize: "
<< BatchSize << ", aio-nr/aio-max-nr: " << aioNr << "/"
<< aioMaxNr);

Sleep(waitTime);
}
Y_ABORT_UNLESS(!error, "io_setup: %d, iterations: %d", error, iterations);
}

vhd_bdev_info TAioBackend::Init(const TOptions& options)
{
STORAGE_INFO("Initializing AIO backend");
Expand All @@ -176,7 +206,7 @@ vhd_bdev_info TAioBackend::Init(const TOptions& options)
}
BatchSize = options.BatchSize;

Y_ABORT_UNLESS(io_setup(BatchSize, &Io) >= 0, "io_setup");
IoSetup();

for (ui32 i = 0; i < options.QueueCount; i++) {
Batches.emplace_back();
Expand Down

0 comments on commit 423cd5e

Please sign in to comment.