Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed May 3, 2022
1 parent 08b6a9e commit 4924b6e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ zstd = "0.11.1"
crate-type = ["lib"]
name = "solana_runtime"

[target."cfg(linux)".dependencies]
[target.'cfg(unix)'.dependencies]
mmarinus = "0.4.0"

[dev-dependencies]
Expand Down
33 changes: 10 additions & 23 deletions runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1512,28 +1512,11 @@ fn untar_snapshot_in<P: AsRef<Path>>(
archive_format: ArchiveFormat,
parallel_divisions: usize,
) -> Result<UnpackedAppendVecMap> {
// use memmap2::Mmap;
// let file = File::open(&snapshot_tar).unwrap();

// // Map the file into immutable memory for better I/O performance
// let mmap = unsafe { Mmap::map(&file) };
// let mmap = mmap.unwrap_or_else(|e| {
// error!(
// "Failed to map the snapshot file: {} {}.\n
// Please increase the virtual memory on the system.",
// snapshot_tar.as_ref().display(),
// e,
// );
// std::process::exit(1);
// });

// // The following code is safe because the lifetime of mmap last till the end of the function
// // while the usage of mmap, BufReader's lifetime only last within fn unpack_snapshot_local.
// let len = &mmap[..].len();
// let ptr = &mmap[0] as *const u8;
// let slice = unsafe { slice::from_raw_parts(ptr, *len) };

use mmarinus::{perms, Map, Private};
use {
mmarinus::{perms, Map, Private},
std::slice
};

let mmap = Map::load(&snapshot_tar, Private, perms::Read).unwrap_or_else(|e| {
error!(
"Failed to map the snapshot file: {} {}.\n
Expand All @@ -1544,7 +1527,11 @@ fn untar_snapshot_in<P: AsRef<Path>>(
std::process::exit(1);
});

let slice = mmap;
// The following code is safe because the lifetime of mmap last till the end of the function
// while the usage of mmap, BufReader's lifetime only last within fn unpack_snapshot_local.
let len = &mmap[..].len();
let ptr = &mmap[0] as *const u8;
let slice = unsafe { slice::from_raw_parts(ptr, *len) };

let account_paths_map = match archive_format {
ArchiveFormat::TarBzip2 => unpack_snapshot_local(
Expand Down

0 comments on commit 4924b6e

Please sign in to comment.