~/bend-docscommunity

src/virtio/balauto.bend checks

raw source on the hub · import 0x797e6e88f253acc21022638860fd49ed/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.pages source · line 76 · raw

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

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

def Auto.entry source · line 79 · raw

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

def Auto.stats.go source · line 88 · 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 97 · raw

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

def Auto.fresh source · line 100 · raw

Stats

def Auto.grow source · line 103 · raw

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

def Auto.shrink source · line 106 · raw

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

def Auto.target source · line 114 · raw

@+st:Stats -> @+target: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.later source · line 127 · 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 131 · raw

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

Whether this tick polls the balloon.

def Auto.ticks source · line 137 · 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).