From Fedora Project Wiki
 
(9 intermediate revisions by 2 users not shown)
Line 24: Line 24:
<br><br>
<br><br>
Enabling fstrim.timer will cause fstrim.service to execute weekly, which in turn executes `/usr/sbin/fstrim --fstab --verbose --quiet`
Enabling fstrim.timer will cause fstrim.service to execute weekly, which in turn executes `/usr/sbin/fstrim --fstab --verbose --quiet`
The fstrim command informs physical storage device's firmware about unused blocks. And this hinting can make wear leveling and block erasure more efficient.
The fstrim command informs storage devices (physical and virtual) about unused blocks. This hinting can make wear leveling and block erasure more efficient, and improve utilization of free logical extents on LVM thin provisioning by returning them to the thin pool.


== Owner ==
== Owner ==
Line 52: Line 52:
CLOSED as NEXTRELEASE -> change is completed and verified and will be delivered in next release under development
CLOSED as NEXTRELEASE -> change is completed and verified and will be delivered in next release under development
-->
-->
* Tracker bug: <will be assigned by the Wrangler>
* Tracker bug: [https://bugzilla.redhat.com/show_bug.cgi?id=1790580 #1790580]
* Release notes tracker: <will be assigned by the Wrangler>
* Release notes tracker: [https://pagure.io/fedora-docs/release-notes/issue/430 #430]


== Detailed Description ==
== Detailed Description ==
Line 97: Line 97:


== How To Test ==
== How To Test ==
<!-- This does not need to be a full-fledged document. Describe the dimensions of tests that this change implementation is expected to pass when it is done.  If it needs to be tested with different hardware or software configurations, indicate them.  The more specific you can be, the better the community testing can be.
<!-- REQUIRED FOR SYSTEM WIDE CHANGES -->
The low level function of systemd timers, fstrim.service, and fstrim command are well understood and tested already, all Fedora needs to test is that the timer is enabled following clean installation and upgrades:<br><br>
The low level function of systemd timers, fstrim.service, and fstrim command are well understood and tested already, all Fedora needs to test is that the timer is enabled following clean installation and upgrades:<br><br>
Preliminaries:
Preliminaries:
* Clean install Fedora 32, any edition or spin; or
* Clean install Fedora 32, any edition or spin; or
* Upgrade from Fedora 30 or Fedora 31, any edition or spin, to Fedora 32
* Upgrade from Fedora 30/31, any edition or spin, to Fedora 32; or
* Fedora 30/31 users can enable this feature: `sudo systemctl enable fstrim.timer`
Confirm:
Confirm:
* Run `sudo systemctl list-timers`
* Run `sudo systemctl list-timers`
Line 111: Line 110:
{{code|Dec 18 13:48:54 fmac.local systemd[1]: fstrim.service: Succeeded.}}
{{code|Dec 18 13:48:54 fmac.local systemd[1]: fstrim.service: Succeeded.}}


Full example on a device with an SSD and filesystem supporting trim:<br>
Full example on a device with NVMe drive and filesystems supporting trim:<br>
<pre>
<pre>
$ sudo systemctl status fstrim.service
$ systemctl status fstrim.service
● fstrim.service - Discard unused blocks on filesystems from /etc/fstab
● fstrim.service - Discard unused blocks on filesystems from /etc/fstab
   Loaded: loaded (/usr/lib/systemd/system/fstrim.service; static; vendor preset: disabled)
   Loaded: loaded (/usr/lib/systemd/system/fstrim.service; static; vendor preset: disabled)
   Active: inactive (dead) since Wed 2019-12-18 13:48:54 MST; 15min ago
   Active: inactive (dead) since Mon 2020-02-10 00:01:06 MST; 46min ago
     Docs: man:fstrim(8)
     Docs: man:fstrim(8)
   Process: 3870 ExecStart=/usr/sbin/fstrim --fstab --verbose --quiet (code=exited, status=0/SUCCESS)
   Process: 34876 ExecStart=/usr/sbin/fstrim --fstab --verbose --quiet (code=exited, status=0/SUCCESS)
  Main PID: 3870 (code=exited, status=0/SUCCESS)
  Main PID: 34876 (code=exited, status=0/SUCCESS)
       CPU: 1.387s
       CPU: 2.119s


Dec 18 13:48:48 fmac.local systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Feb 10 00:00:19 flap.local systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Dec 18 13:48:54 fmac.local fstrim[3870]: /: 32 GiB (34409328640 bytes) trimmed on /dev/sda4
Feb 10 00:01:06 flap.local fstrim[34876]: /boot/efi: 41.4 MiB (43448320 bytes) trimmed on /dev/nvme0n1p2
Dec 18 13:48:54 fmac.local systemd[1]: fstrim.service: Succeeded.
Feb 10 00:01:06 flap.local fstrim[34876]: /: 171.7 GiB (184363905024 bytes) trimmed on /dev/nvme0n1p7
Dec 18 13:48:54 fmac.local systemd[1]: Started Discard unused blocks on filesystems from /etc/fstab.
Feb 10 00:01:06 flap.local systemd[1]: fstrim.service: Succeeded.
Dec 18 13:48:54 fmac.local systemd[1]: fstrim.service: Consumed 1.387s CPU time.
Feb 10 00:01:06 flap.local systemd[1]: Started Discard unused blocks on filesystems from /etc/fstab.
Feb 10 00:01:06 flap.local systemd[1]: fstrim.service: Consumed 2.119s CPU time.
$
</pre>
</pre>
<br>
<br>
Line 135: Line 136:


This does not affect all storage. Only file systems listed in fstab are affected.  
This does not affect all storage. Only file systems listed in fstab are affected.  
To disable this feature:
`sudo systemctl disable fstrim.timer`
Advanced customizations:


Like any systemd unit customization, the user shouldn't directly modify /usr units. Example: `sudo systemctl edit fstrim.service` and insert a modified ExecStart line using --all instead of --fstab, which then creates /etc/systemd/system/fstrim.service.d containing override.conf; reboot or `systemctl daemon-reload`; and now fstrim is applied to all mounted file systems. For more information see:<br>
Like any systemd unit customization, the user shouldn't directly modify /usr units. Example: `sudo systemctl edit fstrim.service` and insert a modified ExecStart line using --all instead of --fstab, which then creates /etc/systemd/system/fstrim.service.d containing override.conf; reboot or `systemctl daemon-reload`; and now fstrim is applied to all mounted file systems. For more information see:<br>
https://www.freedesktop.org/software/systemd/man/systemctl.html<br>
https://www.freedesktop.org/software/systemd/man/systemctl.html<br>
https://www.freedesktop.org/software/systemd/man/systemd.unit.html
https://www.freedesktop.org/software/systemd/man/systemd.unit.html
In virtual machines, fstrim.service will have no effect unless the virtual block device advertises support for discards. In virt-manager, this is in the block device's Advanced options>Performance options>Discard mode: unmap
Starting with util-linux 2.35, which will appear in fc32, the fstrim.service contains:
ConditionVirtualization=!container
So it will not run in containers.
Issues arrise with VM's. By default virt-manager qemu-kvm VMs ignores discards. The fstrim.service unit will still succeed but there will be a kernel message indicating the failure:
{{code|[  122.895923] localhost.localdomain kernel: blk_update_request: operation not supported error, dev vda, sector 206856170 op 0x3:(DISCARD) flags 0x0 phys_seg 2 prio class 0}}
If discards are set to unmap in the VM for supported storage, the fstrim command will pass through to underlying backing storage; if the backing storage is raw or qcow2, it will become a sparse file.


== Dependencies ==
== Dependencies ==
Line 162: Line 180:
fstrim.timer is enabled by default, and runs fstrim.service weekly. This service executes `/usr/sbin/fstrim --fstab --verbose --quiet` See `man fstrim` for details.
fstrim.timer is enabled by default, and runs fstrim.service weekly. This service executes `/usr/sbin/fstrim --fstab --verbose --quiet` See `man fstrim` for details.


[[Category:ChangeAnnounced]]
[[Category:ChangeAcceptedF32]]
<!-- When your change proposal page is completed and ready for review and announcement -->
<!-- When your change proposal page is completed and ready for review and announcement -->
<!-- remove Category:ChangePageIncomplete and change it to Category:ChangeReadyForWrangler -->
<!-- remove Category:ChangePageIncomplete and change it to Category:ChangeReadyForWrangler -->

Latest revision as of 22:50, 13 April 2020


Enable fstrim.timer by default

Summary



Enabling fstrim.timer will cause fstrim.service to execute weekly, which in turn executes /usr/sbin/fstrim --fstab --verbose --quiet The fstrim command informs storage devices (physical and virtual) about unused blocks. This hinting can make wear leveling and block erasure more efficient, and improve utilization of free logical extents on LVM thin provisioning by returning them to the thin pool.

Owner

Current status

Detailed Description

Over time, some users experience slow downs in certain flash storage devices. This might be alleviated by issuing a periodic fstrim command to the mounted file system. Devices and file systems that don't support fstrim are unaffected.

By enabling the existing fstrim.timer systemd unit file by default, will cause weekly execution of the fstrim.service. This service acts only on mounted filesystems listed in fstab. On supported hardware (e.g. most SD Card, SSD, and NVMe drives), LVM thin provisioned storage, and file systems (e.g. ext4, XFS, Btrfs, f2fs, VFAT), fstrim will inform underlying physical storage device's firmware about unused blocks. This hinting can make wear leveling and block erasure more efficient.

The timer will execute Monday at 00:00 local time. If the system is inactive at this time, it will be run immediately upon becoming active again (upon wake from suspend, during or very soon after boot).

Some devices do not support "queued trim" and there may be a brief (seconds) pause as the drive firmware acts upon command issuance. It's expected most users won't notice this.

Benefit to Fedora

This is an optimization to the storage stack, and may help improve performance and wear leveling for some devices. On LVM thin provisioned stacks, unused LV extents will be returned to the thin pool, reducing the likelihood of pool exhaustion.

In a way, this is overdue on Fedora, as it's been the default behavior on other distributions for a while (at least Ubuntu and openSUSE). At least it has been well tested.

It also builds on prior Fedora work to enable TRIM passthrough on LUKS devices. [1]

[1] https://fedoraproject.org/wiki/Changes/EnableTrimOnDmCrypt

Scope

  • Proposal owners:

Upon approval, submit a PR for fedora-release, modifying 90-default.preset to enable fstrim.timer

  • Other developers:

fstrim.timer is provided by util-linux, notify util-linux maintainer
https://bugzilla.redhat.com/show_bug.cgi?id=1785041

  • Release engineering: #9116
  • Policies and guidelines: N/A
  • Trademark approval: N/A

Upgrade/compatibility impact

fstrim.timer will be enabled on upgrade. An upgraded system should exhibit the same behaviors as a clean installed system.

How To Test

The low level function of systemd timers, fstrim.service, and fstrim command are well understood and tested already, all Fedora needs to test is that the timer is enabled following clean installation and upgrades:

Preliminaries:

  • Clean install Fedora 32, any edition or spin; or
  • Upgrade from Fedora 30/31, any edition or spin, to Fedora 32; or
  • Fedora 30/31 users can enable this feature: sudo systemctl enable fstrim.timer

Confirm:

  • Run sudo systemctl list-timers
  • Confirm fstrim.timer is listed under UNITS, and is next scheduled for Monday 00:00:00
  • Anytime following the listed NEXT date+time, run sudo systemctl status fstrim.timer

Example, should apply in all cases:
Dec 18 13:48:54 fmac.local systemd[1]: fstrim.service: Succeeded.

Full example on a device with NVMe drive and filesystems supporting trim:

$ systemctl status fstrim.service
● fstrim.service - Discard unused blocks on filesystems from /etc/fstab
   Loaded: loaded (/usr/lib/systemd/system/fstrim.service; static; vendor preset: disabled)
   Active: inactive (dead) since Mon 2020-02-10 00:01:06 MST; 46min ago
     Docs: man:fstrim(8)
  Process: 34876 ExecStart=/usr/sbin/fstrim --fstab --verbose --quiet (code=exited, status=0/SUCCESS)
 Main PID: 34876 (code=exited, status=0/SUCCESS)
      CPU: 2.119s

Feb 10 00:00:19 flap.local systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Feb 10 00:01:06 flap.local fstrim[34876]: /boot/efi: 41.4 MiB (43448320 bytes) trimmed on /dev/nvme0n1p2
Feb 10 00:01:06 flap.local fstrim[34876]: /: 171.7 GiB (184363905024 bytes) trimmed on /dev/nvme0n1p7
Feb 10 00:01:06 flap.local systemd[1]: fstrim.service: Succeeded.
Feb 10 00:01:06 flap.local systemd[1]: Started Discard unused blocks on filesystems from /etc/fstab.
Feb 10 00:01:06 flap.local systemd[1]: fstrim.service: Consumed 2.119s CPU time.
$


Regardless of configuration, there should be no errors.

User Experience

Most users will not notice the change. Some will notice improved performance of flash storage devices, and more efficient use of thinly provisioned storage.

This does not affect all storage. Only file systems listed in fstab are affected.

To disable this feature: sudo systemctl disable fstrim.timer

Advanced customizations:

Like any systemd unit customization, the user shouldn't directly modify /usr units. Example: sudo systemctl edit fstrim.service and insert a modified ExecStart line using --all instead of --fstab, which then creates /etc/systemd/system/fstrim.service.d containing override.conf; reboot or systemctl daemon-reload; and now fstrim is applied to all mounted file systems. For more information see:
https://www.freedesktop.org/software/systemd/man/systemctl.html
https://www.freedesktop.org/software/systemd/man/systemd.unit.html

In virtual machines, fstrim.service will have no effect unless the virtual block device advertises support for discards. In virt-manager, this is in the block device's Advanced options>Performance options>Discard mode: unmap

Starting with util-linux 2.35, which will appear in fc32, the fstrim.service contains: ConditionVirtualization=!container So it will not run in containers.

Issues arrise with VM's. By default virt-manager qemu-kvm VMs ignores discards. The fstrim.service unit will still succeed but there will be a kernel message indicating the failure:

[ 122.895923] localhost.localdomain kernel: blk_update_request: operation not supported error, dev vda, sector 206856170 op 0x3:(DISCARD) flags 0x0 phys_seg 2 prio class 0

If discards are set to unmap in the VM for supported storage, the fstrim command will pass through to underlying backing storage; if the backing storage is raw or qcow2, it will become a sparse file.

Dependencies

None

Contingency Plan

  • Contingency mechanism: Owner will revert the change
  • Contingency deadline: final freeze
  • Blocks release? No
  • Blocks product? No

Documentation

man fstrim


Release Notes

fstrim.timer is enabled by default, and runs fstrim.service weekly. This service executes /usr/sbin/fstrim --fstab --verbose --quiet See man fstrim for details.