Maintain volumes using Filesystem Trim
A typical Portworx volume is formatted with ext4 and then used by a container application to store its content files and directories. Over time, your application might create and delete files and directories. On the volume, the space which was previous used by a deleted file gets freed in the filesystem metadata and the underlying block device is unaware of this fact. This can lead to the following inefficiencies:
- On thin provisioned volumes, the freed space in the volume does not translate into free space in the pool. This means that other volumes in the pool that require space might not be able to get it from the pool.
- On SSDs, the block device performs better when it has knowledge of all the freed blocks that the user no longer requires. This information is used by the SSD firmware to perform wear-leveling more efficiently to improve the service life of the storage device and also provide better I/O performance. When the information about the blocks freed in the filesystem is not available to the block device, it creates hot spots in the device that cause it to wear more than rest of the blocks in the device.
To address these inefficiencies, you can instruct the filesystem to inform the block device of all the unused blocks which were previously used by issuing a FITRIM ioctl command to the mounted filesystem. The filesystem in turn issues a DISCARD request for the freed blocks to the block device.
You can use automatic filesystem trim operations, or you can perform filesystem trim operations manually.
Automatic filesystem trim operations
Automatic filesystem trim is disabled by default. You can enable automatic filesystem trimming (auto fstrim) at the volume, node, or cluster level. When all of the following conditions are met, auto fstrim monitors the unused space in all filesystems mounted on Portworx volumes and automatically triggers a trim job to return unused space back to the pool, and you do not have to manually issue trim jobs:
- Volumes have
nodiscardenabled - Auto fstrim is enabled at the cluster level or on the node where the volume is attached
Auto fstrim takes into account current workloads in the system and dynamically adjusts the rate at which it performs the trim job. This prioritizes user application performance while optimizing trim rate when application load is low. Note that nodiscard and auto fstrim are not supported on volumes formatted with XFS. For more details, see the Force-enable the nodiscard and auto-fstrim options on XFS formatted volumes section.
- Enabling auto fstrim or changing IO rates has a small delay before taking effect.
- If a volume is unmounted or detached, Portworx automatically stops auto fstrim on that volume. If the volume is remounted, auto fstrim automatically starts again.
Enable auto fstrim
Enable on a new volume
To create a new volume with auto fstrim enabled, specify the following options at volume creation:
pxctl volume create <volume_name> --nodiscard
Volume successfully created: <volume_ID>
You can verify that the volume has auto fstrim enabled with the following command:
pxctl volume inspect <volume_name>
...
Mount Options : nodiscard
...
Auto Fstrim : true
...
Enable on an existing volume
To enable auto fstrim on an existing volume, run the following command:
pxctl volume update --nodiscard on <volume_name>
You can verify that the volume has auto fstrim enabled with the following command:
pxctl volume inspect <volume_name>
...
Mount Options : nodiscard
...
Auto Fstrim : true
...
Enable on a node
To enable auto fstrim for a node, run the following command:
pxctl cluster options update --runtime-options-action update-node-specific --runtime-options-selector node=<node_uuid> --runtime-options NodeAutoFstrimEnabled=1
Running this command will overwrite any auto fstrim IO rates you have set at the node level to their default values.
Enable on a cluster
To enable auto fstrim for a cluster, run the following command:
pxctl cluster options update --auto-fstrim on
Schedule fstrim operations
Instead of letting auto fstrim trigger jobs automatically, you can schedule fstrim operations by defining a specific time and duration for fstrim to run. This is particularly beneficial if you're looking to perform operations when you know your node will have low traffic.
When you specify a window, fstrim will do a one time run in the specified window. It collects all locally mounted nodiscard volumes in a queue. This queue is then organized based on the amount of space that can be trimmed, and the process sequentially trims these volumes.
If the queue is empty, fstrim does the same job in the next window to trim volumes which are not in use by the filesystem. It stops if it cannot complete the job in the specified window and reinstates the queue to be processed during the next time window.
The auto fstrim and fstrim schedule job cluster options are mutually exclusive. When autofstrim is enabled on a node, fstrim schedule job will be disabled and vice versa.
To specify a window for fstrim jobs, enter the following pxctl cluster options update command, specifying the following:
- the
--fstrim-schedule-startflag with the UTC time you want to start thefstrimoperation. The window can either be set to weekly or daily. You can specify this in either the daily format:daily=hh:mmor the weekly format:weekly=day@hh:mm. - the
--fstrim-schedule-durationflag followed by the number of hours you want the window to remain open for.
The following command will schedule a fstrim job schedule on the daily basis. To switch to a weekly schedule, modify the format accordingly:
pxctl cluster options update --fstrim-schedule-start <daily=hh:mm> --fstrim-schedule-duration <hrs>