Skip to content

Commit

Permalink
Flushes hash cache data file's mmap after done writing (#2567)
Browse files Browse the repository at this point in the history
(cherry picked from commit 65f6466)
  • Loading branch information
brooksprumo authored and mergify[bot] committed Aug 13, 2024
1 parent 35389e6 commit 870875e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 9 additions & 2 deletions accounts-db/src/cache_hash_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
crate::{accounts_hash::CalculateHashIntermediate, cache_hash_data_stats::CacheHashDataStats},
bytemuck_derive::{Pod, Zeroable},
memmap2::MmapMut,
solana_measure::measure::Measure,
solana_measure::{measure::Measure, measure_us},
solana_sdk::clock::Slot,
std::{
collections::HashSet,
Expand Down Expand Up @@ -371,10 +371,17 @@ impl CacheHashData {
});
assert_eq!(i, entries);
m2.stop();
// We must flush the mmap after writing, since we're about to turn around and load it for
// reading *not* via the mmap. If the mmap is never flushed to disk, it is possible the
// entries will *not* be visible when the reader comes along.
let (_, measure_flush_us) = measure_us!(cache_file.mmap.flush()?);
m.stop();
self.stats
.write_to_mmap_us
.fetch_add(m2.as_us(), Ordering::Relaxed);
m.stop();
self.stats
.flush_mmap_us
.fetch_add(measure_flush_us, Ordering::Relaxed);
self.stats.save_us.fetch_add(m.as_us(), Ordering::Relaxed);
self.stats.saved_to_cache.fetch_add(1, Ordering::Relaxed);
Ok(())
Expand Down
6 changes: 6 additions & 0 deletions accounts-db/src/cache_hash_data_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub struct CacheHashDataStats {
pub save_us: AtomicU64,
pub saved_to_cache: AtomicUsize,
pub write_to_mmap_us: AtomicU64,
pub flush_mmap_us: AtomicU64,
pub create_save_us: AtomicU64,
pub load_us: AtomicU64,
pub read_us: AtomicU64,
Expand Down Expand Up @@ -61,6 +62,11 @@ impl CacheHashDataStats {
self.write_to_mmap_us.load(Ordering::Relaxed),
i64
),
(
"flush_mmap_us",
self.flush_mmap_us.load(Ordering::Relaxed),
i64
),
(
"create_save_us",
self.create_save_us.load(Ordering::Relaxed),
Expand Down

0 comments on commit 870875e

Please sign in to comment.