Skip to content

Commit 262316f

Browse files
authored
feat(storage-proofs): store MTs on disk by default (#836)
BREAKING CHANGE: We now store MTs on disk by default, this shouldn't have an impact on replication time but will increase disk usage considerably (roughly 20x the sector size). To store them on memory instead use the (new) `mem-trees` feature (that replaces the old, now removed, `disk-trees`).
1 parent 17f95d6 commit 262316f

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ jobs:
8080
cargo +stable test --verbose --release --all
8181
RUSTFLAGS="-D warnings" cargo +stable build --examples --release --all
8282
83-
test_disk_trees:
83+
test_mem_trees:
8484
docker:
8585
- image: filecoin/rust:latest
8686
working_directory: /mnt/crate
@@ -94,9 +94,9 @@ jobs:
9494
- cargo-v12-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
9595
- parameter-cache-{{ .Revision }}
9696
- run:
97-
name: Test (nightly) disk-trees feature
97+
name: Test (nightly) mem-trees feature
9898
command: |
99-
cargo +$(cat rust-toolchain) test --verbose --release -p storage-proofs --features disk-trees -Z package-features
99+
cargo +$(cat rust-toolchain) test --verbose --release -p storage-proofs --features mem-trees -Z package-features
100100
environment:
101101
FIL_PROOFS_REPLICATED_TREES_DIR: replicated-disk-trees
102102

@@ -329,7 +329,7 @@ workflows:
329329
- test_release:
330330
requires:
331331
- cargo_fetch
332-
- test_disk_trees:
332+
- test_mem_trees:
333333
requires:
334334
- cargo_fetch
335335
- test_ignored_release:

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,24 @@ To check that it's working you can inspect the replication log to find `using pa
159159

160160
(You can also verify if the cache is working by inspecting the time each layer takes to encode, `encoding, layer:` in the log, where the first two layers, forward and reverse, will take more time than the rest to populate the cache while the remaining 8 should see a considerable time drop.)
161161

162-
### Memory
163-
164-
We try to generate the MTs in parallel to speed up the process but that takes 2 sector sizes per each layer (e.g., a 1 GiB sector may require, in the worst case scenario, up to 20 GiB of memory to hold the MTs alone). To reduce that (at the cost of speed) we have the (experimental) `disk-trees` feature to offload the MTs to disk when we don't use them. For example, to run the `zigzag` example with this feature you'd need to indicate so to `cargo`,
162+
In the most extreme case, to reduce time at the cost of *a lot* of memory consumption you can turn on the feature that stores MTs on memory (`mem-trees`) instead of on disk (the default) to generate them all on RAM and avoid disk I/O (if the HW doesn't have enough RAM to handle the MTs, roughly 20x the sector size, this won't have the desired effect as the OS will start backing them on disk anyway). For example, to run the `zigzag` example with this feature turned on you'd need to indicate so to `cargo`,
165163

166164
```
167-
# From inside the `storage-proofs` directory, where this feature
168-
# needs to be activated:
169-
cargo build \
165+
# NEEDS TO BE RUN INSIDE `storage-proofs\` directory
166+
# for the `--features` to take effect.
167+
cargo run \
170168
-p filecoin-proofs \
171169
--release \
172170
--example zigzag \
173171
--features \
174-
disk-trees &&
175-
../target/release/examples/zigzag \
172+
mem-trees \
173+
-- \
176174
--size 1048576
177175
```
178176

179-
This optimization should reduce the maximum RSS, in the `zigzag` example, to 1-2 times the sector size used (so in the above command that tested ZigZag with a 1 GiB sector the maximum RSS reported by commands like `/usr/bin/time -v` should not exceed 2 GiB, please submit an issue if you observe otherwise).
177+
### Memory
178+
179+
At the moment the default configuration is set to reduce memory consumption as much as possible so there's not much to do from the user side. (We are now storing MTs on disk, which were the main source of memory consumption.) You should expect a maximum RSS between 1-2 sector sizes, if you experience peaks beyond that range please report an issue (you can check the max RSS with the `/usr/bin/time -v` command).
180180

181181
## Generate Documentation
182182

storage-proofs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pretty_env_logger = "0.3.0"
5151
default = []
5252
simd = []
5353
asm = ["sha2/sha2-asm"]
54-
disk-trees = []
54+
mem-trees = []
5555
big-sector-sizes-bench = []
5656
unchecked-degrees = []
5757

storage-proofs/src/merkle.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,20 @@ use paired::bls12_381::Fr;
1111
use crate::hasher::{Domain, Hasher};
1212

1313
pub use merkletree::merkle::{next_pow2, populate_leaves, Store};
14-
pub type MmapStore<E> = merkletree::merkle::MmapStore<E>;
15-
pub type DiskStore<E> = merkletree::merkle::DiskStore<E>;
16-
#[cfg(feature = "disk-trees")]
14+
15+
#[cfg(not(feature = "mem-trees"))]
16+
type DiskStore<E> = merkletree::merkle::DiskStore<E>;
17+
#[cfg(not(feature = "mem-trees"))]
1718
pub type MerkleTree<T, A> = merkle::MerkleTree<T, A, DiskStore<T>>;
18-
#[cfg(not(feature = "disk-trees"))]
19-
pub type MerkleTree<T, A> = merkle::MerkleTree<T, A, MmapStore<T>>;
20-
#[cfg(feature = "disk-trees")]
19+
#[cfg(not(feature = "mem-trees"))]
2120
pub type MerkleStore<T> = DiskStore<T>;
22-
#[cfg(not(feature = "disk-trees"))]
23-
pub type MerkleStore<T> = MmapStore<T>;
21+
22+
#[cfg(feature = "mem-trees")]
23+
type VecStore<E> = merkletree::merkle::VecStore<E>;
24+
#[cfg(feature = "mem-trees")]
25+
pub type MerkleTree<T, A> = merkle::MerkleTree<T, A, VecStore<T>>;
26+
#[cfg(feature = "mem-trees")]
27+
pub type MerkleStore<T> = VecStore<T>;
2428

2529
/// Representation of a merkle proof.
2630
/// Each element in the `path` vector consists of a tuple `(hash, is_right)`, with `hash` being the the hash of the node at the current level and `is_right` a boolean indicating if the path is taking the right path.

0 commit comments

Comments
 (0)