Add ability to control the memory used by fully emulated QEMU guests

Registered by Kashyap Chamarthy

QEMU in its TCG mode (i.e. full system emulation) uses a translation
block (TB) cache of 32MB as an optimization during dynamic code
translation. However, in QEMU v5.0, the default size of this cache was
updated[1] from 32MB to a whopping 1024MB. This was done for two
reasons: (a) the small 32MB buffer meant, QEMU had to flush and
regenerate it hundreds of times, thus slowing down the guest; and (b)
an assumption that "we expect most system emulation to run one or two
guests per host. Users running large scale system emulation may want to
tweak their runtime setup via the `tb-size` control"[1].

While this increase of 'tb-cache' buffer improves the guest performance,
it also dramatically increases[2] the memory used by a TCG guest
(<domain type='qemu'>). As a consequnce, CI systems with TCG gusts that
relied on older behaviour of 32MB cache will now hit OOM Killer --
because, the newer 1GB cache means far fewer TCG guests per host. (Note
that this does not affect KVM guests.)

Luckily, adjusting the "tb-size" parameter in QEMU (e.g. `-accel
tcg,tb-size=64`) lets you control this cache value. And upstream
libvirt is in the process of wiring it up[3][4][5] via "tb-cache":

      ...
      <features>
        <tcg>
          <tb-cache unit='MiB'>64</tb-cache>
        </tcg>
      </features>
      ...

Both MiB and KiB are valid units in the XML for `tb-cache`; internally
libvirt stores it in KiB. This feature will be available in libvirt
v7.10.0 (December 2021).

    [1] https://gitlab.com/qemu-project/qemu/-/commit/600e17b26
        accel/tcg: increase default code gen buffer size for 64 bit
    [2] https://gitlab.com/qemu-project/qemu/-/issues/693 (Qemu increased
        memory usage with TCG)
    [3] https://gitlab.com/libvirt/libvirt/-/issues/229
    [4] https://gitlab.com/libvirt/libvirt/-/issues/233
    [5] https://listman.redhat.com/archives/libvir-list/2021-November/msg00194.html
        "Introduce TCG domain features"

Blueprint information

Status:
Not started
Approver:
None
Priority:
Undefined
Drafter:
Kashyap Chamarthy
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.