diff --git a/Cargo.lock b/Cargo.lock index 7ab9378853..70fc9aebc8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4262,6 +4262,7 @@ dependencies = [ "consumption_metrics", "crc32c", "criterion", + "dashmap 6.1.0", "either", "enum-map", "enumset", diff --git a/Cargo.toml b/Cargo.toml index 9d7904a787..3a3716a08a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,6 +85,7 @@ clashmap = { version = "1.0", features = ["raw-api"] } comfy-table = "7.1" const_format = "0.2" crc32c = "0.6" +dashmap = "6.1" diatomic-waker = { version = "0.2.3" } either = "1.8" enum-map = "2.4.2" diff --git a/pageserver/Cargo.toml b/pageserver/Cargo.toml index 5c5bab0642..10ec455715 100644 --- a/pageserver/Cargo.toml +++ b/pageserver/Cargo.toml @@ -27,6 +27,7 @@ chrono = { workspace = true, features = ["serde"] } clap = { workspace = true, features = ["string"] } consumption_metrics.workspace = true crc32c.workspace = true +dashmap.workspace = true either.workspace = true fail.workspace = true futures.workspace = true diff --git a/pageserver/src/page_cache.rs b/pageserver/src/page_cache.rs index 90db5291b9..3522e17134 100644 --- a/pageserver/src/page_cache.rs +++ b/pageserver/src/page_cache.rs @@ -67,8 +67,8 @@ //! mapping is automatically removed and the slot is marked free. //! -use std::collections::HashMap; -use std::collections::hash_map::Entry; +use dashmap::DashMap; +use dashmap::Entry; use std::sync::atomic::{AtomicU8, AtomicU64, AtomicUsize, Ordering}; use std::sync::{Arc, Weak}; use std::time::Duration; @@ -194,7 +194,7 @@ impl SlotInner { } pub struct PageCache { - immutable_page_map: std::sync::RwLock>, + immutable_page_map: std::sync::Arc::>, /// The actual buffers with their metadata. slots: Box<[Slot]>, @@ -483,8 +483,7 @@ impl PageCache { fn search_mapping(&self, cache_key: &CacheKey) -> Option { match cache_key { CacheKey::ImmutableFilePage { file_id, blkno } => { - let map = self.immutable_page_map.read().unwrap(); - Some(*map.get(&(*file_id, *blkno))?) + Some(*self.immutable_page_map.get(&(*file_id, *blkno))?) } } } @@ -495,8 +494,7 @@ impl PageCache { fn remove_mapping(&self, old_key: &CacheKey) { match old_key { CacheKey::ImmutableFilePage { file_id, blkno } => { - let mut map = self.immutable_page_map.write().unwrap(); - map.remove(&(*file_id, *blkno)) + self.immutable_page_map.remove(&(*file_id, *blkno)) .expect("could not find old key in mapping"); } } @@ -510,8 +508,7 @@ impl PageCache { fn try_insert_mapping(&self, new_key: &CacheKey, slot_idx: usize) -> Option { match new_key { CacheKey::ImmutableFilePage { file_id, blkno } => { - let mut map = self.immutable_page_map.write().unwrap(); - match map.entry((*file_id, *blkno)) { + match self.immutable_page_map.entry((*file_id, *blkno)) { Entry::Occupied(entry) => Some(*entry.get()), Entry::Vacant(entry) => { entry.insert(slot_idx);