大网数据广告活动
服务器运维问答

fstrim is very slow on xfs and always return same value unlike ext4

· 52CE 我爱测

I just noticed if I do time fstrim /<some ext4>; time fstrim /<some ext4> the 2nd call usually print 0 bytes trimmed and finished immediately. However if I do same thing on XFS, 2 of the calls are taking exactly same time and pri…

问题原文

原帖链接 · Wang · CC BY-SA 4.0

I just noticed if I do time fstrim /<some ext4>; time fstrim /<some ext4> the 2nd call usually print 0 bytes trimmed and finished immediately. However if I do same thing on XFS, 2 of the calls are taking exactly same time and print exactly same amount of trimmed bytes. This makes me wonder does the trim really worked? If yes, is there any flag I can turn on to make the XFS not re-trim the already trimmed blocks?

I used all default settings to mount xfs.

已采纳解答

原帖链接 · Don Zoomik · CC BY-SA 4.0

Ext4 caches extents that have already been trimmed in memory and doesn't retrim them until reboot.

XFS does not cache this information and retrims everything on every fstrim start.

Source:

Fstrim calls FITRIM IOCTL on file system that eventually calls into a FS specific internal function: https://github.com/util-linux/util-linux/blob/master/sys-utils/fstrim.c#L120

I omitted several in-between functions...

Ext4 driver checks memory structures if the range has already been discarded. If not, it tries to discard it and sets it as already discarded, preventing further discards until system is rebooted: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/ext4/mballoc.c?h=v6.0#n6442

XFS internal function has no such check and just discards everything: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/xfs/xfs_discard.c?h=v6.0#n151

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2022-10-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。