Skip to main content

Module budget

Module budget 

Source
Expand description

Memory budgets: the mechanism in the core, the policy in the batch engine.

A budget is shared by many inputs (a batch’s admission pool, its dependency pool). The core never asks it directly: every charge an input’s crate::limits::Meter grants is also booked here, as a Permit that rides inside the charge, so the budget sees everything every input holds, and gets it back when the last owner drops it. The request never blocks: blocking inside a rayon pool can deadlock, so a batch engine does any waiting of its own before it hands work to the pool (plan section 4.1 lists what the core guarantees it).

A decoder writes through a DecodeBuf, which charges the input’s meter before every growth, so no decoded byte exists unpaid, a refused growth allocates nothing, and a dropped buffer (a failed decode) returns its charge.

Owner: the scaffold (implemented); package C maintains it.

Structs§

AllocError
A host allocator refusal, kept by value without a heap-owned source.
BudgetExceeded
A refused reservation.
Counting
A non-blocking budget with a fixed limit, counting what is alive.
DecodeBuf
A decoder’s output buffer that pays before it grows.
Permit
Bytes reserved from a budget, returned when the permit drops.
Unbounded
A budget that never refuses: UnityPy’s behaviour, and the default.

Enums§

Reservation
Which kind of load a charge belongs to, so a refusal says which pool refused (plan section 4.1).

Constants§

OWNER_COST
What wrapping a buffer in Bytes allocates besides the buffer: the shared owner record Bytes::from_owner boxes (the buffer, its charge and a reference count), with room to spare.

Traits§

MemoryBudget
A source of permits.
PermitHome
Where a permit returns its bytes. The same contract as MemoryBudget: called under core locks, so it must not block or call the core.

Functions§

charged_bytes
buf as Bytes that carry charge, which must already cover buf’s allocation: the owner record is charged first (OWNER_COST), and the whole charge returns when the last slice drops, whoever holds it.