编辑
2024-01-08
工作知识
0
请注意,本文编写于 515 天前,最后修改于 451 天前,其中某些信息可能已经过时。

目录

磁盘速度太慢
ext文件系统的模式
注意的配置
设置
参考链接

磁盘速度太慢

在使用服务器编译代码的时候,因为最近有一个组raid的过程,所以使用的空间是格式化过的。空间虽然大了,但是编译速度却下降很多,十分苦恼。

/dev/sdc1 7.3T 328G 6.6T 5% /root/public-workspace

主要原因是格式化时是直接使用mkfs.ext4命令格式,所以它默认带数据日志的。

ext文件系统的模式

ext4 支持多个模式

  1. Writeback 模式

Data ordering is not preserved, data may be written into the main file system after its metadata has been committed to the journal.

数据和日志写入主文件,但是无顺序的 2. Ordered 模式

All data are forced directly out to the main file system prior to its metadata being committed to the journal.

数据在写日志之前进入主文件

  1. Journal 模式

All data are committed into the journal prior to being written into the main file system. Enabling this mode will disable delayed allocation and O_DIRECT support.

所有数据到主文件都是在日志之后

注意的配置

  1. norecovery noload

Don't load the journal on mounting. Note that if the filesystem was not unmounted cleanly, skipping the journal replay will lead to the filesystem containing inconsistencies that can lead to any number of problems. 挂载时不加载日志,但是如果文件系统卸载不干净的时候将会导致文件系统的各类问题。

  1. commit=nrsec

Ext4 can be told to sync all its data and metadata every 'nrsec' seconds. The default value is 5 seconds. This means that if you lose your power, you will lose as much as the latest 5 seconds of work (your filesystem will not be damaged though, thanks to the journaling). This default value (or any low value) will hurt performance, but it's good for data-safety. Setting it to 0 will have the same effect as leaving it at the default (5 seconds). Setting it to very large values will improve performance. 设置commit的时间,默认5s,如果设置提交时间太短,则影响性能,设置时间过长可提高性能,但是异常断电的时候会丢最近nrsec的内容

设置

根据上面的介绍,我可以有两个方式

  1. 设置提交日志的时间 (更稳妥)
  2. 关闭日志 (更激进)

对于1,我选择60秒同步一次日志,如下设置(/etc/fstab)

LABEL=public-workspace /root/public-workspace ext4 nofail,auto,noatime,data=ordered,commit=60 0 0

对于2,我选择关闭日志,如下设置

LABEL=public-workspace /root/public-workspace ext4 nofail,auto,noatime,noload,norecovery 0 0

最后我选择2,选择权在自己手上,风险自己能把握住就行。

参考链接

https://www.kernel.org/doc/Documentation/filesystems/ext4.txt