Limiting Memory of Snap Packages

Some snaps (cough Slack) will given the opportunity eat up an almost unlimited amount of memory. In the pre-slack post systemd world I could create a namespace, limit it's memory/cpu etc... and force slack to not eat the world by executing it inside of that namespace.

What's the proper way to add a similar limit to a Snap Package? Since snaps are already exectuted inside of some cgroup wizardry I'm hoping its as simple as a snap modify <snappackage> -addmemlimit 1G or something.


Solution 1:

It is possible, but experimental, through the use of the quota groups feature. You have to create a quota group with resource limits (for now, only the memory resource limit is available), and attach one or more snaps to that quota group :

  1. Enable the experimental feature : snap set system experimental.quota-groups=true
  2. Create the quota group w/snaps attached : snap set-quota --memory=4GB memlimit firefox

Source : https://snapcraft.io/docs/quota-groups