Skip to content

Commit c0981e0

Browse files
Jaesoo Leefacebook-github-bot
authored andcommitted
AsyncDevice: add support for libaio
Summary: This change adds the support for libaio. As such, user can select which aio implementation to use via a configuration option NavyConfig::enableIoUring_ between io_uring and libaio. Reviewed By: therealgymmy Differential Revision: D47306900 fbshipit-source-id: f09555213a3d39e8e666486f30b2e87f0c093188
1 parent 112817d commit c0981e0

File tree

8 files changed

+166
-101
lines changed

8 files changed

+166
-101
lines changed

cachelib/allocator/nvmcache/NavyConfig.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ std::map<std::string, std::string> NavyConfig::serialize() const {
232232
configMap["navyConfig::numIoThreads"] = folly::to<std::string>(numIoThreads_);
233233
configMap["navyConfig::QDepthPerThread"] =
234234
folly::to<std::string>(qDepthPerThread_);
235+
configMap["navyConfig::enableIoUring"] = enableIoUring_ ? "true" : "false";
235236
// Other settings
236237
configMap["navyConfig::maxConcurrentInserts"] =
237238
folly::to<std::string>(maxConcurrentInserts_);

cachelib/allocator/nvmcache/NavyConfig.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ class NavyConfig {
478478
const RandomAPConfig& randomAdmPolicy() const { return randomAPConfig_; }
479479

480480
// ============ Device settings =============
481+
bool getEnableIoUring() const { return enableIoUring_; }
481482
unsigned int getNumIoThreads() const { return numIoThreads_; }
482483
unsigned int getQDepthPerThread() const { return qDepthPerThread_; }
483484
uint64_t getBlockSize() const { return blockSize_; }
@@ -527,6 +528,11 @@ class NavyConfig {
527528
// configurations. For now, AsyncDevice is not supported for RAID.
528529
void setIoThreads(unsigned int numIoThreads, unsigned int qDepthPerThread);
529530

531+
// Enable io_uring engine; applicable for AsyncDevice only
532+
void setEnableIoUring(bool enableIoUring) noexcept {
533+
enableIoUring_ = enableIoUring;
534+
}
535+
530536
// Set the device block size, i.e., minimum unit of IO
531537
void setBlockSize(uint64_t blockSize) noexcept { blockSize_ = blockSize; }
532538
// Set the parameters for a simple file.
@@ -621,6 +627,13 @@ class NavyConfig {
621627
// This is only used when in-mem buffer is enabled.
622628
uint32_t deviceMaxWriteSize_{};
623629

630+
// Number of IO threads for AsyncDevice.
631+
unsigned int numIoThreads_{0};
632+
// Number of queue depth per thread for AsyncDevice.
633+
unsigned int qDepthPerThread_{64};
634+
// Enable io_uring
635+
bool enableIoUring_{true};
636+
624637
// ============ Engines settings =============
625638
// Currently we support one pair of engines.
626639
std::vector<EnginesConfig> enginesConfigs_{1};
@@ -637,10 +650,6 @@ class NavyConfig {
637650
// This value needs to be non-zero.
638651
uint64_t navyReqOrderingShards_{20};
639652

640-
// Number of IO threads for AsyncDevice.
641-
unsigned int numIoThreads_{0};
642-
// Number of queue depth per thread for AsyncDevice.
643-
unsigned int qDepthPerThread_{64};
644653
// ============ Other settings =============
645654
// Maximum number of concurrent inserts we allow globally for Navy.
646655
// 0 means unlimited.

cachelib/allocator/nvmcache/NavySetup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ std::unique_ptr<cachelib::navy::Device> createDevice(
333333
config.getNumIoThreads(),
334334
config.getQDepthPerThread(),
335335
std::move(encryptor),
336-
maxDeviceWriteSize > 0 ? alignDown(maxDeviceWriteSize, blockSize)
337-
: 0);
336+
maxDeviceWriteSize > 0 ? alignDown(maxDeviceWriteSize, blockSize) : 0,
337+
config.getEnableIoUring());
338338
}
339339
return cachelib::navy::createFileDevice(
340340
config.getFileName(),

cachelib/allocator/nvmcache/tests/NavyConfigTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ TEST(NavyConfigTest, Serialization) {
185185
expectedConfigMap["navyConfig::deviceMaxWriteSize"] = "4194304";
186186
expectedConfigMap["navyConfig::numIoThreads"] = "0";
187187
expectedConfigMap["navyConfig::QDepthPerThread"] = "64";
188+
expectedConfigMap["navyConfig::enableIoUring"] = "true";
188189

189190
expectedConfigMap["navyConfig::blockCacheLru"] = "false";
190191
expectedConfigMap["navyConfig::blockCacheRegionSize"] = "16777216";

cachelib/navy/Factory.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,17 +503,18 @@ std::unique_ptr<Device> createAsyncFileDevice(
503503
uint32_t numIoThreads,
504504
uint32_t qDepthPerThread,
505505
std::shared_ptr<DeviceEncryptor> encryptor,
506-
uint32_t maxDeviceWriteSize) {
506+
uint32_t maxDeviceWriteSize,
507+
bool enableIoUring) {
507508
folly::File f;
508509
try {
509510
f = openCacheFile(fileName, singleFileSize, truncateFile);
510511
} catch (const std::exception& e) {
511512
XLOG(ERR) << "Exception in openCacheFile: " << e.what();
512513
throw;
513514
}
514-
return createAsyncIoFileDevice(std::move(f), singleFileSize, blockSize,
515-
numIoThreads, qDepthPerThread,
516-
std::move(encryptor), maxDeviceWriteSize);
515+
return createAsyncIoFileDevice(
516+
std::move(f), singleFileSize, blockSize, numIoThreads, qDepthPerThread,
517+
std::move(encryptor), maxDeviceWriteSize, enableIoUring);
517518
}
518519

519520
} // namespace navy

cachelib/navy/Factory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ std::unique_ptr<Device> createAsyncFileDevice(
247247
uint32_t numIoThreads,
248248
uint32_t qDepthPerThread,
249249
std::shared_ptr<DeviceEncryptor> encryptor,
250-
uint32_t maxDeviceWriteSize);
250+
uint32_t maxDeviceWriteSize,
251+
bool enableIoUring);
251252

252253
} // namespace navy
253254
} // namespace cachelib

0 commit comments

Comments
 (0)