To create a quota group, use the snap set-quota command with a group name and a limiting attribute, such as --memory=<amount>:
snap set-quota mygroup --memory=64MB
Add snaps to a quota group
Snaps that contain services can be optionally added to a quota group when a group is created:
snap set-quota mygroup --memory=64MB snap1 snap2
After a group has been created, a snap can be added to a group when it’s installed:
snap install snap1 --quota-group=mygroup
A pre-installed snap can be added to a pre-existing quota group by running the set-quota command again:
snap set-quota highmem hello-world
See below for details on which limiting attributes are supported by quota groups.
Journal log limits
While the snap logs command is used to retrieve the systemd journal logs for a specific service, or for all services within a snap (see Inspecting logs for further details), a quota can be used to limit the output.
Log output can be limited by both size and rate within a quota group:
1. Journal size
Limit the size of the aggregated journal log for all the snaps in the quota group. This is useful when service log output is verbose on devices with limited storage capacity.
Accepts a value in either kilobytes(KB), megabytes(MB) or gigabytes(GB), including aggregated values:
In the above example, services in the max-two-specific-cores quota group could run using 100% of two cores and 0% of the other two cores, or 25% of each core, 33% of 3 of the cores and 0% of the last core, or any other combination that does not exceed 200%. The number 200% comes from the size of the --cpu-set set multiplied by the --cpu setting.
4. Limit the number of threads
The --threads option is used to limit the number of threads or processes that can be created by the snaps within the quota group.
For example, --threads=4096 will limit a quota group to no more than 4096 threads or processes.
The threads option can also be used with both --cpu and --cpu-set options to target specific requirements:
If the quota group already exists, snaps can be added by using set-quota without the resource limit:
sudo snap set-quota lowmem go-example-webserver
Adding new a snap to a quota group will result in all non-disabled services in
that snap being restarted.
New quotas can be set on existing quota groups, but existing quotas cannot be removed from a quota group, without removing and recreating the entire group.
The CPU set limit for a quota group can be modified to include new cores, or to remove existing cores from the quota already set.
The threads limit for a quota group can be increased but not decreased. To
decrease the threads limit for a quota group, the entire group must be removed
with the remove-quota command and recreated with a lower limit.
View group members and resource usage
The quota command shows information about a quota group, including the set of
snaps it includes and any subgroups it contains, as well as its resource constraints and
the current usage of those constrained resources by snap services in those snaps:
Currently, only quota groups with no subgroups can be removed. In order to remove a quota group with subgroups, the subgroups must be first removed until there are no further subgroups in the group, then the group itself can be removed.
An existing subgroup cannot be moved from one parent to another.
To remove a subgroup from a quota group, the subgroup must be first removed directly with the remove-quota command.