Unverified Commit 029304d8 authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

turbo-persistence: skip random advice for hot bottom SSTs

Co-authored-by: 's avatarTobias Koppers <1365881+sokra@users.noreply.github.com>
parent fb20d9af
...@@ -1308,6 +1308,7 @@ fn bench_static_sorted_file_lookup(c: &mut Criterion) { ...@@ -1308,6 +1308,7 @@ fn bench_static_sorted_file_lookup(c: &mut Criterion) {
sst_meta, sst_meta,
Compression::Lz4, Compression::Lz4,
turbo_persistence::AccessMode::Mmap, turbo_persistence::AccessMode::Mmap,
true,
) )
.unwrap(); .unwrap();
......
...@@ -1387,7 +1387,7 @@ impl<S: ParallelScheduler, const FAMILIES: usize> TurboPersistence<S, FAMILIES> ...@@ -1387,7 +1387,7 @@ impl<S: ParallelScheduler, const FAMILIES: usize> TurboPersistence<S, FAMILIES>
// Free block caches and SST mmaps before compaction. The block caches // Free block caches and SST mmaps before compaction. The block caches
// are not used during compaction (we iterate uncached), and any cached // are not used during compaction (we iterate uncached), and any cached
// SST mmaps would use MADV_RANDOM which is wrong for sequential scans. // SST mmaps would mostly use MADV_RANDOM which is wrong for sequential scans.
// Clearing them upfront frees memory for the merge work. // Clearing them upfront frees memory for the merge work.
self.clear_cache(); self.clear_cache();
......
...@@ -187,6 +187,8 @@ impl MetaEntry { ...@@ -187,6 +187,8 @@ impl MetaEntry {
self.sst_data, self.sst_data,
self.compression, self.compression,
meta.access_mode, meta.access_mode,
// Warm (hot bottom) files keep the default readahead.
!(self.flags.bottom() && !self.flags.cold()),
) )
.with_context(|| { .with_context(|| {
format!( format!(
......
...@@ -444,11 +444,20 @@ impl StaticSortedFile { ...@@ -444,11 +444,20 @@ impl StaticSortedFile {
/// ///
/// Only the index block is read here, and its CRC is verified. Key and value blocks stay /// Only the index block is read here, and its CRC is verified. Key and value blocks stay
/// lazy, read on demand. /// lazy, read on demand.
///
/// `random_access_advice` applies `MADV_RANDOM` to the whole mmap (disabling kernel
/// readahead). Pass `false` for warm files (hot bottom files) to keep the default readahead.
/// It has no effect for [`AccessMode::File`] or on non-unix platforms.
#[cfg_attr(
not(all(feature = "mmap", unix)),
allow(unused_variables, reason = "only used for mmap advice on unix")
)]
pub fn open( pub fn open(
db_path: &Path, db_path: &Path,
meta: StaticSortedFileMetaData, meta: StaticSortedFileMetaData,
compression: Compression, compression: Compression,
access_mode: AccessMode, access_mode: AccessMode,
random_access_advice: bool,
) -> Result<Self> { ) -> Result<Self> {
let filename = format!("{:08}.sst", meta.sequence_number); let filename = format!("{:08}.sst", meta.sequence_number);
let path = db_path.join(&filename); let path = db_path.join(&filename);
...@@ -465,7 +474,9 @@ impl StaticSortedFile { ...@@ -465,7 +474,9 @@ impl StaticSortedFile {
})?; })?;
#[cfg(unix)] #[cfg(unix)]
{ {
mmap.advise(memmap2::Advice::Random)?; if random_access_advice {
mmap.advise(memmap2::Advice::Random)?;
}
let offset = meta.block_offsets_start(mmap.len()); let offset = meta.block_offsets_start(mmap.len());
let _ = let _ =
mmap.advise_range(memmap2::Advice::Sequential, offset, mmap.len() - offset); mmap.advise_range(memmap2::Advice::Sequential, offset, mmap.len() - offset);
......
...@@ -1612,6 +1612,7 @@ mod tests { ...@@ -1612,6 +1612,7 @@ mod tests {
}, },
Compression::Lz4, Compression::Lz4,
crate::mmap_access_mode(), crate::mmap_access_mode(),
true,
) )
} }
...@@ -2013,6 +2014,7 @@ mod tests { ...@@ -2013,6 +2014,7 @@ mod tests {
}, },
Compression::Lz4, Compression::Lz4,
crate::mmap_access_mode(), crate::mmap_access_mode(),
true,
)?; )?;
let sst2 = StaticSortedFile::open( let sst2 = StaticSortedFile::open(
dir.path(), dir.path(),
...@@ -2022,6 +2024,8 @@ mod tests { ...@@ -2022,6 +2024,8 @@ mod tests {
}, },
Compression::Lz4, Compression::Lz4,
crate::mmap_access_mode(), crate::mmap_access_mode(),
// Exercise opening without the random access advice too.
false,
)?; )?;
let kc = make_cache(); let kc = make_cache();
let vc = make_cache(); let vc = make_cache();
......
...@@ -589,6 +589,7 @@ impl<'db, K: StoreKey + Send + Sync, S: ParallelScheduler, const FAMILIES: usize ...@@ -589,6 +589,7 @@ impl<'db, K: StoreKey + Send + Sync, S: ParallelScheduler, const FAMILIES: usize
}, },
self.family_configs[usize_from_u32(family)].compression, self.family_configs[usize_from_u32(family)].compression,
crate::mmap_access_mode(), crate::mmap_access_mode(),
true,
)?; )?;
let cache2 = BlockCache::with( let cache2 = BlockCache::with(
10, 10,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment