Configuring and Using the Discard

The Discard command allows cleaning unused blocks on a disk. All BSU volumes support this command, provided that the operating system is compatible and properly configured.

This command has different names depending on the operating system (for example Trim, Discard or Unmap). In this guide, the command is named Discard.

Using the Discard command reduces the space consumed by snapshots, and therefore their cost. It may also improve the IOPS (input output per second) performances. For more information, see About Volumes.

It is recommended to use the Discard command each time you create a snapshot.

This technical guide describes 3 methods to configure and using the Discard command:

  • Launching the discard periodically

    We recommend using this method. This method is applied by default to our official images since January 2024.

  • Launching the discard manually

  • Configuring the discard when mounting a volume

    This method can be dangerous and must be used with full knowledge of the possible impact on the performance.

Making Sure the Discard is Available

Making Sure the Discard is Available on Linux

Use the following command:

$ lsblk -D /dev/vda
  • If the Discard is available, you will get information about the disk:

    Result Sample
    NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
    vda         512      512B       2G         0
    └─vda1        0      512B       2G         0
  • If the Discard is unavailable, the returned elements are set to 0:

    Result Sample
    NAME   DISC-ALN DISC-GRAN DISC-MAX DISC-ZERO
    vda           0        0B       0B         0
    └─vda1        0        0B       0B         0

Making Sure the Discard is Available on Windows

On Windows, you cannot check the availability of Discard on each disk.

Use the following command to check that automatic Discard detection is enabled:

fsutil behavior query DisableDeleteNotify
  • If the automatic Discard detection is activated, the command returns the following element:

    Result Sample
    DisableDeleteNotify = 1 (Enabled)
  • If the automatic Discard detection is not activated, the command returns the following element:

    Result Sample
    DisableDeleteNotify = 0 (Disabled)

Configuring and Using Methods of the Discard

We recommend using this method. This method is applied by default to our official images since January 2024.

Launching the Discard Periodically

Method 1: Launching the Discard Periodically on Linux

  1. View the service status with the following command:

    $ systemctl status fstrim.timer

    The command returns the following elements:

    Result Sample
    ● fstrim.timer - Discard unused blocks once a week
       Loaded: loaded (/usr/lib/systemd/system/fstrim.timer; disabled; vendor preset: disabled)
       Active: inactive (dead)
      Trigger: n/a
         Docs: man:fstrim
  2. Activate and configure the task with the following command:

    $ systemctl enable fstrim.timer
  3. Make sure the task is defined with the following command:

    $ systemctl list-timers

    The command returns the following elements:

    Result Sample
    NEXT                         LEFT        LAST                         PASSED       UNIT                         ACTIVATES
    Wed 2023-10-04 14:53:08 UTC  56min left  Wed 2023-10-04 13:27:59 UTC  28min ago    dnf-makecache.timer          dnf-makecache.service
    Thu 2023-10-05 00:00:00 UTC  10h left    n/a                          n/a          unbound-anchor.timer         unbound-anchor.service
    Thu 2023-10-05 12:44:59 UTC  22h left    Wed 2023-10-04 12:44:59 UTC  1h 11min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
    Mon 2023-10-09 00:00:00 UTC  4 days left n/a                          n/a          fstrim.timer                 fstrim.service
    
    4 timers listed.
    Pass --all to see loaded but inactive timers, too.
  4. View the task status with the following command:

    $ systemctl status fstrim.timer

    The command returns the following elements:

    Result Sample
    ● fstrim.timer - Discard unused blocks once a week
       Loaded: loaded (/usr/lib/systemd/system/fstrim.timer; enabled; vendor preset: disabled)
       Active: active (waiting) since Wed 2023-10-04 13:55:44 UTC; 1s ago
      Trigger: Mon 2023-10-09 00:00:00 UTC; 4 days left
         Docs: man:fstrim
    
    oct. 04 13:55:44 ip-10-0-0-00.website.exemple.com systemd[1]: Started Discard unused blocks once a week.

Launching the Discard Periodically on Windows

Windows is able to detect automatically if the disk is compatible with the Discard. A periodical task can be configured in the Disk Management.

  1. In Disk Management, right-click a disk and click Properties.

  2. In the Tools tab, click Optimize.

  3. In the Scheduled optimization section, click Change settings.

  4. Customize the frequency.

    It is recommended to define a weekly frequency.

  5. Click OK.

Method 2: Launching the Discard Manually

Launching the Discard Manually on Linux

You can launch the Discard manually at any time on all systems of mounted files with the following command:

fstrim -v --all

The command returns in GiB or in octet the trimmed space on the volume.

Result Sample
/ : 7,9 GiB (8507092992 octets) trimmed

Method 3: Configuring the Discard When Mounting a Volume

This command may affect significantly the performances.

Configuring the Discard When Mounting a Volume on Linux

You can configure the Discard when mounting a volume with the following command:

mount -o discard /dev/sda /mnt

Related Page