pub struct KernelCacheConfig {
pub capacity: usize,
pub max_total_bytes: Option<u64>,
pub verify_on_get: bool,
pub registry: Option<Arc<dyn KernelRegistry>>,
}Expand description
Construction-time configuration for KernelCache.
Holds the small set of policy knobs the cache supports today: capacity
(count cap) and whether to recompute the per-entry BLAKE3 integrity
hash on every get. Future knobs (per-byte cap, eviction policy
choice) will land here without breaking the existing
KernelCache::with_capacity / KernelCache::with_disk_persistence
shorthands — those construct an equivalent KernelCacheConfig under
the hood.
Construct via KernelCacheConfig::default (which mirrors the
historical defaults — capacity DEFAULT_CAPACITY, verify-on-get
true) and refine with the with_* builders, then hand the config
to KernelCache::with_config.
Fields§
§capacity: usizeSoft maximum L1 entry count. Clamped to >= 1 inside the cache.
max_total_bytes: Option<u64>Optional soft maximum on the total bytes of cached PTX text held
in L1, summed across every live entry (each entry contributes
cached.ptx.text.len()). When Some(cap), KernelCache::put
evicts LRU entries — using the same eviction queue the count cap
drives — until the running byte total fits under cap, after
admitting the new entry. The count cap (Self::capacity) still
applies independently; whichever cap binds first wins.
Why this exists: the count cap alone is a DoS vector. A 256-slot
cache fed adversarial multi-MB PTX blueprints (a deliberately
unrolled kernel can emit 10 MB of PTX) reaches ~2.5 GB of resident
L1 — see the memory-ceiling note on DEFAULT_CAPACITY. The byte
cap bounds the worst case regardless of per-entry size.
A single entry larger than cap is still admitted (the cache never
refuses an insert outright — it would otherwise wedge the dispatch
path) but it will evict every other entry first; the byte total may
transiently exceed cap by at most one such oversized entry.
Default None (preserves the historical count-only behaviour). Set
via Self::with_max_total_bytes. Track the live total via
KernelCache::total_bytes.
verify_on_get: boolWhen true (the default), KernelCache::get recomputes a
BLAKE3 over the cached ptx.text on every L1 hit and compares
the result against the entry’s stored integrity_hash (jit S-3
in-mem poisoning defence). When false, the recompute is skipped
— the cache still refuses entries whose stored hash is all-zero
(the construction signal for “built without CachedKernel::new”)
as defence-in-depth.
The recompute costs ~10 µs over a typical multi-KB PTX blob;
skipping it shaves that off every L1 hit at the cost of widening
the in-memory poisoning window from “one get call” to “the
lifetime of the entry in L1”. Operators on a high-QPS path with
multi-MB PTX where the recompute dominates can opt out, but the
safe default is verify-on-get.
registry: Option<Arc<dyn KernelRegistry>>Optional registry consulted on L1+L2 miss. v0.4 path: caller resolves
(tenant, blueprint, sm_version) → (name, version) via an external
lookup, then KernelCache::get_with_registry_fallback consults the
registry by that pair. v0.3.8 ships a resolve_by_blueprint_hint
trait method on the cache config for the resolver step; the
in-memory test impl resolves blueprint fingerprint → name@version
directly via a HashMap.
Implementations§
Source§impl KernelCacheConfig
impl KernelCacheConfig
Sourcepub fn with_capacity(self, capacity: usize) -> Self
pub fn with_capacity(self, capacity: usize) -> Self
Override the L1 entry count cap. Clamped to >= 1 at cache
construction time; values below 1 are silently raised.
Sourcepub fn with_max_total_bytes(self, max_total_bytes: u64) -> Self
pub fn with_max_total_bytes(self, max_total_bytes: u64) -> Self
Set the soft total-bytes cap on resident L1 PTX. None (the
default) preserves the historical count-only behaviour; Some(cap)
makes KernelCache::put evict LRU entries until the running PTX
byte total fits under cap. See the field-level docs on
Self::max_total_bytes for the DoS-mitigation rationale and the
single-oversized-entry caveat.
Sourcepub fn with_verify_on_get(self, on: bool) -> Self
pub fn with_verify_on_get(self, on: bool) -> Self
Toggle the per-get BLAKE3 recompute. Default true; setting
false is the high-QPS opt-out. See the field-level docs on
Self::verify_on_get for the threat-model trade-off.
Sourcepub fn with_registry(self, reg: Arc<dyn KernelRegistry>) -> Self
pub fn with_registry(self, reg: Arc<dyn KernelRegistry>) -> Self
Attach a KernelRegistry as the L3 fallback consulted by
KernelCache::get_with_registry_fallback on an L1+L2 miss.
Default is None (registry path disabled). See the field-level
docs on Self::registry for the resolution contract.
Trait Implementations§
Source§impl Clone for KernelCacheConfig
impl Clone for KernelCacheConfig
Source§fn clone(&self) -> KernelCacheConfig
fn clone(&self) -> KernelCacheConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for KernelCacheConfig
impl Debug for KernelCacheConfig
Auto Trait Implementations§
impl !RefUnwindSafe for KernelCacheConfig
impl !UnwindSafe for KernelCacheConfig
impl Freeze for KernelCacheConfig
impl Send for KernelCacheConfig
impl Sync for KernelCacheConfig
impl Unpin for KernelCacheConfig
impl UnsafeUnpin for KernelCacheConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more