I have been observing strange OpenWrt behaviors on QEMU
q35 machine. The command to boot is nothing unusual except from virtio devices plugged into PCI Express ports to improve performance, and serial output (no GPU emulation). The images I use:
First problem: the minimum memory required to boot is 132MiB (
qemu-system-x86_64 -m 132M) on UEFI, and 39MiB on legacy. If I boot it with 131MiB (or 38MiB on legacy), once I get past the GRUB boot menu, I get
error: out of memory and the system reboots.
Second problem: the memory reported by OpenWrt is always lower than what QEMU assigns to it.
- I assigned 132MiB on UEFI, and
freereported 103MiB (104,988KiB) total memory. Everything ran fine even after I used a balloon device to steal 55MiB from OpenWrt to return to the host. The balloon device complained if I tried to steal 60MiB, which I thought should be fine to leave OpenWrt with ~43MiB of RAM.
- I assigned 39MiB on legacy, which was the minimum to boot. Kernel panic happened a lot during boot due to low memory. Once booted into BusyBox, it ran very slowly and
freereported 17MiB (17,704KiB) total memory.
Can someone explain these strange behaviors?
P.S: Why UEFI and legacy have different memory requirements and why is 131MiB not enough to boot OpenWrt?