Expand description
Names the operation behind large or bursty heap use in the daemon.
The aft binary installs TracingAllocator as its global allocator. It
forwards every call to the process allocator and watches two things:
- One allocation or reallocation of
LARGE_ALLOCATION_BYTESor more records an event: its size, the old size for a reallocation, the thread, the current operation label and the caller’s return addresses. - Allocations made while an operation label is set (see
scope) add to that label’s live bytes, and frees made under the same label subtract from them. When one label’s live bytes crossLABEL_BURST_BYTESan event is recorded, and another when they fall back below half of it. A label’s count starts again from zero whenever no scope of it is open, so memory an operation hands to someone else does not pile up on it over the daemon’s life.
The allocator never allocates, locks or logs on behalf of a caller. Its
common path is a thread-local add; every FLUSH_QUANTUM_BYTES of net
change it adds the thread’s share to the label’s shared counter with a
relaxed atomic. Events go into a fixed ring that a logger thread drains,
names and writes as WARN lines (see report).
Only Rust heap allocations pass through a global allocator. Memory that C
libraries (SQLite, tree-sitter, ONNX Runtime) take from malloc directly
is not seen here.
Re-exports§
pub use report::drain_now;pub use report::start_logger;
Structs§
- Carry
- The current thread’s label and root, to carry into work handed to a pool.
- Label
- An operation the allocator attributes live bytes to.
- Label
Peak - One label’s high-water mark for the memory census.
- Labelled
- A future whose polls run under a label; see
future. - Root
Name - The repository an operation works on, kept inline so that the allocator can copy it into an event without allocating: the last component of the root path, cut to fit.
- Scope
Guard - While alive, allocations on this thread are attributed to its label. Dropping it restores the label and root that were current before.
- Tracing
Allocator - The global allocator wrapper the
aftbinary installs. It forwards to jemalloc on Linux and the system allocator elsewhere, then reports each call.
Constants§
- FLUSH_
QUANTUM_ BYTES - A thread hands its pending bytes to the label’s shared counter whenever they move this far from zero, so the shared counter lags each thread by less than this.
- LABEL_
BURST_ BYTES - One label’s live bytes crossing this records a burst event.
- LARGE_
ALLOCATION_ BYTES - A single allocation at least this large is recorded with its backtrace.
Functions§
- carry
- Captures the current label and root for a pool task; see
Carry::enter. - drain_
now - Writes every queued event now, on the calling thread.
- future
inner, with every poll run underlabel. For async work, where aScopeGuardcannot be held across an await: the label is open from the first poll until the future is dropped.- install
pool.install(op), withoprun under the caller’s label. Parallel iterators insideopcarry it further withCarry::each.- scope
- Attributes this thread’s allocations to
labeluntil the guard drops. With aroot, events name that repository; without one the current root, if any, stays. - start_
logger - Starts the logger thread once. Events recorded before it starts wait in the ring, which keeps the most recent ones that fit.
- take_
census_ peaks - The
limitlabels with the highest live bytes since the previous call, highest first; each label’s mark then restarts from its current count. Labels that never held a byte are left out. Empty unless the logger runs, which only theaftbinary starts: without the tracer installed nothing counts real allocations, and unit tests that drive the hooks by hand must not leak their labels into other tests’ census.