Skip to content

Commit

Permalink
[Filestore] issue-1751: support guest writeback cache
Browse files Browse the repository at this point in the history
Pass FUSE_CAP_WRITEBACK_CACHE to fuse client when GuestWritebackCacheEnabled
flag is set. This flag ensures that individual write request may be buffered and
merged in the kernel of the filesystem client
  • Loading branch information
budevg committed Oct 31, 2024
1 parent 11aab3b commit 9328308
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cloud/filestore/config/filesystem.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@ message TFileSystemConfig

// Aligment needed for buffers when using direct io
optional uint32 DirectIoAlign = 14;

// Enable Writeback cache on guest (fuse client)
optional bool GuestWritebackCacheEnabled = 15;
}
4 changes: 4 additions & 0 deletions cloud/filestore/config/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ message TLocalServiceConfig

// Aligment needed for buffers when using direct io
optional uint32 DirectIoAlign = 10;

// Enable Writeback cache on guest (fuse client)
optional bool GuestWritebackCacheEnabled = 11;

}

////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 3 additions & 0 deletions cloud/filestore/config/storage.proto
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,7 @@ message TStorageConfig

// Disables TwoStageRead for HDD filesystems.
optional bool TwoStageReadDisabledForHDD = 404;

// Enable Writeback cache on guest (fuse client)
optional bool GuestWritebackCacheEnabled = 405;
}
1 change: 1 addition & 0 deletions cloud/filestore/libs/service_local/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace {
xxx(MaxHandlePerSessionCount, ui32, 10000 )\
xxx(DirectIoEnabled, bool, false )\
xxx(DirectIoAlign, ui32, 4_KB )\
xxx(GuestWritebackCacheEnabled, bool, false )\
// FILESTORE_SERVICE_CONFIG

#define FILESTORE_SERVICE_DECLARE_CONFIG(name, type, value) \
Expand Down
1 change: 1 addition & 0 deletions cloud/filestore/libs/service_local/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class TLocalFileStoreConfig
ui32 GetMaxHandlePerSessionCount() const;
bool GetDirectIoEnabled() const;
ui32 GetDirectIoAlign() const;
bool GetGuestWritebackCacheEnabled() const;

void Dump(IOutputStream& out) const;
void DumpHtml(IOutputStream& out) const;
Expand Down
2 changes: 2 additions & 0 deletions cloud/filestore/libs/service_local/fs_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ NProto::TCreateSessionResponse TLocalFileSystem::CreateSession(
auto* features = response.MutableFileStore()->MutableFeatures();
features->SetDirectIoEnabled(Config->GetDirectIoEnabled());
features->SetDirectIoAlign(Config->GetDirectIoAlign());
features->SetGuestWritebackCacheEnabled(
Config->GetGuestWritebackCacheEnabled());

return response;
}
Expand Down
1 change: 1 addition & 0 deletions cloud/filestore/libs/storage/core/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ using TAliases = NProto::TStorageConfig::TFilestoreAliases;
xxx(GarbageCompactionThresholdAverage, ui32, 20 )\
xxx(CompactRangeGarbagePercentageThreshold, ui32, 0 )\
xxx(CompactRangeAverageBlobSizeThreshold, ui32, 0 )\
xxx(GuestWritebackCacheEnabled, bool, false )\
xxx(NewCompactionEnabled, bool, false )\
xxx(UseMixedBlocksInsteadOfAliveBlocksInCompaction, bool, false )\
xxx(CollectGarbageThreshold, ui32, 4_MB )\
Expand Down
2 changes: 2 additions & 0 deletions cloud/filestore/libs/storage/core/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ class TStorageConfig

bool GetTwoStageReadDisabledForHDD() const;
bool GetThreeStageWriteDisabledForHDD() const;

bool GetGuestWritebackCacheEnabled() const;
};

} // namespace NCloud::NFileStore::NStorage
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ void FillFeatures(const TStorageConfig& config, NProto::TFileStore& fileStore)
config.GetAsyncDestroyHandleEnabled());
features->SetAsyncHandleOperationPeriod(
config.GetAsyncHandleOperationPeriod().MilliSeconds());

features->SetGuestWritebackCacheEnabled(
config.GetGuestWritebackCacheEnabled());
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions cloud/filestore/libs/vfs_fuse/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ namespace {
\
xxx(DirectIoEnabled, bool, false )\
xxx(DirectIoAlign, ui32, 4_KB )\
\
xxx(GuestWritebackCacheEnabled, bool, false )\
// FILESTORE_FUSE_CONFIG

#define FILESTORE_FILESYSTEM_DECLARE_CONFIG(name, type, value) \
Expand Down
2 changes: 2 additions & 0 deletions cloud/filestore/libs/vfs_fuse/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ struct TFileSystemConfig
bool GetDirectIoEnabled() const;
ui32 GetDirectIoAlign() const;

bool GetGuestWritebackCacheEnabled() const;

void Dump(IOutputStream& out) const;
void DumpHtml(IOutputStream& out) const;
};
Expand Down
18 changes: 13 additions & 5 deletions cloud/filestore/libs/vfs_fuse/loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ class TFileSystemLoop final
std::shared_ptr<TCompletionQueue> CompletionQueue;
IRequestStatsPtr RequestStats;
IFileSystemPtr FileSystem;
TFileSystemConfigPtr FileSystemConfig;

bool HandleOpsQueueInitialized = false;

Expand Down Expand Up @@ -785,13 +786,13 @@ class TFileSystemLoop final
RequestStats,
Log,
StorageMediaKind);
auto filestoreConfig = MakeFileSystemConfig(filestore);
FileSystemConfig = MakeFileSystemConfig(filestore);
std::unique_ptr<THandleOpsQueue> handleOpsQueue;

if (filestoreConfig->GetAsyncDestroyHandleEnabled()) {
if (FileSystemConfig->GetAsyncDestroyHandleEnabled()) {
TString path =
TFsPath(Config->GetHandleOpsQueuePath()) /
filestoreConfig->GetFileSystemId() /
FileSystemConfig->GetFileSystemId() /
response.GetSession().GetSessionId();
if (!NFs::MakeDirectoryRecursive(path)) {
TString msg = TStringBuilder()
Expand All @@ -816,7 +817,7 @@ class TFileSystemLoop final
ProfileLog,
Scheduler,
Timer,
filestoreConfig,
FileSystemConfig,
Session,
RequestStats,
CompletionQueue,
Expand All @@ -834,7 +835,7 @@ class TFileSystemLoop final
SessionState.empty() ? "new" : "existing");

TStringStream filestoreConfigDump;
filestoreConfig->Dump(filestoreConfigDump);
FileSystemConfig->Dump(filestoreConfigDump);
STORAGE_INFO(
"[f:%s][c:%s] new session filestore config: %s",
Config->GetFileSystemId().Quote().c_str(),
Expand Down Expand Up @@ -900,6 +901,9 @@ class TFileSystemLoop final
config.SetDirectIoEnabled(features.GetDirectIoEnabled());
config.SetDirectIoAlign(features.GetDirectIoAlign());

config.SetGuestWritebackCacheEnabled(
features.GetGuestWritebackCacheEnabled());

return std::make_shared<TFileSystemConfig>(config);
}

Expand Down Expand Up @@ -931,6 +935,10 @@ class TFileSystemLoop final
// e.g. left from a crash or smth, paranoid mode
ResetSessionState(SessionThread->GetSession().Dump());

if (FileSystemConfig->GetGuestWritebackCacheEnabled()) {
conn->want |= FUSE_CAP_WRITEBACK_CACHE;
}

FileSystem->Init();
}

Expand Down
1 change: 1 addition & 0 deletions cloud/filestore/public/api/protos/fs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ message TFileStoreFeatures
uint32 DirectIoAlign = 11;
bool TwoStageReadDisabledForHDD = 12;
bool ThreeStageWriteDisabledForHDD = 13;
bool GuestWritebackCacheEnabled = 14;
}

message TFileStore
Expand Down
2 changes: 2 additions & 0 deletions contrib/libs/fuse/include/fuse_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ struct fuse_file_info {
* FUSE_CAP_SPLICE_MOVE: ability to move data to the fuse device with splice()
* FUSE_CAP_SPLICE_READ: ability to use splice() to read from the fuse device
* FUSE_CAP_IOCTL_DIR: ioctl support on directories
* FUSE_CAP_WRITEBACK_CACHE: writeback caching should be enabled
*/
#define FUSE_CAP_ASYNC_READ (1 << 0)
#define FUSE_CAP_POSIX_LOCKS (1 << 1)
Expand All @@ -112,6 +113,7 @@ struct fuse_file_info {
#define FUSE_CAP_SPLICE_READ (1 << 9)
#define FUSE_CAP_FLOCK_LOCKS (1 << 10)
#define FUSE_CAP_IOCTL_DIR (1 << 11)
#define FUSE_CAP_WRITEBACK_CACHE (1 << 16)

/**
* Ioctl flags
Expand Down
1 change: 1 addition & 0 deletions contrib/libs/fuse/include/fuse_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ struct fuse_file_lock {
#define FUSE_BIG_WRITES (1 << 5)
#define FUSE_DONT_MASK (1 << 6)
#define FUSE_FLOCK_LOCKS (1 << 10)
#define FUSE_WRITEBACK_CACHE (1 << 16)

/**
* CUSE INIT request/reply flags
Expand Down
3 changes: 3 additions & 0 deletions contrib/libs/fuse/lib/fuse_lowlevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,9 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
outarg.flags |= FUSE_DONT_MASK;
if (f->conn.want & FUSE_CAP_FLOCK_LOCKS)
outarg.flags |= FUSE_FLOCK_LOCKS;
if (f->conn.want & FUSE_CAP_WRITEBACK_CACHE)
outarg.flags |= FUSE_WRITEBACK_CACHE;

outarg.max_readahead = f->conn.max_readahead;
outarg.max_write = f->conn.max_write;
if (f->conn.proto_minor >= 13) {
Expand Down

0 comments on commit 9328308

Please sign in to comment.