文件系统选项之noatime、nodiratime

1、关于文件的几个时间

我们通过stat命令查看文件的信息,

[root@CentOS-6-5 /home]# stat a
  File: `a'
  Size: 12552     	Blocks: 32         IO Block: 4096   regular file
Device: 802h/2050d	Inode: 1177548     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-10-23 16:54:55.259130660 +0800
Modify: 2019-10-23 16:54:55.259130660 +0800
Change: 2019-10-23 16:54:55.259130660 +0800

其中有三个时间,
access:文件上次被读取的时间,文件被读取,执行,打开都会触发更新
modify:文件上次被修改的时间,
change:文件上次权限属主被修改的时间

2、noatime选项

对于文件系统,有时候为了提供性能,会设置noatime选项,这个选项的意思是不更新文件的access时间。所以在读取、打开、执行文件时都不会修改,这在一定程度上就降低了系统的IO,尤其是对于读取居多的服务器。

未设置noatime

[root@CentOS-6-5 /home]# mount | grep sda2
/dev/sda2 on / type ext4 (rw)
[root@CentOS-6-5 /home]# stat a
  File: `a'
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d	Inode: 1177548     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-10-23 16:54:55.259130660 +0800
Modify: 2019-10-26 22:16:49.186557777 +0800
Change: 2019-10-26 22:16:49.186557777 +0800
[root@CentOS-6-5 /home]# cat a
hello
[root@CentOS-6-5 /home]# stat a
  File: `a'
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d	Inode: 1177548     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-10-26 22:25:14.722556455 +0800
Modify: 2019-10-26 22:16:49.186557777 +0800
Change: 2019-10-26 22:16:49.186557777 +0800

此时文件系统未设置noatime,读取文件后,文件的access时间发生更新。

现在我们通过remount添加noatime选项,

[root@CentOS-6-5 /home]# mount -o remount,noatime /dev/sda2
[root@CentOS-6-5 /home]# mount  | grep sda2
/dev/sda2 on / type ext4 (rw,noatime)
[root@CentOS-6-5 /home]# stat a
  File: `a'
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d	Inode: 1177548     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-10-26 22:25:14.722556455 +0800
Modify: 2019-10-26 22:16:49.186557777 +0800
Change: 2019-10-26 22:16:49.186557777 +0800
[root@CentOS-6-5 /home]# cat a
hello
[root@CentOS-6-5 /home]# stat a
  File: `a'
  Size: 6         	Blocks: 8          IO Block: 4096   regular file
Device: 802h/2050d	Inode: 1177548     Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2019-10-26 22:25:14.722556455 +0800
Modify: 2019-10-26 22:16:49.186557777 +0800
Change: 2019-10-26 22:16:49.186557777 +0800

可见,添加noatime后,执行同样的读取文件操作,文件的access时间并没有更新,因此就可以节约大量的IO,提供系统性能。

3、nodiratime选项

noatime是对于文件而言,那对于目录呢。其实在linux上,目录也是一种文件,毕竟zai linux上everything is a file。因此当设置noatime时,对于目录也是一样的效果。如果想要单独对目录有此效果,就可以使用nodiratime。因此noatime设置后,就无需再设置nodiratime。

这是一个针对 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、付费专栏及课程。

余额充值