-->
  • Recent Articles

    How to stop or change schedule for fstrim process on ubuntu/mint ?

     How to stop or change schedule for fstrim process on ubuntu/mint ?

    fstrim is used on a mounted filesystem to discard (trim) blocks which are not in use by the filesystem. This is especially useful for solid-state drives, SSDs and thin-provisioned storage. fstrim is enabled by default and runs weekly, every Monday 00:00:00.

    fstrim scans the filesystem and sends 'UNMAP' commands for each unused block it finds.

    Consequently fstrim is only needed if:

     1. the underlying device is thin-provisioned

    2. the filesystem doesn't use UNMAP internally

    fstrim is used mainly for SSD rather than HDD. It would be logical to assume that running this on a HDD could cause unexpected results. fstrim also imapcts the performance during its runtime and adversly effect the lifespan of old disk. fstrim (or TRIM/DISCARD in general) only makes a difference to a thin-provisioned system if the system itself is over-provisioned. If the system has allocated enough space for each LUN (thin-provisioned or not) issuing TRIM commands is not required.

    1. Validate whether UNMAP is supported on the filesystem

    To validate whether the filesystem supports UNMAP the discard max value reported by 'lsblk -D' can be looked at. A discard_max_bytes value of 0 means that the device does not support discard functionality. The same can be achieved by checking sysfs directly:

     

    # cat /sys/block/sda/queue/discard_max_bytes 

    0


    OR


    Another method to check if fstrim/UNMAP is or is not supported on a filesystem is to check the 'fstrim -v' output. If fstrim/UNMAP is not supported:

    'fstrim -v /mnt/xzy' will return

    'fstrim: /mnt/xyz: the discard operation is not supported'.

     

    If it is supported fstrim will discard unused blocks and report back:

    'fstrim -v /mnt/ /mnt: 12.3 Gib (number_of_ bytes) trimmed.


    2. Check the fstrim service Status.

    systemctl status fstrim

    fstrim status

    3. Check the long running Jobs.

    root@unisonunix:~# systemd-analyze blame

    root@unisonunix:~# systemctl list-jobs

    fstrim

    4. Check fstrim logs

    root@unisonunix:~# journalctl --no-pager | grep fstrim

    fstrim logs

    5. Change the scheduler timer of fstrim. Edit the file "/lib/systemd/system/fstrim.timer" and Change the "OnCalendar=weekly" Value.


    6. Disable fstrim:

    The fstrim.timer is scheduled to activate the fstrim.service every Monday 00:00:00. fstrim.service then executes '/usr/sbin/fstrim -av'.

     To stop/disable fstrim:

    systemctl stop fstrim.timer

    systemctl disable fstrim.timer

    No comments