需要同时设置 noatime 和 nodiratime 吗?

 

需要同时设置 noatime 和 nodiratime 吗?


      相信对性能、优化这些关键字有兴趣的朋友都知道在 Linux 下面挂载文件系统的时候设置 noatime 可以显著提高文件系统的性能。默认情况下,Linux ext2/ext3 文件系统在文件被访问、创建、修改等的时候记录下了文件的一些时间戳,比如:文件创建时间、最近一次修改时间和最近一次访问时间。因为系统运行的时候要访问大量文件,如果能减少一些动作(比如减少时间戳的记录次数等)将会显著提高磁盘 IO 的效率、提升文件系统的性能。Linux 提供了 noatime 这个参数来禁止记录最近一次访问时间戳。

      给文件系统挂载的时候加上 noatime 参数能大幅提高文件系统性能:

# vi /etc/fstab
/dev/sda1        /       [separator]       ext3     defaults,noatime,errors=remount-ro 0 0
devpts           /dev/pts      devpts   gid=5,mode=620             0 0
proc             /proc         proc     defaults                   0 0
/dev/sda2        swap          swap     defaults,noatime           0 0

修改设置后只需要重新挂载文件系统、不需要重启就可以应用新设置:

# mount -o remount /
# mount
/dev/sda1 on / type ext3 (rw,noatime,errors=remount-ro)
proc on /proc type proc (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

      网上很多资料都提到要同时设置 noatime 和 nodiratime,不知道这个结论来自哪里,其实不需要像设置 noatime 那样设置 nodiratime,最可靠的资料应该是源代码,VPSee 查了一下源代码,发现在内核源代码 linux-2.6.33/fs/inode.c 文件里有一个 touch_atime 函数,可以看出如果 inode 的标记位是 NOATIME 的话就直接返回了,根本就走不到 NODIRATIME 那里去,所以只设置 noatime 就可以了,不必再设置 nodiratime.

void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
1405{
1406        struct inode *inode = dentry->d_inode;
1407        struct timespec now;
1408
1409        if (inode->i_flags & S_NOATIME)
1410                return;
1411        if (IS_NOATIME(inode))
1412                return;
1413        if ((inode->i_sb->s_flags & MS_NODIRATIME) && S_ISDIR(inode->i_mode))
1414                return;
1415
1416        if (mnt->mnt_flags & MNT_NOATIME)
1417                return;
1418        if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))
1419                return;
...
1435}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这是一个针对 rk3288 平台的 Android 系统的 fstab 文件,它定义了系统中各个分区的挂载点、文件系统类型和挂载选项。文件名中的 forceencrypt.bootmode.emmc 暗示了该系统启用了强制加密功能,并且使用了 eMMC 存储设备。以下是该文件的内容: 复制 # Android fstab file for rk3288 emmc devices # # The filesystem that contains the filesystem checker binary (typically /system) cannot # specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK # mount point fstype device [device2] [options] [flags] # boot, recovery, and cache are automatically set up with defaults /dev/block/platform/ff0f0000.dwmmc/by-name/system /system ext4 ro,barrier=1,discard wait /dev/block/platform/ff0f0000.dwmmc/by-name/userdata /data ext4 noatime,nodiratime,nosuid,nodev,noauto_da_alloc,discard,errors=panic wait,check,encryptable=footer # The following entry is optional, but can be used to specify an # alternate resource file to be used instead of the compiled-in # defaults: # /system/etc/recovery.fstab # A/B OTA support /dev/block/platform/ff0f0000.dwmmc/by-name/system_other /system ext4 ro,barrier=1,discard wait,slotselect /dev/block/platform/ff0f0000.dwmmc/by-name/userdata_other /data ext4 noatime,nodiratime,nosuid,nodev,noauto_da_alloc,discard,errors=panic wait,check,encryptable=footer,slotselect # /cache partition is optional, wipe cache if needed /dev/block/platform/ff0f0000.dwmmc/by-name/cache /cache ext4 noatime,nodiratime,nosuid,nodev,noauto_da_alloc,discard wait,check # /vendor partition is optional, mount if present /dev/block/platform/ff0f0000.dwmmc/by-name/vendor /vendor ext4 ro,barrier=1,noauto_da_alloc wait # /misc partition is optional, mount if present /dev/block/platform/ff0f0000.dwmmc/by-name/misc /misc emmc defaults defaults # /metadata partition is optional, mount if present /dev/block/platform/ff0f0000.dwmmc/by-name/metadata /metadata ext4 noatime,nodiratime,nosuid,nodev,noauto_da_alloc,discard wait,check
06-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值