Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong cache eviction order in branch v2.0.0-preview #461

Open
Fischer0522 opened this issue Dec 4, 2024 · 0 comments
Open

Wrong cache eviction order in branch v2.0.0-preview #461

Fischer0522 opened this issue Dec 4, 2024 · 0 comments

Comments

@Fischer0522
Copy link

Fischer0522 commented Dec 4, 2024

sgx_protected_fs uses LRUCache to reduce the IO cost. When pfs needs a new node, it will create one and push it in front of the list. But when pfs needs to evict a node, it will call cache.iter() to get all nodes that are dirty, which will get node from front to end.

In the C++ version, the file protected by pfs is implemented by mmap, so the write will be handled by the page cache and it won't trigger a real IO action. So it's okay to evict nodes in a reverse order. But in branch v2.0.0-preview, this Rust SDK rewrites pfs in Rust. The node.write_to_disk() will directly write data to the file. So when we perform sequential writes on a file like block[1,2,3,4,5], the actual order is block[5,4,3,2,1], which is a random write, causing terrible performance.

so, we should use cache.iter().rev() or create a rev_iter as follow:

    pub fn write_to_disk(&mut self, flush: bool) -> FsResult {
        if self.is_need_write_node() {
            for mut node in self.cache.iter().rev().filter_map(|node| {
            // ...
        }
        // ...
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant