启用 fstrim.service 的错误消息

启用 fstrim.service 的错误消息

我从去年二月开始运行 Ubuntu 20.04 桌面。

今天我发布了sudo systemctl enable fstrim.service并收到了以下消息:

The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template
units). This means they are not meant to be enabled using systemctl.
 

Possible reasons for having this kind of units are:
• A unit may be statically enabled by being symlinked from another unit's
  .wants/ or .requires/ directory.
• A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
• In case of template units, the unit is meant to be enabled with some
  instance name specified.

然后我检查该服务是否已启用,因此我发出journalctl -fu fstrim并得到了“日志开始于 2022-07-10 星期日 07:55:26 PDT”,随后是 8 月 8 日和 8 月 15 日的事件列表。

最后我发出systemctl status fstrim.service并得到了以下消息:

fstrim.service - Discard unused blocks on filesystems from /etc/fstab
     Loaded: loaded (/lib/systemd/system/fstrim.service; static; vendor preset:>
     Active: inactive (dead)
TriggeredBy: fstrim.timer
       Docs: man:fstrim(8)

因此看起来 fstrim 已在运行,并且我在二月份安装 Ubuntu 时默认启用了它。我的问题是:

(1)上面“sudo systemctl enable fstrim.service”显示的那些消息有什么意义?

(2) 看起来它每周一运行一次。这个频率够高吗?还是太高了?如果需要,我该如何更改修剪频率?

(3)由于它是开箱即用的,是否还有其他建议启用的选项?

答案1

是的。当安装程序看到 SSD 时,fstrim 将自动安装。

  • 上面显示的那些消息有何意义sudo systemctl enable fstrim.service

除了已经显示的原因之外,当服务已运行时也会显示此信息。当服务中已经存在符号链接时,就会触发此信息/etc/systemd/system/multi-user.target.wants/

  • 看起来它每周一运行一次。这个频率够高还是太高了?如果需要,我该如何更改修剪频率?

是的。不是。手册上写道:

频繁运行 fstrim 甚至使用 都mount -o discard可能对劣质 SSD 设备的使用寿命产生负面影响。对于大多数台式机和服务器系统,每周一次的修剪频率就足够了。

并查看fstrim.timer服务。其中有一个“每周”:

$ more /usr/lib/systemd/system/fstrim.timer
[Unit]
Description=Discard unused blocks once a week
Documentation=man:fstrim
ConditionVirtualization=!container
ConditionPathExists=!/etc/initrd-release

[Timer]
OnCalendar=weekly
AccuracySec=1h
Persistent=true
RandomizedDelaySec=6000

[Install]
WantedBy=timers.target
  • 由于它是开箱即用的,是否还有其他建议启用的选项?

不可以。建议不要更改任何一个。

但是除了fstrim.timer提供的功能之外,手册上fstrim还有 4 个选项可以控制它的功能fstrim

默认情况下,fstrim 将丢弃文件系统中所有未使用的块。可以使用选项根据范围或大小修改此行为,如下所述。

它所指的选项是:

-o, --offset offset 文件系统中开始搜索要丢弃的空闲块的字节偏移量。默认值为零,从文件系统的开头开始。

   -l, --length length
       The number of bytes (after the starting point) to search for free
       blocks to discard. If the specified value extends past the end of
       the filesystem, fstrim will stop at the filesystem size boundary.
       The default value extends to the end of the filesystem.

   -I, --listed-in list
       Specifies a colon-separated list of files in fstab or kernel
       mountinfo format. All missing or empty files are silently ignored.
       The evaluation of the list stops after first non-empty file. For
       example:

       --listed-in /etc/fstab:/proc/self/mountinfo.

 -m, --minimum minimum-size
       Minimum contiguous free range to discard, in bytes. (This value is
       internally rounded up to a multiple of the filesystem block size.)
       Free ranges smaller than this will be ignored and fstrim will
       adjust the minimum if it’s smaller than the device’s minimum, and
       report that (fstrim_range.minlen) back to userspace. By increasing
       this value, the fstrim operation will complete more quickly for
       filesystems with badly fragmented freespace, although not all
       blocks will be discarded. The default value is zero, discarding
       every free block.

相关内容