Skip to content

Commit

Permalink
lazyfs and cache: add option for sync other files in sync pages fault
Browse files Browse the repository at this point in the history
  • Loading branch information
mj-ramos committed Oct 14, 2024
1 parent 23d1190 commit af8020e
Show file tree
Hide file tree
Showing 8 changed files with 454 additions and 339 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ cd lazyfs/

./scripts/mount-lazyfs.sh -c config/default.toml -m /tmp/lazyfs.mnt -r /tmp/lazyfs.root

# [Recommended] Running LazyFS in single-thread mode (add '-s')

./scripts/mount-lazyfs.sh -c config/default.toml -m /tmp/lazyfs.mnt -r /tmp/lazyfs.root -s


# Umount with

./scripts/umount-lazyfs.sh -m /tmp/lazyfs.mnt/
Expand Down
2 changes: 1 addition & 1 deletion lazyfs/include/lazyfs/lazyfs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class LazyFS : public Fusepp::Fuse<LazyFS> {
* @param parts Pages to be persisted
*
*/
void command_fault_sync_page (string path, string parts, bool lock_needed = true);
void command_fault_sync_page (string path, string parts, bool sync_other_files, bool lock_needed = true);

/**
* @brief Fifo: (info) Display the cache usage
Expand Down
707 changes: 386 additions & 321 deletions lazyfs/src/lazyfs.cpp

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions libs/libpcache/include/cache/cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Cache {
*/
cache::config::Config* cache_config;
/**
* @brief Maps content ids (e.g. file names) to the contents
* @brief Maps content ids (e.g. inodes) to the contents
*
*/
unordered_map<string, Item*> contents;
Expand Down Expand Up @@ -240,9 +240,9 @@ class Cache {
* @param owner the content id
* @param only_sync_data only sync data from content
* @param orig_path original path to write data
* @return int true if item was removed
* @return bool true if data was synced
*/
int sync_owner (string owner, bool only_sync_data, char* orig_path);
bool sync_owner (string owner, bool only_sync_data, char* orig_path);

/**
* @brief Renames an item id
Expand Down Expand Up @@ -282,10 +282,10 @@ class Cache {
* @param owner the content id
* @param path original path name
* @param parts parts from file that will be removed
* @return int true if item was removed
* @return bool true if parts were synced
*
*/
int partial_file_sync (string owner, char* path, string parts);
bool partial_file_sync (string owner, char* path, string parts);

/**
* @brief Gets the list of files that have unsynced data, mapped to
Expand Down Expand Up @@ -320,6 +320,14 @@ class Cache {
* @return vector<string> files mapped to that inode
*/
vector<string> find_files_mapped_to_inode (string inode);

/**
* @brief Retrieves a list of unsynced inodes.
*
* @return std::vector<std::string> A vector of unsynced inodes.
*/
vector<string> unsynced_inodes();

};

} // namespace cache
Expand Down
8 changes: 7 additions & 1 deletion libs/libpcache/include/faults/faults.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ class SyncPageF : public Fault {
*/
bool ret;

/**
* @brief True if we want to fsync other files.
*/
bool sync_other_files;

/**
* @brief Constructor for Fault.
*
Expand All @@ -352,8 +357,9 @@ class SyncPageF : public Fault {
* @param crash If the fault is a crash fault.
* @param pages Pages to clear.
* @param ret If the current system call is finished before crashing.
* @param sync_other_files If we want to fsync other files.
*/
SyncPageF(string timing, string op, string from, string to, int occurrence, string pages, bool ret);
SyncPageF(string timing, string op, string from, string to, int occurrence, string pages, bool ret, bool fsync_other_files = true);

~SyncPageF ();

Expand Down
27 changes: 22 additions & 5 deletions libs/libpcache/src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ bool Cache::truncate_item (string owner, off_t new_size) {
return true;
}

int Cache::sync_owner (string owner, bool only_sync_data, char* orig_path) {
bool Cache::sync_owner (string owner, bool only_sync_data, char* orig_path) {

std::unique_lock<shared_mutex> lock (lock_cache_mtx, std::defer_lock);
lock.lock ();
Expand All @@ -373,7 +373,10 @@ int Cache::sync_owner (string owner, bool only_sync_data, char* orig_path) {
off_t last_size = get_content_metadata (owner)->size;

res = this->engine->sync_pages (owner, last_size, orig_path);
_get_content_ptr (owner)->set_data_sync_flag (true);
if (res)
_get_content_ptr (owner)->set_data_sync_flag (true);
else
spdlog::warn ("[cache] sync_pages failed");

if (not only_sync_data) {

Expand Down Expand Up @@ -560,18 +563,17 @@ void Cache::full_checkpoint () {
this->sync_owner (it.second, false, (char*)it.first.c_str ());
}

int Cache::partial_file_sync (string owner, char* path, string parts) {
bool Cache::partial_file_sync (string owner, char* path, string parts) {

string inode = get_original_inode (owner);
off_t last_size = get_content_metadata (inode)->size;

//spdlog::info ("[CACHE]: partial file sync for inode: {} path: {} parts: {}", inode, path, parts);

int res = this->engine->partial_sync_pages (inode, last_size, path, parts);
bool res = this->engine->partial_sync_pages (inode, last_size, path, parts);

if (this->engine->is_owner_synced (inode)) {
_get_content_ptr (inode)->set_data_sync_flag (true);
cout << "SYNCED" << endl;
}

return res;
Expand Down Expand Up @@ -608,4 +610,19 @@ vector<string> Cache::find_files_mapped_to_inode (string inode) {
return res;
}

vector<string> Cache::unsynced_inodes() {

std::lock_guard<shared_mutex> lock (lock_cache_mtx);

vector<string> res;

for (auto const& it : this->contents) {
if (not it.second->is_synced ()) {
res.push_back (it.first);
}
}

return res;
}

} // namespace cache
22 changes: 17 additions & 5 deletions libs/libpcache/src/engine/backends/custom/custom_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ void CustomCacheEngine::make_block_readable_to_offset (string cid,
bool CustomCacheEngine::sync_pages (string owner, off_t size, char* orig_path) {

std::unique_lock<std::shared_mutex> lock (lock_cache_mtx);
bool res = true;

int fd = open (orig_path, O_WRONLY);

Expand Down Expand Up @@ -545,6 +546,11 @@ bool CustomCacheEngine::sync_pages (string owner, off_t size, char* orig_path) {
}

wrote_bytes += pwritev (fd, iov, page_streak, page_streak_last_offset);

if (wrote_bytes < 0) {
spdlog::warn ("[cache] pwritev of partial sync failed");
res = false;
}

page_streak = 0;

Expand All @@ -556,18 +562,19 @@ bool CustomCacheEngine::sync_pages (string owner, off_t size, char* orig_path) {
}

if (ftruncate (fd, size) < 0) {
spdlog::info ("ftruncate: failed");
spdlog::warn ("ftruncate: failed");
}

close (fd);

return 0;
return res;
}

bool CustomCacheEngine::partial_sync_pages (string owner, off_t last_size, char* orig_path, string parts) {

std::unique_lock<std::shared_mutex> lock (lock_cache_mtx);

bool res = true;
int fd = open (orig_path, O_WRONLY);

if (this->owner_pages_mapping.find (owner) != this->owner_pages_mapping.end ()) {
Expand Down Expand Up @@ -680,6 +687,11 @@ bool CustomCacheEngine::partial_sync_pages (string owner, off_t last_size, char*

wrote_bytes += pwritev (fd, iov, page_streak, page_streak_last_offset);

if (wrote_bytes < 0) {
spdlog::warn ("[cache] pwritev of partial sync failed");
res = false;
}

page_streak = 0;

page_chunk.clear ();
Expand All @@ -690,12 +702,12 @@ bool CustomCacheEngine::partial_sync_pages (string owner, off_t last_size, char*
}

if (ftruncate (fd, last_size) < 0) {
spdlog::info ("ftruncate: failed");
spdlog::warn ("[cache] ftruncate of partial sync failed");
}

close (fd);

return 0;
return res;
}

bool CustomCacheEngine::is_owner_synced (string owner) {
Expand Down Expand Up @@ -827,4 +839,4 @@ vector<tuple<int, pair<int, int>, int>> CustomCacheEngine::get_dirty_blocks_info
return res;
}

} // namespace cache::engine::backends::custom
} // namespace cache::engine::backends::custom
4 changes: 3 additions & 1 deletion libs/libpcache/src/faults.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void ClearF::pretty_print() const {


// Clear page Fault
SyncPageF::SyncPageF (string timing, string op, string from, string to, int occurrence, string pages, bool ret) : Fault(CLEAR) {
SyncPageF::SyncPageF (string timing, string op, string from, string to, int occurrence, string pages, bool ret, bool sync_other_files) : Fault(CLEAR) {
this->timing = timing;
this->op = op;
this->from = from;
Expand All @@ -231,6 +231,7 @@ SyncPageF::SyncPageF (string timing, string op, string from, string to, int occu
this->pages = pages;
(this->counter).store(0);
this->ret = ret;
this->sync_other_files = sync_other_files;
}

SyncPageF::~SyncPageF(){}
Expand Down Expand Up @@ -275,6 +276,7 @@ void SyncPageF::pretty_print() const {
cout << " Occurrence: " << this->occurrence << endl;
cout << " Pages: " << this->pages << endl;
cout << " Return: " << (this->ret ? "true" : "false") << endl;
cout << " Sync other files: " << (this->sync_other_files ? "true" : "false") << endl;
}

// namespace faults
Expand Down

0 comments on commit af8020e

Please sign in to comment.