Linux Commands

How to Setup ZFS Quotas and Reservations

ZFS Quota and Reservation are used to limit the amount of disk space a specific ZFS filesystem can use from the ZFS pool.

ZFS Quota: Let’s say you have a ZFS pool of size 10GB. You have created a ZFS filesystem on that pool. If you set a quota of 2 GB for that ZFS filesystem, then the ZFS filesystem can use only 2 GB of disk space from the pool. It can’t use any more than that even if there is free space available on the pool.

ZFS Reservation: If you set a quota of 2 GB for a ZFS filesystem, ZFS will not allocate 2 GB of disk space for that filesystem immediately. Disk space will be allocated as required until the quota limit is reached. Imagine you have many filesystems on your ZFS pool, and many users are writing to them. There may come a time when a filesystem’s quota limit is not reached, but other filesystems have filled up the disk space of the pool. So, even though the filesystem used up less than 2 GB of disk space from the pool, it still won’t write to the pool as the pool does not have any free disk space.

To solve this problem, you can use ZFS reservation. You can set 2 GB of reservation for your very special ZFS filesystem, and the moment you set the reservation, 2 GB of disk space will be allocated for the filesystem from the ZFS pool. This way, no matter how much data other filesystems store on that pool, you will still have dedicated disk spaces available for your filesystem, and you will still be able to create files on that filesystem even if the pool is full (does not have any free disk space).

In this article, I will show you how to configure quotas and reservations for ZFS filesystems. So, let’s get started.

Table of Contents

  1. Creating ZFS Pools and Filesystems
  2. Configuring ZFS Filesystem Quota
  3. Configuring ZFS Filesystem Reservation
  4. Configuring ZFS Filesystem Reservation Alongside Quota
  5. Disabling ZFS Filesystem Reservation
  6. Disabling ZFS Filesystem Quota
  7. Conclusion
  8. References

Creating ZFS Pools and Filesystems

To experiment with ZFS quota and reservation, I will create a ZFS pool pool1 and 4 ZFS filesystems fs1, fs2, fs3, and fs4 on the ZFS pool pool1. If you want to follow along, you may do the same.

This article will use the vdb and vdc storage devices to create the ZFS pool pool1.

$ sudo lsblk -e7 -d

To create the ZFS pool pool1 using the vdb and vdc storage devices, run the following command:

$ sudo zpool create -f pool1 vdb vdc

A ZFS pool pool1 should be created.

$ sudo zfs list

Create the filesystems fs1, fs2, fs3, and fs4 on the ZFS pool pool1 with the following commands:

$ sudo zfs create pool1/fs1
$ sudo zfs create pool1/fs2
$ sudo zfs create pool1/fs3
$ sudo zfs create pool1/fs4

The ZFS filesystems fs1, fs2, fs3, and fs4 should be created on the ZFS pool pool1.

$ sudo zfs list

Configuring ZFS Filesystem Quota

To set up a quota for a ZFS filesystem, you will have to configure the quota and refquota properties of that ZFS filesystem.

quota: The quota will be set for the data, filesystem snapshots, and filesystem clones. So, the total size of the data of your filesystem, filesystem snapshots, and filesystem clones can’t exceed the quota limit.

In short,

filesystem data size + filesystem snapshots size + filesystem clones size < quota limit

refquota: The quota limit is only set for the filesystem data, not for the filesystem snapshots and filesystem clones.

In short,

filesystem data size < refquota limit

By default, the quota and refquota properties are not set on any ZFS filesystems. So, the filesystem data, filesystem snapshots, and filesystem clones of any ZFS filesystem can span the entire size of the ZFS pool.

As you can see, quota and refquota properties are set to none on the ZFS filesystem fs1 by default. It is the same for the fs2, fs3, and fs4 filesystems as well.

$ sudo zfs get refquota,quota pool1/fs1

To set a quota of 2 GB for the ZFS filesystem fs1, run the following command:

$ sudo zfs set quota=2G pool1/fs1

As you can see, a quota of 2 GB is set for the ZFS filesystem fs1.

$ sudo zfs get quota pool1/fs1

After 2 GB of quota is set for the ZFS filesystem fs1, the available disk space (AVAIL) of the fs1 filesystem should be 2 GB instead of the available disk space of the pool pool1 (8.72 GB in this case), as you can see in the screenshot below.

$ sudo zfs list

You have set a quota of 2 GB for the ZFS filesystem fs1. So, you can’t keep more than 2 GB of data on the filesystem fs1. Imagine creating a few filesystem snapshots and clones that used up about 1 GB of disk space. In that case, you will have only 1 GB of disk space available for data on the fs1 filesystem. If filesystem snapshots and clones use up about 1.5 GB of disk space, you will have only 500 MB of disk space available for data on the fs1 filesystem. That’s a problem.

At times, you may want to dedicate some disk space for storing only data on your ZFS filesystem, so that filesystem snapshots and clones do not use up all the available disk space from the ZFS filesystem. You can set the refquota property for that.

Let’s say you want to set a quota of 2 GB for the ZFS filesystem fs2 and dedicate 1 GB of disk space for only data. This way, you can only use 1 GB of disk space for storing filesystem snapshots and clones.

Set up 2 GB of quota for the ZFS filesystem fs2 as follows:

$ sudo zfs set quota=2G pool1/fs1

As you can see, 2 GB of quota is set for the ZFS filesystem fs2.

$ sudo zfs list

To dedicate 1 GB of disk space for storing only data for the ZFS filesystem fs2, set the refquota property of the filesystem fs2 as follows:

$ sudo zfs set refquota=1G pool1/fs2

As you can see, the refquota property is set to 1 GB, and the quota property is set to 2 GB on the ZFS filesystem fs2.

$ sudo zfs get refquota,quota pool1/fs2

The available disk space of the ZFS filesystem fs2 should be 1 GB (1024 MB) – the size you’ve seen using the refquota property, as you can see in the screenshot below.

$ sudo zfs list

After the quota is set, let’s see how disk spaces are allocated when you create files on the ZFS filesystems fs1 and fs2.

Create a 200 MB file test.img in the ZFS filesystem fs1 as follows:

$ sudo dd if=/dev/random of=/pool1/fs1/test.img bs=1M count=200 status=progress

Create a 100 MB file test.img in the ZFS filesystem fs2 as follows:

$ sudo dd if=/dev/random of=/pool1/fs2/test.img bs=1M count=100 status=progress

As you can see, fs1 uses 200 MB of disk space, and fs2 uses 100 MB of disk space from the pool pool1. In total, 300 MB of disk space is used from the pool pool1. Even though you have set quotas for the fs1 and fs2 filesystems, only the required disk space is allocated for the filesystems fs1 and fs2 from the pool pool1.

$ sudo zfs list

If you want to set a quota only for the data of a ZFS filesystem, not for the filesystem snapshots and clones, then only set the refquota property on your desired ZFS filesystem. You don’t have to set the quota property. This way, filesystem snapshots and clones can take up as much disk space as required from the ZFS pool. But quota limit will only be placed on the data you store on your ZFS filesystem.

If you aren’t taking any filesystem snapshots or make filesystem clones, then quota and refquota work the same way. It does not matter which one you use.

Configuring ZFS Filesystem Reservation

Earlier, you have seen that when you set a quota on a ZFS filesystem, no disk space is automatically allocated for that filesystem from the ZFS pool. Disk space is allocated as files are created on that filesystem. There is no problem with that. But, there are times when you don’t want that.

In some cases, you may want to dedicate some disk space for a specific ZFS filesystem from the pool. This way, even if other filesystems fill up the pool, you will still have free spaces on your ZFS filesystem. This is what ZFS reservation is used for.

To set up a reservation for a ZFS filesystem, you will have to configure the reservation and refreservation properties of that ZFS filesystem.

Reservation: Disk space will be reserved for the data, filesystem snapshots, and filesystem clones of a ZFS filesystem from the ZFS pool.

refreservation: Disk space will be reserved for only the data of a ZFS filesystem from the ZFS pool. No disk space will be reserved for filesystem snapshots and filesystem clones.

By default, the reservation and refreservation properties are not set on any ZFS filesystems. So, ZFS does not allocate any disk space for the data, filesystem snapshots, and filesystem clones of any ZFS filesystem from the ZFS pool.

As you can see, reservation and refreservation properties are set to none on the ZFS filesystem fs3 by default. It is the same for the fs1, fs2, and fs4 filesystems as well.

$ sudo zfs get a reservation,refreservation pool1/fs3

By default, the ZFS filesystems fs3 and fs4 have the same free disk space (8.43 GB) as the pool pool1.

$ sudo zfs list

To reserve 2 GB of disk space for the ZFS filesystem fs3 (for filesystem data, snapshots, and clones) from the pool, set the reservation property of the ZFS filesystem fs3 as follows:

$ sudo zfs set reservation=2G pool1/fs3

As you can see, the reservation property is set to 2 GB for the ZFS filesystem fs3.

$ sudo zfs get reservation pool1/fs3

Notice that, immediately after setting the reservation property to 2 GB for the ZFS filesystem fs3, 2 GB is used from the ZFS pool pool11. Also, the available disk space for the ZFS filesystem fs3 is 2 GB more than the ZFS pool pool12.

$ sudo zfs list

To reserve 1 GB of disk space for only the data (not for snapshots and clones) of the ZFS filesystem fs4 from the pool, set the refreservation property of the ZFS filesystem fs4 as follows:

$ sudo zfs set refreservation=1G pool1/fs4

The refreservation property should be set to 1 GB for the ZFS filesystem fs4, as you can see in the screenshot below.

$ sudo zfs get refreservation pool1/fs4

Notice that, immediately after setting the refreservation property to 1 GB for the ZFS filesystem fs4, 1 GB is used from the ZFS filesystem fs41. 1 GB is also used from the ZFS pool pool12, and the available disk space of the ZFS filesystem fs4 is 1 GB more3 than the ZFS pool pool14.

$ sudo zfs list

Configuring ZFS Filesystem Reservation Alongside Quota

You can use reservation alongside quota on ZFS filesystems as well. Let’s see some examples.

Let’s say you want to set a quota of 2 GB for the ZFS filesystem fs3 and reserve 2 GB of disk space for the ZFS filesystem fs3 (for storing filesystem data, snapshots, and clones) from the ZFS pool.

To do that, set the quota and reservation properties of the ZFS filesystem fs3 as follows:

$ sudo zfs set quota=2G reservation=2G pool1/fs3

The quota and reservation properties of the ZFS filesystem fs3 should be set to 2 GB, as you can see in the screenshot below.

$ sudo zfs get quota,reservation pool1/fs3

The available disk space of the ZFS filesystem fs3 should be set to 2 GB. 2 GB of disk space should also be reserved for the ZFS filesystem fs3 from the ZFS pool pool1.

$ sudo zfs list

Let’s say you want to set a quota of 2 GB for the ZFS filesystem fs4. But, you want to allow only 1 GB of disk space for storing filesystem data and the other 1 GB for storing filesystem snapshots and clones. Also, you want to reserve 1 GB of disk space to store the ZFS filesystem fs4 from the ZFS pool.

To do that, set the quota, refquota, and refreservation properties of the ZFS filesystem fs4 as follows:

$ sudo zfs set quota=2G refquota=1G refreservation=1G pool1/fs4

The quota property of the ZFS filesystem fs4 should be set to 2 GB, and the refquota and refreservation properties should be set to 1 GB, as you can see in the screenshot below.

$ sudo zfs set quota,refquota,refreservation pool1/fs4

The available disk space of the ZFS filesystem fs4 should be set to 1 GB. 1 GB of disk space should also be reserved for the ZFS filesystem fs4 from the ZFS pool pool1.

$ sudo zfs list

Let’s say you want to set a quota of 2 GB for the ZFS filesystem fs4. But, you want to allow only 1 GB of disk space for storing filesystem data and the other 1 GB for storing filesystem snapshots and clones. Also, you want to reserve 2 GB of disk space for storing the filesystem data, snapshots, and clones and 1 GB of disk space from that reservation to store only the ZFS filesystem fs4.

To do that, set the quota, refquota, reservation, and refreservation properties of the ZFS filesystem fs4 as follows:

$ sudo zfs set quota=2G refquota=1G reservation=2G refreservation=1G pool1/fs4

As you can see, the quota and reservation properties of the ZFS filesystem fs4 are set to 2 GB, and the refquota and refreservation properties are set to 1 GB.

$ sudo zfs get quota,refquota,reservation,refreservation pool1/fs4

Earlier, the ZFS filesystem reserved 1 GB of disk space from the pool pool1. Now, it reserved 1 GB more. In total, 2 GB of disk space is reserved for the ZFS filesystem fs4 from the ZFS pool pool1. Also, the quota limit is set for the ZFS filesystem fs4.

$ sudo zfs list

Disabling ZFS Filesystem Reservation

You can set the reservation and refreservation property of a ZFS filesystem to none or 0 to disable reservation for that ZFS filesystem.

To disable reservation for the ZFS filesystem fs4, set the reservation and refreservation properties of the ZFS filesystem fs4 to none as follows:

$ sudo zfs set reservation=none refreservation=none pool1/fs4

Reservation should be disabled for the ZFS filesystem fs4.

$ sudo zfs get a reservation,refreservation pool1/fs4

As you can see, 2 GB of disk space (4.49 GB to 2.29 GB now) is deallocated from the ZFS pool pool1 as a reservation is disabled for the ZFS filesystem fs4.

$ sudo zfs list

Disabling ZFS Filesystem Quota

You can set the quota and refquota property of a ZFS filesystem to none or 0 to disable quota for that ZFS filesystem.

To disable quota for the ZFS filesystem fs4, set the quota and refquota properties of the ZFS filesystem fs4 to none as follows:

$ sudo zfs set quota=none refquota=none pool1/fs4

Quota should be disabled for the ZFS filesystem fs4.

$ sudo zfs get quota,refquota pool1/fs4

As you can see, no quota limits are set for the ZFS filesystem fs4 anymore.

$ sudo zfs list

Conclusion

In this article, I have discussed the quota and reservation features of the ZFS filesystem. I have shown you how to configure quotas and reservations for ZFS filesystems. I have also shown you how to disable quotas and reservations from the ZFS filesystems.

References

[1] Setting ZFS Quotas and Reservations (Solaris ZFS Administration Guide)

About the author

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.