Skip to content

Commit

Permalink
issue-2086: use multiple aio services (#2126)
Browse files Browse the repository at this point in the history
* issue-2086: use multiple aio services
  • Loading branch information
sharpeye authored Sep 27, 2024
1 parent 04cca17 commit f4cf1bb
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 75 deletions.
7 changes: 7 additions & 0 deletions cloud/blockstore/config/disk.proto
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ message TDiskAgentConfig

// Max. count of concurrently processing operations (io_setup).
optional uint32 MaxAIOContextEvents = 33;

// Number of paths per each FileIOService.
// 0 means that only one IO service will be created.
// 1 means that one IO service per file path will be created.
// 2 means that one IO service will be created for every two file paths.
// etc.
optional uint32 PathsPerFileIOService = 34;
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
10 changes: 6 additions & 4 deletions cloud/blockstore/libs/daemon/common/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <cloud/blockstore/libs/service/service_filtered.h>
#include <cloud/blockstore/libs/service/service_null.h>
#include <cloud/blockstore/libs/service/storage_provider.h>
#include <cloud/blockstore/libs/service_local/file_io_service_provider.h>
#include <cloud/blockstore/libs/service_local/service_local.h>
#include <cloud/blockstore/libs/service_local/storage_aio.h>
#include <cloud/blockstore/libs/service_local/storage_null.h>
Expand Down Expand Up @@ -740,7 +741,8 @@ void TBootstrapBase::InitLocalService()
? *Configs->ServerConfig->GetLocalServiceConfig()
: NProto::TLocalServiceConfig();

FileIOService = CreateAIOService();
FileIOServiceProvider =
CreateSingleFileIOServiceProvider(CreateAIOService());

NvmeManager = CreateNvmeManager(
Configs->DiskAgentConfig->GetSecureEraseTimeout());
Expand All @@ -749,7 +751,7 @@ void TBootstrapBase::InitLocalService()
config,
DiscoveryService,
CreateAioStorageProvider(
FileIOService,
FileIOServiceProvider,
NvmeManager,
false, // directIO
EAioSubmitQueueOpt::DontUse
Expand Down Expand Up @@ -869,7 +871,7 @@ void TBootstrapBase::Start()
START_KIKIMR_COMPONENT(StatsUploader);
START_COMMON_COMPONENT(Spdk);
START_KIKIMR_COMPONENT(ActorSystem);
START_COMMON_COMPONENT(FileIOService);
START_COMMON_COMPONENT(FileIOServiceProvider);
START_COMMON_COMPONENT(EndpointProxyClient);
START_COMMON_COMPONENT(EndpointManager);
START_COMMON_COMPONENT(Service);
Expand Down Expand Up @@ -939,7 +941,7 @@ void TBootstrapBase::Stop()
STOP_COMMON_COMPONENT(Service);
STOP_COMMON_COMPONENT(EndpointManager);
STOP_COMMON_COMPONENT(EndpointProxyClient);
STOP_COMMON_COMPONENT(FileIOService);
STOP_COMMON_COMPONENT(FileIOServiceProvider);
STOP_KIKIMR_COMPONENT(ActorSystem);
STOP_COMMON_COMPONENT(Spdk);
STOP_KIKIMR_COMPONENT(StatsUploader);
Expand Down
2 changes: 1 addition & 1 deletion cloud/blockstore/libs/daemon/common/bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TBootstrapBase
NVhost::IServerPtr VhostServer;
NVhost::TVhostCallbacks VhostCallbacks;
NBD::IServerPtr NbdServer;
IFileIOServicePtr FileIOService;
IFileIOServiceProviderPtr FileIOServiceProvider;
IStorageProviderPtr StorageProvider;
IKmsKeyProviderPtr KmsKeyProvider;
IRootKmsKeyProviderPtr RootKmsKeyProvider;
Expand Down
31 changes: 18 additions & 13 deletions cloud/blockstore/libs/daemon/ydb/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <cloud/blockstore/libs/service/service_auth.h>
#include <cloud/blockstore/libs/service_kikimr/auth_provider_kikimr.h>
#include <cloud/blockstore/libs/service_kikimr/service_kikimr.h>
#include <cloud/blockstore/libs/service_local/file_io_service_provider.h>
#include <cloud/blockstore/libs/service_local/storage_aio.h>
#include <cloud/blockstore/libs/service_local/storage_null.h>
#include <cloud/blockstore/libs/spdk/iface/env.h>
Expand Down Expand Up @@ -433,23 +434,30 @@ void TBootstrapYdb::InitKikimrService()

InitSpdk();

FileIOService = CreateAIOService();

if (Configs->DiskAgentConfig->GetEnabled() &&
Configs->DiskAgentConfig->GetBackend() == NProto::DISK_AGENT_BACKEND_AIO &&
if (const auto& config = *Configs->DiskAgentConfig;
config.GetEnabled() &&
config.GetBackend() == NProto::DISK_AGENT_BACKEND_AIO &&
!AioStorageProvider)
{
Y_ABORT_UNLESS(FileIOService);

NvmeManager = CreateNvmeManager(
Configs->DiskAgentConfig->GetSecureEraseTimeout());

auto factory = [events = config.GetMaxAIOContextEvents()] {
return CreateAIOService(events);
};

FileIOServiceProvider =
config.GetPathsPerFileIOService()
? CreateFileIOServiceProvider(
config.GetPathsPerFileIOService(),
factory)
: CreateSingleFileIOServiceProvider(factory());

AioStorageProvider = CreateAioStorageProvider(
FileIOService,
FileIOServiceProvider,
NvmeManager,
!Configs->DiskAgentConfig->GetDirectIoFlagDisabled(),
EAioSubmitQueueOpt::DontUse
);
!config.GetDirectIoFlagDisabled(),
EAioSubmitQueueOpt::DontUse);

STORAGE_INFO("AioStorageProvider initialized");
}
Expand All @@ -465,8 +473,6 @@ void TBootstrapYdb::InitKikimrService()
STORAGE_INFO("AioStorageProvider (null) initialized");
}

Y_ABORT_UNLESS(FileIOService);

Allocator = CreateCachingAllocator(
Spdk ? Spdk->GetAllocator() : TDefaultAllocator::Instance(),
Configs->DiskAgentConfig->GetPageSize(),
Expand Down Expand Up @@ -534,7 +540,6 @@ void TBootstrapYdb::InitKikimrService()
args.DiscoveryService = DiscoveryService;
args.Spdk = Spdk;
args.Allocator = Allocator;
args.FileIOService = FileIOService;
args.AioStorageProvider = AioStorageProvider;
args.ProfileLog = ProfileLog;
args.BlockDigestGenerator = BlockDigestGenerator;
Expand Down
26 changes: 18 additions & 8 deletions cloud/blockstore/libs/disk_agent/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cloud/blockstore/libs/rdma/iface/probes.h>
#include <cloud/blockstore/libs/rdma/iface/server.h>
#include <cloud/blockstore/libs/server/config.h>
#include <cloud/blockstore/libs/service_local/file_io_service_provider.h>
#include <cloud/blockstore/libs/service_local/storage_aio.h>
#include <cloud/blockstore/libs/service_local/storage_null.h>
#include <cloud/blockstore/libs/spdk/iface/config.h>
Expand Down Expand Up @@ -430,20 +431,30 @@ bool TBootstrap::InitKikimrService()
break;
}

case NProto::DISK_AGENT_BACKEND_AIO:
FileIOService =
CreateAIOService(config.GetMaxAIOContextEvents());
case NProto::DISK_AGENT_BACKEND_AIO: {
NvmeManager = CreateNvmeManager(config.GetSecureEraseTimeout());

auto factory = [events = config.GetMaxAIOContextEvents()] {
return CreateAIOService(events);
};

FileIOServiceProvider =
config.GetPathsPerFileIOService()
? CreateFileIOServiceProvider(
config.GetPathsPerFileIOService(),
factory)
: CreateSingleFileIOServiceProvider(factory());

AioStorageProvider = CreateAioStorageProvider(
FileIOService,
FileIOServiceProvider,
NvmeManager,
!config.GetDirectIoFlagDisabled(),
EAioSubmitQueueOpt::Use
);

STORAGE_INFO("Aio backend initialized");
break;
}
case NProto::DISK_AGENT_BACKEND_NULL:
NvmeManager = CreateNvmeManager(config.GetSecureEraseTimeout());
AioStorageProvider = CreateNullStorageProvider();
Expand Down Expand Up @@ -489,7 +500,6 @@ bool TBootstrap::InitKikimrService()
args.AsyncLogger = AsyncLogger;
args.Spdk = Spdk;
args.Allocator = Allocator;
args.FileIOService = FileIOService;
args.AioStorageProvider = AioStorageProvider;
args.ProfileLog = ProfileLog;
args.BlockDigestGenerator = BlockDigestGenerator;
Expand Down Expand Up @@ -606,7 +616,7 @@ void TBootstrap::Start()
START_COMPONENT(TraceProcessor);
START_COMPONENT(Spdk);
START_COMPONENT(RdmaServer);
START_COMPONENT(FileIOService);
START_COMPONENT(FileIOServiceProvider);
START_COMPONENT(ActorSystem);

// we need to start scheduler after all other components for 2 reasons:
Expand Down Expand Up @@ -644,9 +654,9 @@ void TBootstrap::Stop()
STOP_COMPONENT(Scheduler);

STOP_COMPONENT(ActorSystem);
// stop FileIOService after ActorSystem to ensure that there are no
// stop FileIOServiceProvider after ActorSystem to ensure that there are no
// in-flight I/O requests from TDiskAgentActor
STOP_COMPONENT(FileIOService);
STOP_COMPONENT(FileIOServiceProvider);

STOP_COMPONENT(Spdk);
STOP_COMPONENT(RdmaServer);
Expand Down
2 changes: 1 addition & 1 deletion cloud/blockstore/libs/disk_agent/bootstrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TBootstrap
ITraceProcessorPtr TraceProcessor;
IProfileLogPtr ProfileLog;
IBlockDigestGeneratorPtr BlockDigestGenerator;
IFileIOServicePtr FileIOService;
IFileIOServiceProviderPtr FileIOServiceProvider;
NSpdk::ISpdkEnvPtr Spdk;
std::function<void(TLog& log)> SpdkLogInitializer;
ICachingAllocatorPtr Allocator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class TFileIOServiceProvider final

////////////////////////////////////////////////////////////////////////////////

struct TFileIOServiceProviderStub final
struct TSingleFileIOServiceProvider final
: IFileIOServiceProvider
{
IFileIOServicePtr FileIO;

explicit TFileIOServiceProviderStub(
explicit TSingleFileIOServiceProvider(
IFileIOServicePtr fileIO)
: FileIO{std::move(fileIO)}
{}
Expand All @@ -96,10 +96,10 @@ struct TFileIOServiceProviderStub final

////////////////////////////////////////////////////////////////////////////////

IFileIOServiceProviderPtr CreateFileIOServiceProviderStub(
IFileIOServiceProviderPtr CreateSingleFileIOServiceProvider(
IFileIOServicePtr fileIO)
{
return std::make_shared<TFileIOServiceProviderStub>(std::move(fileIO));
return std::make_shared<TSingleFileIOServiceProvider>(std::move(fileIO));
}

IFileIOServiceProviderPtr CreateFileIOServiceProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct IFileIOServiceProvider

////////////////////////////////////////////////////////////////////////////////

IFileIOServiceProviderPtr CreateFileIOServiceProviderStub(
IFileIOServiceProviderPtr CreateSingleFileIOServiceProvider(
IFileIOServicePtr fileIO);

IFileIOServiceProviderPtr CreateFileIOServiceProvider(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Y_UNIT_TEST_SUITE(TFileIOServiceProviderTest)
auto fileIO = std::make_shared<TTestFileIOService>();
UNIT_ASSERT_VALUES_EQUAL(0, fileIO->Started);

auto provider = CreateFileIOServiceProviderStub(fileIO);
auto provider = CreateSingleFileIOServiceProvider(fileIO);
provider->Start();

UNIT_ASSERT_VALUES_EQUAL(1, fileIO->Started);
Expand Down
16 changes: 9 additions & 7 deletions cloud/blockstore/libs/service_local/storage_aio.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "storage_aio.h"

#include "file_io_service_provider.h"

#include <cloud/blockstore/libs/common/iovector.h>
#include <cloud/blockstore/libs/nvme/nvme.h>
#include <cloud/blockstore/libs/service/context.h>
Expand Down Expand Up @@ -882,7 +884,7 @@ class TSafeDeallocator
const NProto::TError& error,
ui32 bytes)
{
auto checker = static_cast<TSafeDeallocator*>(completion);
auto* checker = static_cast<TSafeDeallocator*>(completion);
checker->ReadBlockComplete(error, bytes);
}
};
Expand Down Expand Up @@ -916,18 +918,18 @@ class TAioStorageProvider final
{
private:
ITaskQueuePtr SubmitQueue;
IFileIOServicePtr FileIOService;
IFileIOServiceProviderPtr FileIOServiceProvider;
INvmeManagerPtr NvmeManager;
const bool DirectIO;

public:
explicit TAioStorageProvider(
ITaskQueuePtr submitQueue,
IFileIOServicePtr fileIO,
IFileIOServiceProviderPtr fileIOProvider,
INvmeManagerPtr nvmeManager,
bool directIO)
: SubmitQueue(std::move(submitQueue))
, FileIOService(std::move(fileIO))
, FileIOServiceProvider(std::move(fileIOProvider))
, NvmeManager(std::move(nvmeManager))
, DirectIO(directIO)
{}
Expand Down Expand Up @@ -957,7 +959,7 @@ class TAioStorageProvider final

auto storage = std::make_shared<TAioStorage>(
SubmitQueue,
FileIOService,
FileIOServiceProvider->CreateFileIOService(filePath),
NvmeManager,
blockSize,
volume.GetStartIndex(),
Expand All @@ -974,7 +976,7 @@ class TAioStorageProvider final
////////////////////////////////////////////////////////////////////////////////

IStorageProviderPtr CreateAioStorageProvider(
IFileIOServicePtr fileIO,
IFileIOServiceProviderPtr fileIOProvider,
INvmeManagerPtr nvmeManager,
bool directIO,
EAioSubmitQueueOpt submitQueueOpt)
Expand All @@ -986,7 +988,7 @@ IStorageProviderPtr CreateAioStorageProvider(

return std::make_shared<TAioStorageProvider>(
std::move(submitQueue),
std::move(fileIO),
std::move(fileIOProvider),
std::move(nvmeManager),
directIO);
}
Expand Down
2 changes: 1 addition & 1 deletion cloud/blockstore/libs/service_local/storage_aio.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum class EAioSubmitQueueOpt : bool {
////////////////////////////////////////////////////////////////////////////////

IStorageProviderPtr CreateAioStorageProvider(
IFileIOServicePtr fileIO,
IFileIOServiceProviderPtr fileIOProvider,
NNvme::INvmeManagerPtr nvmeManager,
bool directIO,
EAioSubmitQueueOpt submitQueueOpt);
Expand Down
Loading

0 comments on commit f4cf1bb

Please sign in to comment.