如题,我们需要同时设置noatime和nodiratime吗?很多资料都提到要同时设置noatime和nodiratime,但我们看mount(2)关于参数的描述:
MS_NOATIME
Do not update access times for (all types of) files on this file
system.
MS_NODIRATIME
Do not update access times for directories on this file system.
This flag provides a subset of the functionality provided by
MS_NOATIME; that is, MS_NOATIME implies MS_NODIRATIME.
Do not update access times for (all types of) files on this file
system.
MS_NODIRATIME
Do not update access times for directories on this file system.
This flag provides a subset of the functionality provided by
MS_NOATIME; that is, MS_NOATIME implies MS_NODIRATIME.
如何理解这里的“(all types of) files”,目录是否作为文件的一类?
还是看看内核源码的相关内容,在文件fs/inode.c中有个touch_atime函数:
void
touch_atime(
struct
vfsmount
*
mnt,
struct
dentry
*
dentry)
{
/* ... */
if (inode -> i_flags & S_NOATIME)
return ;
if (IS_NOATIME(inode))
return ;
if ((inode -> i_sb -> s_flags & MS_NODIRATIME) && S_ISDIR(inode -> i_mode))
return ;
{
/* ... */
if (inode -> i_flags & S_NOATIME)
return ;
if (IS_NOATIME(inode))
return ;
if ((inode -> i_sb -> s_flags & MS_NODIRATIME) && S_ISDIR(inode -> i_mode))
return ;
可以看到,一旦NOATIME标志位设置,NODIRATIME就不再被处理了。
而且Andrew Morton同学也说了:"noatime is a superset of nodiratime, btw."
好了,大家知道该怎么做了吧。