A quota group sets resource limits on services running inside snaps.
Resource limits can be set for the following attributes:
Quota groups are created, removed and queried with the following snap commands:
Quota groups require snap version 2.59+. Setting quotas for journal log messages is currently considered experimental and requires that an experimental feature-flag is first be enabled:
sudo snap set system experimental.quota-groups=true
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
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.
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:
journal-size=<value>[KB|MB|GB]
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:
sudo snap set-quota loggroup --journal-size=64MB
journal-rate-limit=<number-of-messages>/<time-period>
Limit the number of messages logged to a maximum per time period. This is a useful way of limiting the number of messages for snaps.
The time period is can be nanoseconds(us), milliseconds (ms), seconds(s), minutes (m), and hours(h), including aggregated periods:
sudo snap set-quota loggroup --journal-rate-limit=10/1h2m3s4ms5us
memory=value[KB|MB|GB]
Memory units can be ‘B’, ‘KB’, 'MB or ‘GB’ with a size greater than 4KB:
sudo snap set-quota highmem --memory=2GB
The memory limit for a quota group can only be increased. Increasing the memory limit for a quota group does not restart any services associated with snaps in the quota group.
To decrease the memory limit for a quota group, the entire group must be removed with the remove-quota command and recreated with a lower limit.
CPU limits can be set in 4 different ways, some of which can be combined depending on requirements:
Without a specified CPU limit, all quota groups can use the full system capacity.
cpu=<percentage>%
Sets a relative percentage limit on how much execution time a process receives, regardless of the number of cores available, up to 100%.
--cpu=<number of cores>x<percentage>%
One or more cores can be specified alongside a CPU percentage to allocate relative CPU resources across only that number of cores.
For example, --cpu=2x100%
on a 4 core system would permit a process to run at full capacity on only two cores, which is equivalent to 50% of full system capacity.
cpu-set=<core number 1>,<core number 2> --cpu=<percentage>%
Using an additional --cpu-set
argument with --cpu
, it’s possible to specify exactly which cores to be used as the CPU resources for that quota group.
For example, --cpu-set=0,1 --cpu=100%
will permit up to 100% CPU resource usage on 2 specific cores (0 and 1).
The following example will allow up to a maximum of half usage combined on four specific cores which means the sum of usage across all 4 specific cores cannot exceed 200%:
snap set-quota max-two-specific-cores --cpu-set=0,1,2,3 --cpu=50%
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.
threads=<thread limit>
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:
snap set-quota max-two-specific-cores --cpu-set=0,1,2,3 --cpu=50% --threads=8092
By default, quota groups are not limited in the number of threads they can create.
If the group already exists, set-quota will update its resource limits.
Use the quotas command to view created quota groups:
$ snap quotas
Quota Parent Constraints Current
highmem memory=2.00GB cpu=50%,cpu-set=0,1
cpuhalf cpu=50%,cpu-set=0,1
manycores cpu=2x,cpu=100%,threads=4096
maxcores cpu=100%
memcpu memory=2.00GB,cpu=50%
threads threads=4096
loggroup journal-size=64.0MB,journal-rate=10/1h2m3.004005s
Snaps can belong to only one quota group, but quota groups can be nested.
To create a nested quota group, add the --parent=<parent group>
argument to the set-quota command when creating a new quota group:
sudo snap set-quota lowmem --memory=1GB --parent=highmem
The quotas command will also show nested quota groups:
$ snap quotas
Quota Parent Constraints Current
highmem memory=2.00GB
lowmem highmem memory=1.00GB
The total resource use of nested quota groups cannot exceed that of the parent group.
Add the names of one or more snaps to the set-quota command to include those snaps in the quota group when its created:
sudo snap set-quota lowmem go-example-webserver --parent=highmem
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.
Updating quotas in a group, or imposing new quotas on an existing quota group, will per default require restarting any running services in that quota group.
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:
$ snap quota lowmem
name: lowmem
parent: highmem
constraints:
memory: 1.00GB
current:
memory: 5.32MB
snaps:
- go-example-webserver
Use the quota command on the parent of any nested groups to view total resource usage and subgroups:
$ snap quota highmem
name: highmem
constraints:
memory: 2.00GB
current:
memory: 5.35MB
subgroups:
- lowmem
To remove a snap from a quota group, the entire group must be removed with the remove-quota command and the quota group recreated without the snaps:
$ sudo snap remove-quota lowmem
$ sudo snap set-quota lowmem --memory=1GB
$ snap quota lowmem
name: lowmem
constraints:
memory: 1.00GB
current:
memory: 0B
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.
Last updated 3 months ago.