Volume Size
In this section, you’ll have a better understanding of concepts related to volume size.
Size
:Actual Size
In the example, we will explain how volume size
and actual size
get changed after a bunch of IO and snapshot related operations.
The illustration presents the file organization of one replica. The volume head and snapshots are actually sparse files, which we mentioned above.
size
is 12 Gi and the actual size
is almost 0.actual size
is 0.25 Gi and is not exactly 0.actual size
is increased by 4 Gi because of the allocated blocks in the replica for the 4 Gi data. Meanwhile, df
command in the filesystem also shows the 4 Gi used space. See Figure 2 of the illustration.Delete the 4 Gi data. Then, df
command shows that the used space of the filesystem is nearly 0, but the actual size
is unchanged.
Users can see the volume
actual size
is not shrunk after deleting the 4 Gi data. Longhorn is a block-level storage system. Therefore, the deletion in the filesystem only marks the blocks that belong to the deleted file as unused. Currently, Longhorn does not support TRIM/UNMAP operations, so thediscard
mount option orfstrim
in the filesystem layer cannot reclaim the unused blocks. In consequence, the actual size of Longhorn volumes cannot be shrunk in this case.
Then, rewrite the 4 Gi data (data#1), and the df
command in the filesystem shows 4 Gi used space again. However, the actual size
is increased by 4 Gi and becomes 8.25Gi. See Figure 3(a) of the illustration.
After deletion, filesystem may or maynot reuse the recently freed blocks from recently deleted files according to the filesystem design and please refer to Block allocation strategies of various filesystems. If the volume nominal
size
is 12 Gi, theactual size
in the end would range from 4 Gi to 8 Gi since the filesystem may or maynot reuse the freed blocks. On the other hand, if the volume nominalsize
is 6 Gi, theactual size
at the end would range from 4 Gi to 6 Gi, because the filesystem has to reuse the freed blocks in the 2nd round of writing. See Figure 3(b) of the illustration.Thus, allocating an appropriate nominal
size
for a volume that holds heavy writing tasks according to the IO pattern would make disk space usage more efficient.
actual size
remains 8.25 Gi.Delete data#1 from the mount point.
actual size
is still 8.25 Gi.Write 8 Gi data (data#2) in the volume mount, then take one more snapshot (snapshot#2). See Figure 5 of the illustration.
actual size
is 16.3 Gi, which is greater than the volume nominal size
.The volume head holds the latest data of the volume only, while each snapshot may store historical data as well as active data, which consumes at most size space. Therefore, the volume
actual size
, which is the size sum of the volume head and all snapshots, is possibly bigger than the size specified by users.Even if users will not take snapshots for volumes, there are operations like rebuilding, expansion, or backing up that would lead to system (hidden) snapshot creation. As a result, volume
actual size
being larger than size is unavoidable under some use cases.
Here we summarize the important things related to disk space usage we have in the example:
Unused blocks are not released
Longhorn does not support TRIM/UNMAP operations. Hence deleting files from filesystems will not lead to volume actual size decreasing/shrinking.
Allocated blocks but unused are not reused
Deleting then writing new files would lead to the actual size keeps increasing. Since the filesystem may not reuse the recently freed blocks from recently deleted files. Thus, allocating an appropriate nominal size for a volume that holds heavy writing tasks according to the IO pattern would make disk space usage more efficient.
By deleting snapshots, the overlapping part of the used blocks might be eliminated regardless of whether the blocks are recently released blocks by the filesystem or still contain historical data.
Reserve enough free space in disks as buffers in case of the actual size of existing volumes keep growing up.
A quick estimation for maximum space consumption estimation of a volume is
(N + 1 + 1) x head/snapshot average actual size
where N is the number of snapshots retained, the 1st 1 is for the system snapshot, and the 2nd 1 is for the temporary space that may be required by snapshot deletion.
If there are heavy writing tasks for volumes, the head/snapshot average actual size would be volume the nominal size. In this case, it’s better to set Storage Over Provisioning Percentage
to be smaller than 100% to avoid disk space exhaustion.
Do not retain too many snapshots for the volumes.
Cleaning up snapshots will help reclaim disk space. There are two ways to clean up snapshots:
Also, notice that the extra space, up to volume nominal size
, is required during snapshot cleanup and merge.
An appropriate the volume nominal size
according to the workloads.
© 2019-2024 Longhorn Authors | Documentation Distributed under CC-BY-4.0
© 2024 The Linux Foundation. All rights reserved. The Linux Foundation has registered trademarks and uses trademarks. For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.