pub struct Segment {
pub next: *mut Segment,
pub owner: usize,
pub foreign: AtomicPtr<u8>,
pub foreign_bytes: AtomicUsize,
pub foreign_live: AtomicUsize,
pub spans: [SpanMeta; 64],
/* private fields */
}Expand description
The header at the base of every segment.
Fields§
§next: *mut SegmentIntrusive list of a heap’s segments — an allocator cannot use a
Vec to track its own memory without recursing into itself.
owner: usizeThe shard that owns every span here. Foreign frees find their way home through this.
foreign: AtomicPtr<u8>Slots freed by a thread other than the owner, as a lock-free
stack of slot addresses. See [push_foreign] for why this is
push-only.
foreign_bytes: AtomicUsizeSlot bytes parked on foreign, so the accounting can price the
list without walking it. Bytes rather than a count: one list
carries slots of several classes, so a count cannot be converted
back.
AtomicUsize rather than AtomicU64 because 32-bit targets
(Cortex-M among them) have no 64-bit atomic, and a pending
foreign-free list cannot exceed the address space anyway.
foreign_live: AtomicUsizeOf those, the bytes callers actually asked for.
The owner’s live/rounding counters still include everything on
this list, because the thread that freed it cannot touch another
thread’s counters. Snapshots move the amount across so it is
counted once — see Heap::snapshot.
spans: [SpanMeta; 64]Per-span bookkeeping, indexed by span number. Index 0 describes the header span itself and is never assigned a class.
Implementations§
Source§impl Segment
impl Segment
Sourcepub unsafe fn init(base: NonNull<u8>, owner: usize) -> NonNull<Segment>
pub unsafe fn init(base: NonNull<u8>, owner: usize) -> NonNull<Segment>
Initialise a freshly mapped segment in place.
§Safety
base must be a live, writable, 4 MiB-aligned mapping of
SEGMENT_BYTES bytes that nothing else references.