#[non_exhaustive]pub struct HostHeapState {
pub active_bytes: Option<u64>,
pub allocated_bytes: Option<u64>,
pub resident_bytes: Option<u64>,
pub mapped_bytes: Option<u64>,
pub narenas: Option<usize>,
}Expand description
Heap-state snapshot for the running process’s jemalloc allocator.
Every field is Option<u64> (or Option<usize> for the arena
count) so a partial read lands what succeeded and consumers can
distinguish “jemalloc reported X” from “jemalloc did not report
this field”. The Default impl lands every field as None,
matching the non-jemalloc fallback path and serving as the
fixture for test call sites that want the empty shape.
§Constructing instances in tests
HostHeapState is #[non_exhaustive] — see
[crate::non_exhaustive] for the cross-crate construction and
pattern-match rules. Start from HostHeapState::test_fixture
(populated baseline) or HostHeapState::default (all-None)
and mutate fields.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.active_bytes: Option<u64>stats.active — bytes in active pages allocated by the
application. A multiple of the page size and >=
Self::allocated_bytes. Populated whenever libjemalloc
was built with --enable-stats (the stats feature on
tikv-jemalloc-ctl forces this). Some(0) when jemalloc
is linked but is not #[global_allocator] — the whole
HostHeapState collapses to None at the HostContext
call site in that case (see module doc).
allocated_bytes: Option<u64>stats.allocated — total bytes allocated by the
application (sum of live allocations, excluding allocator
metadata and padding). Some(0) when jemalloc is linked
but not installed as #[global_allocator].
resident_bytes: Option<u64>stats.resident — bytes in physically resident data pages
mapped by the allocator. Overestimates by including
demand-zeroed pages that have not been touched; jemalloc
documents this. A multiple of the page size and >=
Self::active_bytes. Reflects jemalloc’s own metadata
footprint even when jemalloc is not #[global_allocator].
mapped_bytes: Option<u64>stats.mapped — bytes in active extents mapped by the
allocator. Excludes inactive extents even those with
unused dirty pages, so there is no strict ordering between
this and Self::resident_bytes. A multiple of the page
size and >= Self::active_bytes. Reflects jemalloc’s
own metadata footprint even when jemalloc is not
#[global_allocator].
narenas: Option<usize>arenas.narenas — current limit on the number of arenas.
Initialized at jemalloc startup (typically 4 * ncpus on a
multi-core Linux host) and updated as the allocator grows
new arenas. Populated whenever libjemalloc is linked into
the binary, including on consumers that use ktstr as a
library without opting into jemallocator as
#[global_allocator] (see the module doc). None only on
the rare mallctl-error path.
Implementations§
Source§impl HostHeapState
impl HostHeapState
Sourcepub fn test_fixture() -> HostHeapState
pub fn test_fixture() -> HostHeapState
Populated fixture for unit tests. Values are plausible for a
small ktstr run on a 16-CPU host: a few hundred KiB
allocated, rounded up to page-size multiples for active /
resident / mapped, and narenas = 64 (jemalloc’s
4 * ncpus default on a 16-CPU box).
Call sites mutate the fields they care about:
use ktstr::prelude::HostHeapState;
let mut h = HostHeapState::test_fixture();
h.allocated_bytes = Some(0);Sourcepub fn format_human(&self) -> String
pub fn format_human(&self) -> String
Render as a human-readable multi-line block. Each field is
one key: value line; absent fields render (unknown) so
operators see which reads failed. The block ends with a
newline. Matches HostContext::format_human’s
shape — pair the two in cargo ktstr show-host for a
single-block host summary.
Sourcepub fn diff(&self, other: &HostHeapState) -> String
pub fn diff(&self, other: &HostHeapState) -> String
Render a field-by-field diff as key: before → after lines.
Omits unchanged fields; an empty return means the two
snapshots are identical. None renders as (unknown) so a
None → Some(..) transition is visible.
Trait Implementations§
Source§impl Clone for HostHeapState
impl Clone for HostHeapState
Source§fn clone(&self) -> HostHeapState
fn clone(&self) -> HostHeapState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HostHeapState
impl Debug for HostHeapState
Source§impl Default for HostHeapState
impl Default for HostHeapState
Source§fn default() -> HostHeapState
fn default() -> HostHeapState
Source§impl<'de> Deserialize<'de> for HostHeapState
impl<'de> Deserialize<'de> for HostHeapState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for HostHeapState
impl PartialEq for HostHeapState
Source§impl Serialize for HostHeapState
impl Serialize for HostHeapState
impl Eq for HostHeapState
impl StructuralPartialEq for HostHeapState
Auto Trait Implementations§
impl Freeze for HostHeapState
impl RefUnwindSafe for HostHeapState
impl Send for HostHeapState
impl Sync for HostHeapState
impl Unpin for HostHeapState
impl UnwindSafe for HostHeapState
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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