Relative atime
cover Relative atime
There was enough interest in the relative atime patches that I went ahead and implemented support in the mount command as well, and cleaned up the patches for inclusion. Relative atime only updates the atime if the previous atime is older than the mtime or ctime. It's like noatime, but useful for applications like mutt that need to know whether a file has been read since it was last modified.
-VAL
PATCH 1/1 Relative atime - kernel side
Add "relatime" (relative atime) support. Relative atime only updates the atime if the previous atime is older than the mtime or ctime. Like noatime, but useful for applications like mutt that need to know when a file has been read since it was last modified.
--- fs/inode.c | 11 ++++++++++- fs/namespace.c | 5 ++++- include/linux/fs.h | 1 + include/linux/mount.h | 1 + 4 files changed, 16 insertions(+), 2 deletions(-)
fs/inode.c +10 -1
@@ -1200,7 +1200,16 @@ void touch_atime(struct vfsmount *mnt, sreturn ; now =current_fs_time (inode->i_sb); -if (!timespec_equal (&inode->i_atime, &now)) { +if (timespec_equal (&inode->i_atime, &now)) +return ; +/* +* With relative atime, only update atime if the previous +* atime is earlier than either the ctime or mtime. +*/ +if (!mnt || + !(mnt->mnt_flags &MNT_RELATIME ) || + (timespec_compare (&inode->i_atime, &inode->i_mtime) <0 ) || + (timespec_compare (&inode->i_atime, &inode->i_ctime) <0 )) { inode->i_atime = now;mark_inode_dirty_sync (inode); }
fs/namespace.c +4 -1
@@ -376,6 +376,7 @@ static int show_vfsmnt(struct seq_file * { MNT_NOEXEC, ",noexec" }, { MNT_NOATIME, ",noatime" }, { MNT_NODIRATIME, ",nodiratime" }, + { MNT_RELATIME, ",relatime" }, { 0, NULL } };struct proc_fs_info *fs_infop;
@@ -1413,9 +1414,11 @@ long do_mount(char *dev_name, char *dir_ mnt_flags |=MNT_NOATIME ;if (flags &MS_NODIRATIME ) mnt_flags |=MNT_NODIRATIME ; +if (flags &MS_RELATIME ) + mnt_flags |=MNT_RELATIME ; flags &= ~(MS_NOSUID |MS_NOEXEC |MS_NODEV |MS_ACTIVE | -MS_NOATIME |MS_NODIRATIME ); +MS_NOATIME |MS_NODIRATIME |MS_RELATIME );/* ... and get the mountpoint */ retval =path_lookup (dir_name,LOOKUP_FOLLOW , &nd);
include/linux/fs.h +1 -0
@@ -119,6 +119,7 @@ extern int dir_notify_enable;#define MS_PRIVATE (1<<18)/* change to private */ #define MS_SLAVE (1<<19)/* change to slave */ #define MS_SHARED (1<<20)/* change to shared */ +#define MS_RELATIME (1<<21)/* Update atime relative to mtime/ctime. */ #define MS_ACTIVE (1<<30)#define MS_NOUSER (1<<31)
include/linux/mount.h +1 -0
@@ -27,6 +27,7 @@ struct namespace;#define MNT_NOEXEC 0x04#define MNT_NOATIME 0x08#define MNT_NODIRATIME 0x10 +#define MNT_RELATIME 0x20#define MNT_SHRINKABLE 0x100
--
PATCH 1/1 Relative atime - userspace
In reply to Valerie HensonAdd the "relatime" (relative atime) option support to mount. Relative atime only updates the atime if the previous atime is older than the mtime or ctime. Like noatime, but useful for applications like mutt that need to know when a file has been read since it was last modified.
--- mount/mount.8 | 7 +++++++ mount/mount.c | 6 ++++++ mount/mount_constants.h | 4 ++++ 3 files changed, 17 insertions(+)
mount/mount.8 +7 -0
@@ -586,6 +586,13 @@ access on the news spool to speed up new .B nodiratime Do not update directory inode access times on this filesystem. .TP +.B relatime +Update inode access times relative to modify or change time. Access +time is only updated if the previous access time was earlier than the +current modify or change time. (Similar to noatime, but doesn't break +mutt or other applications that need to know if a file has been read +since the last time it was modified.) +.TP .B noauto Can only be mounted explicitly (i.e., the .B \-a
mount/mount.c +6 -0
@@ -164,6 +164,12 @@ static const struct opt_map opt_map[] = { "diratime", 0, 1, MS_NODIRATIME }, /* Update dir access times */ { "nodiratime", 0, 0, MS_NODIRATIME },/* Do not update dir access times */ #endif +#ifdef MS_RELATIME + { "relatime", 0, 0, MS_RELATIME }, /* Update access times relative to + mtime/ctime */ + { "norelatime", 0, 1, MS_RELATIME }, /* Update access time without regard + to mtime/ctime */ +#endif { NULL, 0, 0, 0 } };
mount/mount_constants.h +4 -0
@@ -57,6 +57,10 @@ if we have a stack or plain mount - moun#ifndef MS_VERBOSE #define MS_VERBOSE 0x8000/* 32768 */ #endif +#ifndef MS_RELATIME +#define MS_RELATIME 0x200000/* 200000: Update access times relative +to mtime/ctime */ +#endif /* * Magic mount flag number. Had to be or-ed to the flag values. */
Re: [patch] Relative atime - userspace
Quoted 1 line · Valerie Henson
#define
MS_VERBOSE0x8000/* 32768 */
...
Quoted 1 line
+#define
MS_RELATIME0x200000/* 200000: Update access times relative
Just a small thing... 0x200000 != 200000
Josef "Jeff" Sipek.
Signature · 3 lines
Evolution, n.: A hypothetical process whereby infinitely improbable events occur with alarming frequency, order arises from chaos, and no one is given credit.
Re: [patch] Relative atime - userspace
Quoted 6 lines · Josef Sipek
Quoted 1 line · Valerie Henson
#define
MS_VERBOSE0x8000/* 32768 */...
Quoted 1 line
+#define
MS_RELATIME0x200000/* 200000: Update access times relativeJust a small thing...
0x200000!= 200000
Just goes to show what my default base is... :)
Somehow "2097152: blah blah blah" just doesn't seem helpful - I just removed it. Fresh patch below.
-VAL
--- mount/mount.8 | 7 +++++++ mount/mount.c | 6 ++++++ mount/mount_constants.h | 4 ++++ 3 files changed, 17 insertions(+)
mount/mount.8 +7 -0
@@ -586,6 +586,13 @@ access on the news spool to speed up new .B nodiratime Do not update directory inode access times on this filesystem. .TP +.B relatime +Update inode access times relative to modify or change time. Access +time is only updated if the previous access time was earlier than the +current modify or change time. (Similar to noatime, but doesn't break +mutt or other applications that need to know if a file has been read +since the last time it was modified.) +.TP .B noauto Can only be mounted explicitly (i.e., the .B \-a
mount/mount.c +6 -0
@@ -164,6 +164,12 @@ static const struct opt_map opt_map[] = { "diratime", 0, 1, MS_NODIRATIME }, /* Update dir access times */ { "nodiratime", 0, 0, MS_NODIRATIME },/* Do not update dir access times */ #endif +#ifdef MS_RELATIME + { "relatime", 0, 0, MS_RELATIME }, /* Update access times relative to + mtime/ctime */ + { "norelatime", 0, 1, MS_RELATIME }, /* Update access time without regard + to mtime/ctime */ +#endif { NULL, 0, 0, 0 } };
mount/mount_constants.h +4 -0
@@ -57,6 +57,10 @@ if we have a stack or plain mount - moun#ifndef MS_VERBOSE #define MS_VERBOSE 0x8000/* 32768 */ #endif +#ifndef MS_RELATIME +#define MS_RELATIME 0x200000/* Update access times relative +to mtime/ctime */ +#endif /* * Magic mount flag number. Had to be or-ed to the flag values. */