When does the maxmem size of VM RAM become available?

16 views
Skip to first unread message

qubist

unread,
May 22, 2025, 1:55:09 PMMay 22
to qubes...@googlegroups.com
Hi,

I am looking for a way to trigger an event in a bash script as soon as
the full size of the memory of the started qube (maxmem) becomes
available.

/rw/config/rc.local seems to run before that and `grep MemTotal
/proc/meminfo` returns too small number when called from it.

How can I do that?

Marek Marczykowski-Górecki

unread,
May 22, 2025, 2:06:46 PMMay 22
to qubes...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
It feels like you want a VM with some specific amount of memory, not
"as much as it needs, and possibly some more if there is some". So, an
easier way is to simply disable dynamic memory for this VM and set the
desired static amount. This way, that VM will always get this much RAM
(and fail to start if you don't have enough free).

- --
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEhrpukzGPukRmQqkK24/THMrX1ywFAmgvZ64ACgkQ24/THMrX
1yyAyQf+N9I0Lz99n0VVOoIde2C4qkqDCL4DPkoizrPVZ5vaIllo7K3Skg+XigqQ
9JxvX8/PHHIuMHOaZhZaXO5iixaVAeH3DGcJilujgnlOMBzw/D/hFOLPWD6Y3mFZ
2SL1Y8DtEwQQXLln3eAX6Y9Ms7UYKBdX8PN+YOv5ghLCDHjG+wMgNydSR8MxS4F2
TFjb8pirqO4Py+9pEdrUEpAUYzsyTayVfGyiMaF8+CjSX8lOOSQ29vqgtfudbPwW
myHLqn/+mdH4qrcIHDhuLQjM4sI7+658Bm8TtnjiSO5gMbAeG3X5M3EmXvxWc2zw
QkJPkdubOdM8MS9K7s1ULYxhceuYoQ==
=7+hK
-----END PGP SIGNATURE-----

qubist

unread,
May 23, 2025, 12:32:20 PMMay 23
to qubes...@googlegroups.com
I know about fixing the amount to a static value. I am still interested
in the other case - different initial and maxmem, i.e. when does maxmem
become available? How does this whole thing work?

Marek Marczykowski-Górecki

unread,
May 23, 2025, 12:34:38 PMMay 23
to qubes...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

The thing is, you have absolutely no guarantee maxmem will be reached at
all. It's an upper limit, not a preferred size. See here for more info
how it's allocated:
https://www.qubes-os.org/doc/qmemman/

- --
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEhrpukzGPukRmQqkK24/THMrX1ywFAmgwo5cACgkQ24/THMrX
1ywMywf/eiaJd6f/6g45CLGDP2o2kesawAJozGRcqfV7tvO3dKt1YNC83fDKv3r2
1JtId5Us3/e6W4hOAgHHgwP2j+mWvZNciYEfwZIksQdaG9SoE5eM/YuH7UxRbCmU
D4g/+K2Rq5EjbdxJfSvQKOuqdpHo00Zd/S4pWz7nzbUdi3KKg2Mront/UtpCzyFv
wjVe2DRmMMbaoMa3UQtlCsmHeaQSdFOS+Z7c8ySmTK491bNL7u8nT5rde/vFbVmu
JJpX0OzZLRLiTw6BoIKSJ8D1vdMC1HYoMi7HZdvkxNmTgf2zKBtNFMSkWso7OBi3
rlxiFdUFoK7WZJIzhIMDio6jZPHL1w==
=Sl6F
-----END PGP SIGNATURE-----

qubist

unread,
May 23, 2025, 1:14:31 PMMay 23
to qubes...@googlegroups.com
Thanks.

I understand it is a balancing algorithm. Still, I can't answer my own
question.

Suppose:

- there is plenty of available RAM (tens of gigabytes)
- there are not VMs competing for all of it, i.e. there is enough RAM
for one VM to get its maxmem (e.g. 1 gigabyte)

At which particular moment does that one VM get its maxmem?

Also, how was the default initial 400 MB chosen?

Marek Marczykowski-Górecki

unread,
May 23, 2025, 2:04:15 PMMay 23
to qubes...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On Fri, May 23, 2025 at 05:12:38PM -0000, qubist wrote:
> Thanks.
>
> I understand it is a balancing algorithm. Still, I can't answer my own
> question.
>
> Suppose:
>
> - there is plenty of available RAM (tens of gigabytes)
> - there are not VMs competing for all of it, i.e. there is enough RAM
> for one VM to get its maxmem (e.g. 1 gigabyte)
>
> At which particular moment does that one VM get its maxmem?

There is no particular event. The Linux balloon driver will at some
point reach it when it's available. If you really want, I guess you can
wait for it in a loop (observing /proc/meminfo or such). But as said in
the initial response, it looks like a fundamentally wrong direction to
take...

> Also, how was the default initial 400 MB chosen?

Initial memory is amount just necessary for VM to boot. There used to be
a limitation in Linux that initial memory cannot be smaller than 1/10 of
maxmem, but I think it's fixed nowadays.

- --
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEhrpukzGPukRmQqkK24/THMrX1ywFAmgwuJgACgkQ24/THMrX
1yxEMAf/Y12EbvsFEFMqVWNBMuQl9u4NiFSb7uA1OFoqqoi6UdeFW0iU6MdTb7OY
lJ6yFX3ordYoWbK6YNCVus4NwIeMXqxqYI2fvvSztTZC1eOtqeQbh3YCxXaK4yNR
80hQYh6tOznK7n+O192B/Td/rlTyMNCVb+njCODyzKgcQUOtg14puqf/6/WxE3UM
xwDlUqTHi0LvPh1FQA/GizXNfrBxwAst9K6mdXvs8nvpwMPwSQIds/5SXpDpX+OO
oqByEIWuwpETH59lNXWnh2UmBRo27Tz3FAbhz17w8AbFPYCtfA8tyum61QEkMENB
+abdsCW12A8VQ9jMGGNXR0cSiAqzQQ==
=HQ3H
-----END PGP SIGNATURE-----

Ben Grande

unread,
May 23, 2025, 2:16:55 PMMay 23
to qubes...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

On 25-05-23 20:04:08, Marek Marczykowski-Górecki wrote:
> On Fri, May 23, 2025 at 05:12:38PM -0000, qubist wrote:
> > Thanks.
> >
> > I understand it is a balancing algorithm. Still, I can't answer my own
> > question.
> >
> > Suppose:
> >
> > - there is plenty of available RAM (tens of gigabytes)
> > - there are not VMs competing for all of it, i.e. there is enough RAM
> > for one VM to get its maxmem (e.g. 1 gigabyte)
> >
> > At which particular moment does that one VM get its maxmem?
>
> There is no particular event. The Linux balloon driver will at some
> point reach it when it's available. If you really want, I guess you can
> wait for it in a loop (observing /proc/meminfo or such). But as said in
> the initial response, it looks like a fundamentally wrong direction to
> take...

Atrate on Github gave a solution:

https://github.com/QubesOS/qubes-issues/issues/8936

I use this:

if test -f /var/run/qubes-service/meminfo-writer; then
mem_KiB="$(xenstore-read -- memory/hotplug-max)"
else
mem_KiB="$(xenstore-read -- memory/static-max)"
fi

Yes, there is nothing that can assure it will reach the `maxmem` and if
it can't reach, it will probably crash the program that requires a lot
of memory.

- --
Benjamin Grande
-----BEGIN PGP SIGNATURE-----

iHUEARYIAB0WIQRklnEdsUUe50UmvUUbcxS/DMyWhwUCaDC7igAKCRAbcxS/DMyW
h4giAQCGuIU18UkipWRfoHuiDZZcfC1p/WQ81zb1N4QQtPgyXgEAn46JOMzBQCLJ
qsd0z/pdtGteMzy34yl1gu4mBsr0sgs=
=JC4p
-----END PGP SIGNATURE-----

qubist

unread,
May 23, 2025, 2:24:05 PMMay 23
to qubes...@googlegroups.com
Thank you, friends!
Reply all
Reply to author
Forward
0 new messages