From 4924b6e51b30df10073a278573cd7e1fb2de5607 Mon Sep 17 00:00:00 2001 From: hyi Date: Tue, 3 May 2022 12:49:40 +0000 Subject: [PATCH] up --- runtime/Cargo.toml | 2 +- runtime/src/snapshot_utils.rs | 33 ++++++++++----------------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index db121fa529ef87..76d0606d04ab72 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -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] diff --git a/runtime/src/snapshot_utils.rs b/runtime/src/snapshot_utils.rs index bd6732cf41b9d0..826dc2a56f7f0c 100644 --- a/runtime/src/snapshot_utils.rs +++ b/runtime/src/snapshot_utils.rs @@ -1512,28 +1512,11 @@ fn untar_snapshot_in>( archive_format: ArchiveFormat, parallel_divisions: usize, ) -> Result { - // 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 @@ -1544,7 +1527,11 @@ fn untar_snapshot_in>( 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(