apache / apache/teaclave-sgx-sdk

Wrong cache eviction order in branch v2.0.0-preview

Open
#461 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
1.2k
Forks
268
PR merge metrics
No merged PRs in 30d

Description

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:
```Rust
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| {
// ...
}
// ...
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in the v2.0.0-preview Rust pfs implementation at write_to_disk and trace the cache iteration used when dirty nodes are evicted. Confirm that eviction writes nodes in the order needed for sequential file blocks, then verify the resulting behavior with the available pfs checks or a focused sequential-write test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.