Swap space and reducing memory usage?

295 views
Skip to first unread message

Gaiko Kyofusho

unread,
May 20, 2017, 12:51:49 PM5/20/17
to qubes...@googlegroups.com
I have a 16gb mem system which can't be upgraded any further to my knwoledge. I had thought this would be enough but I am running into memory errors more often than I would like. I admittedly open maybe 7-12 appvms so the obvious answer to my prob might be open less appvms but for my workflow that would be inconvient. I do not remember setting up a swap space during setup but I think it was set up automatically though in the dom0 system monitor plugin the swap space monitor never seems to move (stays at zero). 

My questions are two fold I guess:
  1. Are there any recomended ways for reducing memory usage?
  2. How can I tell if swap is being used?
  3. If swap is not being used how can I enable it?

Reg Tiangha

unread,
May 20, 2017, 1:10:10 PM5/20/17
to qubes...@googlegroups.com
On 05/20/2017 10:51 AM, Gaiko Kyofusho wrote:
> I have a 16gb mem system which can't be upgraded any further to my
> knwoledge. I had thought this would be enough but I am running into
> memory errors more often than I would like. I admittedly open maybe
> 7-12 appvms so the obvious answer to my prob might be open less appvms
> but for my workflow that would be inconvient. I do not remember
> setting up a swap space during setup but I think it was set up
> automatically though in the dom0 system monitor plugin the swap space
> monitor never seems to move (stays at zero).
>
> My questions are two fold I guess:
>
> 1. Are there any recomended ways for reducing memory usage?
> 2. How can I tell if swap is being used?
> 3. If swap is not being used how can I enable it?
>
I only have 8 GB of RAM and it can handle about 7-12 VMs, depending on
what I'm doing. But I tweaked my VM memory settings; leaving it to the
defaults makes it hard to run more than 4-5 VMs at the same time since
new ones won't start up because of a lack of RAM.

The first thing you can do is reduce the max amount of memory the AppVMs
use. By default, they're set to use between 400-4000 MB of RAM, but if
you look at your actual VM RAM usage in a terminal window by using the
top or free commands, you may find that your actual usage is a lot less
and can reduce that upper limit to something like 2000 MB or less. That
includes your service VMs like your firewall; you can probably reduce
the upper limit on sys-firewall to 300-400 MB rather than the 4000 MB
it's set to by default.

Or if you don't go crazy with various iptables firewall rules, you can
run the qubes-mirage-firewall from here as a replacement to sys-firewall:

https://github.com/talex5/qubes-mirage-firewall

I have mine running with only 32MB of RAM and things work fine (there's
a hack you may need to do to get DispVMs to connect to the internet
properly though, but regular VMs work fine with it).

Next thing to look at is the RAM allocated to dom0. By default, the
upper limit is 4096 MB but I reduced mine to 2048 MB and haven't
encountered any noticeable issues. In order to change it though, you
have to edit your GRUB config files and then reboot.

Edit /etc/default/grub in dom0 and change the dom0_mem=min and
dom0_mem=max values to match your needs. I set mine to 1024 and 2048
respectively, but you might be able to go even lower (say 512 and 1536
or something like that). Then, you'd need to regenerate
/boot/grub2/grub.cfg to get it to work permanently. I don't remember the
command off the top of my head, but you alternatively, you can edit that
file directly making the changes to all references of dom0 max and min
memory like you did with the previous file, save it, and it'll still
work once you reboot.

If you make those changes, that should help. There's no magic bullet as
to what to set those max memory settings to since it really depends on
how you use your VMs, so you may have to do a bit of profiling first to
figure out what your optimal max RAM values are for each case.


Vít Šesták

unread,
May 20, 2017, 3:19:15 PM5/20/17
to qubes-users
Hello,


> I have a 16gb mem system which can't be upgraded any further to my knwoledge.

What is the reason? CPU limits? MoBo limits? Soldered RAM? If the reason is just MoBo limit, you can just try to ignore it? My old laptop was officially able to have at most 8GiB RAM because of MoBo limits. I was told to ignore it and try 16GiB, as the memory controller is in the CPU, which can handle such amount of the memory. And it works well.

Also, my current laptop supports reportedly at most 16GiB. It currently has one 16GiB module plus one unused memory slot. I believe it will work fine with 16GiB+16GiB, as the CPU supports it. AFAIR, even some forum thread indicates this for this or some similar model.

For Intel CPUs, the memory limit can be found at https://ark.intel.com/ .

>I do not remember setting up a swap space during setup but I think it was set up automatically though in the dom0 system monitor plugin the swap space monitor never seems to move (stays at zero).

Note that Qubes has a separate swap for each VM. You can see details using cat /proc/swaps, htop or gnome-system-monitor, whichever you prefer. But any of them will show you the swap status just for the one VM you run it in. Default swap setup:

* dom0 - not sure
* PV appVMs - 1 GiB swap (this limit used to be hardcoded, not sure about the current status). Theoretically, you can add an extra swap, but I don't think it makes much sense.
* HVMs - depends on the guest OS

Also note that swap does not work well with memory balancing, because Qubes counts used swap as used memory. As a result, even if the VM has swapped some memory, it does not offer it to other VMs. There was some discussion about it in the past.

As far as I know, the only workaround on this fact is reducing the upper memory limit or even disabling memory balancing for the VM.

> Are there any recommended ways for reducing memory usage?

Note that VMs with some PCI device (most notably sys-net and sys-usb on clean install) have memory balancing disabled. It might be worth trying to reduce its memory to as low as 200MiB.

> If swap is not being used how can I enable it?

It depends on for what VM you want swap. When adding a swap for dom0, you might want the swap to be encrypted, ideally with a random key.

Regards,
Vít Šesták 'v6ak'

Vít Šesták

unread,
May 20, 2017, 3:33:06 PM5/20/17
to qubes-users, r...@reginaldtiangha.com
> Edit /etc/default/grub in dom0

Note that /etc/default/grub applies on legacy boot only. If you have UEFI (like me), you have to edit /boot/efi/EFI/qubes/xen.cfg in a similar way. Unlike with grub, you just save the file and reboot, without any need of regenerating any file. When I update kernel, it copies parameters from the latest one.

Gaiko

unread,
May 21, 2017, 4:21:48 PM5/21/17
to qubes-users, r...@reginaldtiangha.com

Wow thanks, I didn't realize that I was lowering the min and ignoring the max (now not sure what I was thinking) but the parameters you gave really helped!

Gaiko

unread,
May 21, 2017, 4:22:37 PM5/21/17
to qubes-users, r...@reginaldtiangha.com
On Saturday, May 20, 2017 at 3:33:06 PM UTC-4, Vít Šesták wrote:
> > Edit /etc/default/grub in dom0
>
> Note that /etc/default/grub applies on legacy boot only. If you have UEFI (like me), you have to edit /boot/efi/EFI/qubes/xen.cfg in a similar way. Unlike with grub, you just save the file and reboot, without any need of regenerating any file. When I update kernel, it copies parameters from the latest one.

Thanks for that note, and esp for the bit about mem, I never considered that I might be able to put more than the factory recomended amount, I will have to research that a bit!
Reply all
Reply to author
Forward
0 new messages