Loading include/client/open_file_map.hpp +7 −0 Original line number Diff line number Diff line Loading @@ -122,8 +122,15 @@ public: void inline_data(const std::string& data); size_t inline_data_size() const; void inline_data_size(size_t size); private: std::string inline_data_; size_t inline_data_size_{0}; }; Loading include/config.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -142,7 +142,7 @@ constexpr auto inline_data_size = 4096; // in bytes // a write appears) constexpr auto create_write_optimization = false; // Prefetch inline data on read operations constexpr auto read_inline_prefetch = false; constexpr auto read_inline_prefetch = true; } // namespace metadata Loading src/client/gkfs_functions.cpp +22 −4 Original line number Diff line number Diff line Loading @@ -343,6 +343,7 @@ gkfs_open(const std::string& path, mode_t mode, int flags) { if(gkfs::config::metadata::read_inline_prefetch and !md.inline_data().empty()) { file->inline_data(md.inline_data()); file->inline_data_size(md.size()); // Store the actual file size } auto fd = CTX->file_map()->add(file); Loading Loading @@ -1425,10 +1426,27 @@ gkfs_do_read(const gkfs::filemap::OpenFile& file, char* buf, size_t count, offset < gkfs::config::metadata::inline_data_size) { // OPTIMIZATION: Check if we have the inline data cached if(!file.inline_data().empty() && count <= file.inline_data().size()) { LOG(DEBUG, "{}() Using cached inline data", __func__); memcpy(buf, file.inline_data().c_str() + offset, count); return count; // We optimize if the client requested at least the size of the file (count + offset > size) // or if the count is <= size if(!file.inline_data().empty() && (offset + count <= file.inline_data_size() || count <= file.inline_data().size())) { // Logic to calculate how much to copy // If requested count goes beyond file size, we clamp it size_t copy_size = 0; if (offset < file.inline_data_size()) { copy_size = std::min(count, file.inline_data_size() - offset); } // If offset is beyond size, copy_size remains 0 (EOF) LOG(DEBUG, "{}() Using cached inline data. count: {} offset: {} size: {} copy: {}", __func__, count, offset, file.inline_data_size(), copy_size); if (copy_size > 0) memcpy(buf, file.inline_data().c_str() + offset, copy_size); return copy_size; } // Forward the read request to the Metadata Server instead of Data Loading src/client/open_file_map.cpp +11 −1 Original line number Diff line number Diff line Loading @@ -129,10 +129,20 @@ OpenFile::inline_data() const { } void OpenFile::inline_data(const string& data) { OpenFile::inline_data(const std::string& data) { OpenFile::inline_data_ = data; } size_t OpenFile::inline_data_size() const { return inline_data_size_; } void OpenFile::inline_data_size(size_t size) { OpenFile::inline_data_size_ = size; } shared_ptr<OpenFile> OpenFileMap::get(int fd) { lock_guard<recursive_mutex> lock(files_mutex_); Loading tests/integration/data/test_inline_read_opt.py +5 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,11 @@ def test_inline_read_optimization(gkfs_daemon, gkfs_client): ret = gkfs_client.run('write', file01, data01, len(data01), '--creat') assert ret.retval == len(data01) # Verify stat immediately after write ret = gkfs_client.stat(file01) assert ret.retval == 0 assert ret.statbuf.st_size == len(data01) # 2. Open file for reading # This should now fetch the inline data into the OpenFile object ret = gkfs_client.open(file01, Loading Loading
include/client/open_file_map.hpp +7 −0 Original line number Diff line number Diff line Loading @@ -122,8 +122,15 @@ public: void inline_data(const std::string& data); size_t inline_data_size() const; void inline_data_size(size_t size); private: std::string inline_data_; size_t inline_data_size_{0}; }; Loading
include/config.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -142,7 +142,7 @@ constexpr auto inline_data_size = 4096; // in bytes // a write appears) constexpr auto create_write_optimization = false; // Prefetch inline data on read operations constexpr auto read_inline_prefetch = false; constexpr auto read_inline_prefetch = true; } // namespace metadata Loading
src/client/gkfs_functions.cpp +22 −4 Original line number Diff line number Diff line Loading @@ -343,6 +343,7 @@ gkfs_open(const std::string& path, mode_t mode, int flags) { if(gkfs::config::metadata::read_inline_prefetch and !md.inline_data().empty()) { file->inline_data(md.inline_data()); file->inline_data_size(md.size()); // Store the actual file size } auto fd = CTX->file_map()->add(file); Loading Loading @@ -1425,10 +1426,27 @@ gkfs_do_read(const gkfs::filemap::OpenFile& file, char* buf, size_t count, offset < gkfs::config::metadata::inline_data_size) { // OPTIMIZATION: Check if we have the inline data cached if(!file.inline_data().empty() && count <= file.inline_data().size()) { LOG(DEBUG, "{}() Using cached inline data", __func__); memcpy(buf, file.inline_data().c_str() + offset, count); return count; // We optimize if the client requested at least the size of the file (count + offset > size) // or if the count is <= size if(!file.inline_data().empty() && (offset + count <= file.inline_data_size() || count <= file.inline_data().size())) { // Logic to calculate how much to copy // If requested count goes beyond file size, we clamp it size_t copy_size = 0; if (offset < file.inline_data_size()) { copy_size = std::min(count, file.inline_data_size() - offset); } // If offset is beyond size, copy_size remains 0 (EOF) LOG(DEBUG, "{}() Using cached inline data. count: {} offset: {} size: {} copy: {}", __func__, count, offset, file.inline_data_size(), copy_size); if (copy_size > 0) memcpy(buf, file.inline_data().c_str() + offset, copy_size); return copy_size; } // Forward the read request to the Metadata Server instead of Data Loading
src/client/open_file_map.cpp +11 −1 Original line number Diff line number Diff line Loading @@ -129,10 +129,20 @@ OpenFile::inline_data() const { } void OpenFile::inline_data(const string& data) { OpenFile::inline_data(const std::string& data) { OpenFile::inline_data_ = data; } size_t OpenFile::inline_data_size() const { return inline_data_size_; } void OpenFile::inline_data_size(size_t size) { OpenFile::inline_data_size_ = size; } shared_ptr<OpenFile> OpenFileMap::get(int fd) { lock_guard<recursive_mutex> lock(files_mutex_); Loading
tests/integration/data/test_inline_read_opt.py +5 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,11 @@ def test_inline_read_optimization(gkfs_daemon, gkfs_client): ret = gkfs_client.run('write', file01, data01, len(data01), '--creat') assert ret.retval == len(data01) # Verify stat immediately after write ret = gkfs_client.stat(file01) assert ret.retval == 0 assert ret.statbuf.st_size == len(data01) # 2. Open file for reading # This should now fetch the inline data into the OpenFile object ret = gkfs_client.open(file01, Loading