~/bend-docscommunity

src/virtio/balloon.bend checks

raw source on the hub · import 0x67452e7bc6132b3fa11a687623945b86/src/virtio/balloon.bend as Balloon

6 imports
import Base
import ../lib/u64.bend as U
import ../lib/bytes.bend as B
import ../vmm/abi.bend as V
import ./queue.bend as Q
import ./balauto.bend as A

Types

type Part source · line 124 · raw

Data

type Bal source · line 127 · raw

Data

type Took source · line 176 · raw

Data

A page into its block's mask: the masks after it, and the block when it is now whole (U32 max when not).

type Inflated source · line 235 · raw

Data

type BalPass source · line 439 · raw

Data

A pass with the device's state.

type AutoSt source · line 536 · raw

Data

What the automatic balloon keeps: the stats buffer the driver posted and the device holds (its head; Auto.none() when none), whether the host asked for the statistics it will bring (only an answer moves the target: the first buffer, posted at the driver's start, does not), whether a target was set by hand (balloon MiB: the automatic balloon stands aside), and the latest statistics.

type StatsPass source · line 562 · raw

Data

Definitions

def Balloon.features source · line 28 · raw

0x67452e7bc6132b3fa11a687623945b86/src/lib/u64.U64

def Balloon.queues source · line 31 · raw

Nat

def Balloon.report_queue source · line 34 · raw

U32

def Balloon.config source · line 37 · raw

List<&2, U32>

def Balloon.align source · line 41 · raw

U32

The release granule: 16 KiB, macOS's host page.

def Balloon.inside source · line 46 · raw

@+addr:0x67452e7bc6132b3fa11a687623945b86/src/lib/u64.U64 -> @+len:U32 -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Iov

The whole granules inside [addr, addr+len): none (len 0) when there are none.

def Balloon.len source · line 51 · raw

@+i:0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Iov -> U32

def Balloon.ranges source · line 57 · raw

@ds:List<&2, 0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Desc> -> List<&2, 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Iov>

The granules of every descriptor of a buffer, the empty ones dropped.

def Balloon.free source · line 68 · raw

@-R:Type -> @go:Bool -> @+rs:List<&2, 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Iov> -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, Unit>

def Balloon.serve source · line 75 · raw

@-R:Type -> @release:Bool -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> @c:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Chain -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, 0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq>

def Balloon.step source · line 83 · raw

@-R:Type -> @release:Bool -> @r:Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Maybe<&2, 0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Chain>) -> @used:Bool -> @k:(@_:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Bool)>) -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Bool)>

def Balloon.go source · line 92 · raw

@fuel:Nat -> @-R:Type -> @+release:Bool -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> @used:Bool -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Bool)>

def Balloon.process source · line 103 · raw

@-R:Type -> @+sel:U32 -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Bool)>

Queue sel's pass: the reporting queue releases what each buffer names; the others return their buffers. At most 256 buffers per pass.

def Balloon.offered source · line 118 · raw

0x67452e7bc6132b3fa11a687623945b86/src/lib/u64.U64

Inflate and deflate (Virtio 1.2 5.5.6), with VIRTIO_BALLOON_F_DEFLATE_ON_OOM (bit 2) offered too (Balloon.offered): the host sets num_pages, a target in 4 KiB pages (balloon MiB on the control socket: Balloon.set_target); the guest gives pages to the balloon on the inflate queue and takes them back on the deflate queue, each buffer an array of u32 page frame numbers (4 KiB pages, at most Balloon.max_pfns() of them read per buffer). The device counts them (actual) and lets go of a 16 KiB block's memory once all its 4 pages are in the balloon: it keeps, per block that is partly in, a 4-bit mask of the pages that are. A deflated page leaves its mask; one of a block already released is not tracked again (its memory reads zeros when the guest touches it), so the device never releases a block with a page the guest still has.

def Balloon.max_pfns source · line 121 · raw

U32

def Balloon.new source · line 130 · raw

Bal

def Balloon.config_of source · line 134 · raw

@+b:Bal -> List<&2, U32>

The config space of a state: num_pages (the target), actual.

def Balloon.set_target source · line 139 · raw

@+b:Bal -> @+pages:U32 -> Bal

def Balloon.target source · line 144 · raw

@+b:Bal -> U32

def Balloon.actual source · line 149 · raw

@+b:Bal -> U32

def Balloon.bits source · line 157 · raw

@+m:U32 -> U32

The pages the balloon holds that the host could not release: those of its partial blocks (a 16 KiB block is released only once all four of its pages are in the balloon).

def Balloon.kept.go source · line 160 · raw

@ps:List<&2, Part> -> U32

def Balloon.kept source · line 169 · raw

@+b:Bal -> U32

def Balloon.none source · line 179 · raw

U32

def Balloon.take.add source · line 182 · raw

@+p:Part -> @+t:Took -> Took

def Balloon.take source · line 187 · raw

@ps:List<&2, Part> -> @+block:U32 -> @+bit:U32 -> Took

def Balloon.give source · line 199 · raw

@ps:List<&2, Part> -> @+block:U32 -> @+bit:U32 -> List<&2, Part>

def Balloon.bit source · line 211 · raw

@+pfn:U32 -> U32

def Balloon.parts16.q source · line 218 · raw

@+b:U32 -> @+m:U32 -> @+q:U32 -> @+rest:List<&2, Part> -> List<&2, Part>

A snapshot taken with 64 KiB blocks (state tags 7 and 8): each mask of 16 pages as the masks of its four 16 KiB blocks (none for an empty quarter). A quarter all in the balloon was not released then: it keeps a whole mask and stays until deflated.

def Balloon.parts16 source · line 222 · raw

@ps:List<&2, Part> -> List<&2, Part>

def Balloon.block_iov source · line 232 · raw

@+block:U32 -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Iov

The released blocks of an inflate, as guest ranges.

def Balloon.inflate.one source · line 238 · raw

@+t:Took -> @+ta:U32 -> @+a:U32 -> @+free:List<&2, 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Iov> -> Inflated

def Balloon.inflate source · line 244 · raw

@pfns:List<&2, U32> -> @+i:Inflated -> Inflated

Pages into the balloon: the state after them, and the blocks now whole.

def Balloon.deflate source · line 254 · raw

@pfns:List<&2, U32> -> @+b:Bal -> Bal

Pages out of the balloon.

def Balloon.part_le source · line 268 · raw

@x:Part -> @y:Part -> Bool

A whole buffer of page numbers at once (Balloon.on_pfns): the same state as Balloon.inflate and Balloon.deflate one page at a time, with the masks in block order, in one walk of them (one page at a time walks them once per page: a fragmented guest's balloon holds tens of thousands of partial blocks, and inflating into it took seconds per MiB).

def Balloon.part_of source · line 275 · raw

@+pfn:U32 -> Part

def Balloon.parts_of source · line 278 · raw

@pfns:List<&2, U32> -> List<&2, Part>

def Balloon.join_into source · line 286 · raw

@+p:Part -> @xs:List<&2, Part> -> List<&2, Part>

A part onto sorted parts: joined with the first when they share a block.

def Balloon.join source · line 297 · raw

@ps:List<&2, Part> -> List<&2, Part>

def Balloon.batch source · line 305 · raw

@+pfns:List<&2, U32> -> List<&2, Part>

A buffer's pages as masks, one per block, in block order.

def Balloon.ordered.go source · line 308 · raw

@ps:List<&2, Part> -> @+prev:U32 -> Bool

def Balloon.ordered.pick source · line 317 · raw

@sorted:Bool -> @+ps:List<&2, Part> -> List<&2, Part>

def Balloon.ordered source · line 326 · raw

@+ps:List<&2, Part> -> List<&2, Part>

The masks in block order (a state from an older snapshot may hold them in any order).

def Balloon.keep source · line 335 · raw

@+p:Part -> @+i:Inflated -> Inflated

def Balloon.one_in source · line 340 · raw

@+b:U32 -> @+m:U32 -> @+i:Inflated -> Inflated

def Balloon.in_only source · line 345 · raw

@ns:List<&2, Part> -> Inflated

def Balloon.in_merge source · line 356 · raw

@fuel:Nat -> @os:List<&2, Part> -> @ns:List<&2, Part> -> Inflated

Sorted masks and a sorted batch: the masks after it (count and target left 0: Balloon.inflate_all sets them), and the blocks now whole.

def Balloon.in_set source · line 378 · raw

@+t:U32 -> @+a:U32 -> @+i:Inflated -> Inflated

def Balloon.inflate_all source · line 383 · raw

@+pfns:List<&2, U32> -> @+b:Bal -> Inflated

def Balloon.out_one source · line 391 · raw

@+b:U32 -> @+m:U32 -> @+rest:List<&2, Part> -> List<&2, Part>

def Balloon.out_merge source · line 394 · raw

@fuel:Nat -> @os:List<&2, Part> -> @ns:List<&2, Part> -> List<&2, Part>

def Balloon.deflate_all source · line 416 · raw

@+pfns:List<&2, U32> -> @+b:Bal -> Bal

def Balloon.pfns source · line 425 · raw

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

The u32 page numbers of a buffer's bytes (little-endian).

def Balloon.on_inflated source · line 442 · raw

@-R:Type -> @+i:Inflated -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, Bal>

def Balloon.on_pfns source · line 449 · raw

@-R:Type -> @+inflate:Bool -> @+b:Bal -> @+pfns:List<&2, U32> -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, Bal>

def Balloon.pfn_serve source · line 458 · raw

@-R:Type -> @+inflate:Bool -> @+b:Bal -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> @c:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Chain -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Bal)>

One inflate or deflate buffer: its page numbers read (at most max_pfns), counted, the whole blocks released; returned with length 0.

def Balloon.pfn_step source · line 467 · raw

@-R:Type -> @+inflate:Bool -> @+b:Bal -> @r:Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Maybe<&2, 0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Chain>) -> @used:Bool -> @k:(@_:Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Bal) -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, BalPass>) -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, BalPass>

def Balloon.pfn_split source · line 476 · raw

@-R:Type -> @qb:Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Bal) -> @k:(@_:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> @_:Bal -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, BalPass>) -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, BalPass>

def Balloon.pfn_go source · line 481 · raw

@fuel:Nat -> @-R:Type -> @+inflate:Bool -> @+b:Bal -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> @used:Bool -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, BalPass>

def Balloon.pass.report source · line 492 · raw

@-R:Type -> @+b:Bal -> @r:Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Bool) -> BalPass

A queue's pass with the device's state: 2 reports free pages; 0 inflates, 1 deflates.

def Balloon.pass.go source · line 497 · raw

@-R:Type -> @report:Bool -> @+sel:U32 -> @+b:Bal -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, BalPass>

def Balloon.pass source · line 504 · raw

@-R:Type -> @+sel:U32 -> @+b:Bal -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, BalPass>

def Balloon.offered_auto source · line 517 · raw

0x67452e7bc6132b3fa11a687623945b86/src/lib/u64.U64

def Balloon.queues_auto source · line 520 · raw

Nat

def Balloon.stats_queue source · line 523 · raw

U32

def Balloon.logical source · line 527 · raw

@+stats:Bool -> @+sel:U32 -> U32

The driver's number for one of ours (stats: it accepted the stats queue).

def Balloon.auto_new source · line 539 · raw

AutoSt

def Balloon.auto_manual source · line 542 · raw

@+a:AutoSt -> @+manual:Bool -> AutoSt

def Balloon.auto_held source · line 547 · raw

@+a:AutoSt -> U32

def Balloon.auto_on source · line 552 · raw

@+a:AutoSt -> Bool

def Balloon.auto_target source · line 559 · raw

@+asked:Bool -> @+manual:Bool -> @+st:0x67452e7bc6132b3fa11a687623945b86/src/virtio/balauto.Stats -> @+b:Bal -> Bal

The target after a stats buffer: moved only when the host asked for it and no target was set by hand.

def Balloon.stats.serve source · line 565 · raw

@-R:Type -> @+b:Bal -> @a:AutoSt -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> @c:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Chain -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, StatsPass>

def Balloon.stats.got source · line 573 · raw

@-R:Type -> @+b:Bal -> @+a:AutoSt -> @r:Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, Maybe<&2, 0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Chain>) -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, StatsPass>

def Balloon.stats_pass source · line 582 · raw

@-R:Type -> @+b:Bal -> @+a:AutoSt -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, StatsPass>

The stats queue's pass: the buffer the driver posted is read and held (the host returns it when it wants fresh statistics: Balloon.poll).

def Balloon.poll.go source · line 588 · raw

@-R:Type -> @skip:Bool -> @+h:U32 -> @+k:Bool -> @+manual:Bool -> @+st:0x67452e7bc6132b3fa11a687623945b86/src/virtio/balauto.Stats -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, Pair(Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, AutoSt), Bool)>

Asking for fresh statistics: the held buffer returned (used length 0); the driver posts it again with new values. Nothing when none is held or a target was set by hand.

def Balloon.poll source · line 596 · raw

@-R:Type -> @+a:AutoSt -> @q:0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq -> 0x67452e7bc6132b3fa11a687623945b86/src/vmm/abi.Op<R, Pair(Pair(0x67452e7bc6132b3fa11a687623945b86/src/virtio/queue.Vq, AutoSt), Bool)>