当前位置: 首页>>技术问答>>正文


如何启用Trim?

ubuntuer 技术问答 , , 去评论

问题描述

我听说,Ubuntu 14.04默认启用Trim。怎么做?通过向ext4安装选项添加丢弃选项或运行cron-job?

Trim的默认选项是否会自动与标准Ubuntu-system加密的LVM和加密层兼容?

很高兴看到一些有关这方面的细节。

最佳解决办法

声称14.04默认启用修剪只是故事的1/2。

Will the default options for TRIM be automatically compatible with the LVM and encryption layers of the standard ubuntu-system encryption?

LVM是一个容器,不是文件系统,所以这不是问题。


文章值得一读:

Blueprint

SSDs need to be TRIMed, i. e. they need to be told which blocks the OS considers as “unused” (i. e. from deleted files). Withouth this, the write speed on SSDs becomes unbearably slow over time.

http://wiki.ubuntuusers.de/SSD/TRIM (German) explains the details, but this kind of housekeeping really should happen by default. There are two approaches to this, immediately marking the blocks as unused when deleting a file (“discard” mount option), or calling fstrim regularly. discard slows down deletion while a cronjob occasionally puts some potentially unexpected IO load on the machine, so this discussion is primarily about deciding which approach we want to do by default.

I (Martin Pitt) think that a cron approach is better. If we go with this we need to discuss when and how to run this:

  • Whats a reasonable interval (weekly/monthly/etc.)
  • How to detect devices/partitions which need trimming (/proc/mounts, hdparm -I, not mounted with “discard”, etc.)

德语中该链接的结论:

  • 每周一次的cron工作,因为丢弃将导致太多的性能损失。


在Ubuntu 14.04中,只有英特尔和三星固态硬盘默认启用TRIM,因为一些廉价的固态硬盘甚至可以在运行TRIM时自行清理。 /etc/cron.weekly/fstrim在14.04 beta 2上的内容:

#!/bin/sh
# call fstrim-all to trim all mounted file systems which support it
set -e

# This only runs on Intel and Samsung SSDs by default, as some SSDs with faulty
# firmware may encounter data loss problems when running fstrim under high I/O
# load (e. g.  https://launchpad.net/bugs/1259829). You can append the
# --no-model-check option here to disable the vendor check and run fstrim on
# all SSD drives.
exec fstrim-all

这并不意味着TRIM只应与三星和英特尔固态硬盘一起使用,但为了避免遇到问题,这是目前的默认选项。请注意,如果您已经知道您的SSD可以处理TRIM,则可以通过编辑上面的/etc/cron.weekly/fstrim文件并将--no-model-check选项添加到最后一行来绕过供应商检查:

exec fstrim-all --no-model-check

或者,您可以通过其他几种方式手动安排TRIM。 How to do it manual

资料来源:webupd8

  • 但并非所有SSD都受支持。我不是顺便说一下(刚检查过)

  • LSI.com在此PDF中有一系列兼容的SSD。


修剪的方法是使用以下命令:

sudo fstrim -v /

这也是Ubuntu如何做到这一点:通过创建一个每周执行此操作的cronjob。

从我自己的系统执行:

rinzwind@schijfwereld:~$ sudo fstrim -v /
[sudo] password for rinzwind: 
/: 93283299328 bytes were trimmed
rinzwind@schijfwereld:~$ 

花一点时间,直到完成后才显示任何进度。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/2839.html,未经允许,请勿转载。

相关文章