Skip to content

Commit 1f0c8f4

Browse files
v2.0: Flushes hash cache data file's mmap after done writing (backport of #2567) (#2575)
Flushes hash cache data file's mmap after done writing (#2567) (cherry picked from commit 65f6466) Co-authored-by: Brooks <[email protected]>
1 parent f615f41 commit 1f0c8f4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

accounts-db/src/cache_hash_data.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use {
55
crate::{accounts_hash::CalculateHashIntermediate, cache_hash_data_stats::CacheHashDataStats},
66
bytemuck_derive::{Pod, Zeroable},
77
memmap2::MmapMut,
8-
solana_measure::measure::Measure,
8+
solana_measure::{measure::Measure, measure_us},
99
solana_sdk::clock::Slot,
1010
std::{
1111
collections::HashSet,
@@ -371,10 +371,17 @@ impl CacheHashData {
371371
});
372372
assert_eq!(i, entries);
373373
m2.stop();
374+
// We must flush the mmap after writing, since we're about to turn around and load it for
375+
// reading *not* via the mmap. If the mmap is never flushed to disk, it is possible the
376+
// entries will *not* be visible when the reader comes along.
377+
let (_, measure_flush_us) = measure_us!(cache_file.mmap.flush()?);
378+
m.stop();
374379
self.stats
375380
.write_to_mmap_us
376381
.fetch_add(m2.as_us(), Ordering::Relaxed);
377-
m.stop();
382+
self.stats
383+
.flush_mmap_us
384+
.fetch_add(measure_flush_us, Ordering::Relaxed);
378385
self.stats.save_us.fetch_add(m.as_us(), Ordering::Relaxed);
379386
self.stats.saved_to_cache.fetch_add(1, Ordering::Relaxed);
380387
Ok(())

accounts-db/src/cache_hash_data_stats.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct CacheHashDataStats {
1111
pub save_us: AtomicU64,
1212
pub saved_to_cache: AtomicUsize,
1313
pub write_to_mmap_us: AtomicU64,
14+
pub flush_mmap_us: AtomicU64,
1415
pub create_save_us: AtomicU64,
1516
pub load_us: AtomicU64,
1617
pub read_us: AtomicU64,
@@ -61,6 +62,11 @@ impl CacheHashDataStats {
6162
self.write_to_mmap_us.load(Ordering::Relaxed),
6263
i64
6364
),
65+
(
66+
"flush_mmap_us",
67+
self.flush_mmap_us.load(Ordering::Relaxed),
68+
i64
69+
),
6470
(
6571
"create_save_us",
6672
self.create_save_us.load(Ordering::Relaxed),

0 commit comments

Comments
 (0)