~/bend-docscommunity

src/virtio/balauto.bend checks

raw source on the hub · import 0x2324e729258ea5021b37b97947af4c3f/src/virtio/balauto.bend as Balauto

2 imports
import Base
import ../lib/bytes.bend as B

Types

type Stats source · line 33 · raw

Data

Definitions

def Auto.none source · line 36 · raw

U32

def Auto.period_ms source · line 40 · raw

U32

def Auto.start_ms source · line 46 · raw

U32

The first poll waits this long after the VM starts: the balloon stays out of the guest's way while it boots and starts its work (inflating takes guest CPU: an upload in the guest's first seconds ran 19% slower).

def Auto.slack source · line 49 · raw

U32

def Auto.step source · line 53 · raw

U32

def Auto.band source · line 63 · raw

U32

Hysteresis: the balloon grows only when free memory is above the floor by more than Auto.slack() and Auto.band() more, and then leaves Auto.slack() free above the floor; it shrinks only below the floor. A guest whose free memory moves by tens of MiB (a busy Kubernetes control plane) no longer makes the balloon chase it: inflating and deflating every poll cost such a VM 20 points of host CPU.

def Auto.floor source · line 67 · raw

@+total:U32 -> U32

def Auto.most source · line 72 · raw

@+total:U32 -> U32

The most the balloon holds: half the guest's RAM.

def Auto.most_of source · line 78 · raw

@+total:U32 -> @+pct:U32 -> U32

The most the balloon holds, as pct percent of the guest's RAM (--balloon auto,max=PCT; 50 is Auto.most). total * pct / 100 without overflowing: a page count is below 2^32 and pct at most 100.

def Auto.pct_ok source · line 83 · raw

@+pct:U32 -> Bool

The percentages --balloon auto,max= takes: 10 to 90 (past 90 the guest's floor and its kernel's own memory no longer fit in some VMs).

def Auto.oom source · line 91 · raw

@+target:U32 -> @+actual:U32 -> U32

The guest took pages back on its own (VIRTIO_BALLOON_F_DEFLATE_ON_OOM: a deflate leaves the balloon holding less than its target): the target drops at once to Auto.step() below what the balloon holds, so the guest gets its memory in one go rather than one MiB a time until the next poll. Otherwise the target stays.

def Auto.pages source · line 95 · raw

@+lo:U32 -> @+hi:U32 -> U32

A byte count in pages, saturated at 2^32 - 1.

def Auto.entry source · line 98 · raw

@+tag:U32 -> @+v:U32 -> @+st:Stats -> Stats

def Auto.stats.go source · line 107 · raw

@fuel:Nat -> @+bs:List<&2, U32> -> @+st:Stats -> Stats

The statistics in a buffer's bytes (entries past the last whole one are ignored; a tag not given keeps its value from st).

def Auto.stats source · line 116 · raw

@+bs:List<&2, U32> -> @+st:Stats -> Stats

def Auto.fresh source · line 119 · raw

Stats

def Auto.grow source · line 122 · raw

@+free:U32 -> @+floor:U32 -> @+target:U32 -> @+most:U32 -> U32

def Auto.shrink source · line 125 · raw

@+free:U32 -> @+floor:U32 -> @+target:U32 -> U32

def Auto.target_at source · line 133 · raw

@+st:Stats -> @+target:U32 -> @+pct:U32 -> U32

The balloon's next target from the guest's statistics and the current one: its target, or what it holds when the guest took pages back (DEFLATE_ON_OOM) and it holds less (a guest that reported no total: unchanged).

def Auto.target source · line 142 · raw

@+st:Stats -> @+target:U32 -> U32

With the balloon holding at most half the guest's RAM (the default).

def Auto.later source · line 150 · raw

@+elapsed:U32 -> U32

The clock (host/main.bend: balloon_poll) ticks every Auto.period_ms() from the start. Each tick the host settles the guest RAM it wrote (macOS: Hvf.ram_settle, a page the VMM writes is charged twice until its mapping is replaced); once Auto.start_ms() passed, an automatic balloon also polls. The time since the start, counted up to Auto.start_ms():

def Auto.polls source · line 154 · raw

@auto:Bool -> @+elapsed:U32 -> Bool

Whether this tick polls the balloon.

def Auto.ticks source · line 160 · raw

@auto:Bool -> @+settled:U32 -> Bool

Whether the clock goes on after a tick: while the balloon is automatic or the host settles RAM (Hvf.ram_settle answers Auto.none() where nothing needs settling: then a machine without the automatic balloon stops it).