Quota groups

A quota group sets resource limits on services running inside snaps.

Resource limits can be set for the following attributes:

  • Journal log messages: as a maximum size for the log and as a rate limit
  • Memory: as a maximum amount of RAM
  • CPU usage: as a percentage across a number - or specific - CPU cores, and as a given number of threads

Quota groups are created, removed and queried with the following snap commands:

  • set-quota: create or update a quota group
  • quota: show quota group for a set of snaps
  • quotas: show all quota groups
  • remove-quota: remove a quota group

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

Create a quota group

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.

Limiting attributes

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:

sudo snap set-quota loggroup --journal-size=64MB

2. Journal rate limit


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 limits


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

CPU limits can be set in 4 different ways, some of which can be combined depending on requirements:

  1. Percentage of total CPU resources
  2. Percentage of a given number of CPU cores
  3. Percentage for specific cores
  4. Limit the number of threads

Without a specified CPU limit, all quota groups can use the full system capacity.

1. Percentage of total CPU resources


Sets a relative percentage limit on how much execution time a process receives, regardless of the number of cores available, up to 100%.

2. Percentage of a given number of CPU cores

--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.

3. Percentage for specific cores

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.

4. Limit the number of threads

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.

View quotas

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.

Nested quota groups

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.

Update a quota 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.

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:

$ snap quota lowmem
name:    lowmem
parent:  highmem
  memory:  1.00GB
  memory:  5.32MB
  - 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
  memory:  2.00GB
  memory:  5.35MB
  - lowmem

Remove snaps and quota groups

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
  memory:  1.00GB
  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.

I note that “snap help --all” does not mention “snap set-quota”. Is that deliberate?


Starting with snapd 2.59, support for per-service quota groups will be introduced. This means that it will be possible to create sub quota-groups that contain on or multiple services of a snap, as long as that snap is in the parent group. That allows individual limits for a service, instead of sharing the limit set for the parent snap.

An example would be a snap containing a backend system, with multiple services, for instance: backend.api-service backend.logic-service

we can then put the backend snap into a quota group like this and give it a memory limit we don’t want the snap to exceed (this is shared limit for all services)

snap set-quota test-top --memory=512MB snap-backend

We then want to isolate the logic-service to not consume all of the memory, by seperating that service into it’s own, specific quota group with a memory limit of 128MB

snap set-quota test-sub --parent=test-top --memory=128MB snap-backend.logic-service

1 Like

Technically, snap set-quota is still experimental, and therefor does not show up in snap help --all. However we expect some of this functionality to go out of experimental soon.

Thanks for letting me know, and for the excellent description. I’ll make sure this is added to the doc.

I know next to nothing about quota groups, but I note that “snap install” has a “–quota-group” option:

   $ snap install --help
    --quota-group=       Add the snap to a quota group on install

That should probably be mentioned here somewhere.

Some minor typos spotted:

Line 4 "Memory: as a maximum amount or RAM " => Should that be “a maximum amount of RAM”?

CPU Limits: Section: 3.Percentage for Specific Cores “for that quote group.” => “for that quota group.”

CPU Limits: Section 4 “threads = < thread limit” - Missing closing brace?

Thank you so much! And sorry these slipped through.

First of all, this is a nice feature. Thanks

One suggestion though.

In documentation above, we can see this:

Yet, when I ran sudo snap set-quota mem512 --memory=512M nextcloud, I got error: cannot parse "512M": try 'kB' or 'MB'

So, units in some examples above seem to be not up to date

1 Like

Ran into the same issue as pointed out by mrk above, @degville – this behavior has probably changed since this was written.

(I’ve gone ahead and changed the references to M in the input examples to MB)

1 Like