linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH, resend] relatime: Let relatime update atime at least once per day
@ 2008-12-28 15:29 Matthew Garrett
  2008-12-28 18:35 ` Jesper Juhl
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Matthew Garrett @ 2008-12-28 15:29 UTC (permalink / raw)
  To: linux-kernel, linux-fsdevel

Ensure relatime updates atime at least once per day
    
Allow atime to be updated once per day even with relatime. This lets
utilities like tmpreaper (which delete files based on last access time)
continue working.
    
Signed-off-by: Matthew Garrett <mjg@redhat.com>
Reviewed-by: Matthew Wilcox <willy@linux.intel.com>
Acked-by: Valerie Aurora Henson <vaurora@redhat.com>
Acked-by: Alan Cox <alan@redhat.com>
Acked-by: Ingo Molnar <mingo@elte.hu>

---

diff --git a/fs/inode.c b/fs/inode.c
index 0487ddb..057c92b 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1179,6 +1179,40 @@ sector_t bmap(struct inode * inode, sector_t block)
 }
 EXPORT_SYMBOL(bmap);
 
+/*
+ * With relative atime, only update atime if the previous atime is
+ * earlier than either the ctime or mtime or if at least a day has
+ * passed since the last atime update.
+ */
+static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
+			     struct timespec now)
+{
+
+	if (!(mnt->mnt_flags & MNT_RELATIME))
+		return 1;
+	/*
+	 * Is mtime younger than atime? If yes, update atime:
+	 */
+	if (timespec_compare(&inode->i_mtime, &inode->i_atime) >= 0)
+		return 1;
+	/*
+	 * Is ctime younger than atime? If yes, update atime:
+	 */
+	if (timespec_compare(&inode->i_ctime, &inode->i_atime) >= 0)
+		return 1;
+
+	/*
+	 * Is the previous atime value older than a day? If yes,
+	 * update atime:
+	 */
+	if ((long)(now.tv_sec - inode->i_atime.tv_sec) >= 24*60*60)
+		return 1;
+	/*
+	 * Good, we can skip the atime update:
+	 */
+	return 0;
+}
+
 /**
  *	touch_atime	-	update the access time
  *	@mnt: mount the inode is accessed on
@@ -1206,17 +1240,12 @@ void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
 		goto out;
 	if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))
 		goto out;
-	if (mnt->mnt_flags & MNT_RELATIME) {
-		/*
-		 * With relative atime, only update atime if the previous
-		 * atime is earlier than either the ctime or mtime.
-		 */
-		if (timespec_compare(&inode->i_mtime, &inode->i_atime) < 0 &&
-		    timespec_compare(&inode->i_ctime, &inode->i_atime) < 0)
-			goto out;
-	}
 
 	now = current_fs_time(inode->i_sb);
+
+	if (!relatime_need_update(mnt, inode, now))
+		goto out;
+
 	if (timespec_equal(&inode->i_atime, &now))
 		goto out;

-- 
Matthew Garrett | mjg59@srcf.ucam.org

^ permalink raw reply related	[flat|nested] 11+ messages in thread
[parent not found: <fa.v5U3CdNO/bF+SC9Lx2IrNK0ksBw@ifi.uio.no>]

end of thread, other threads:[~2009-01-08 13:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-28 15:29 [PATCH, resend] relatime: Let relatime update atime at least once per day Matthew Garrett
2008-12-28 18:35 ` Jesper Juhl
2008-12-28 20:19   ` Matthew Garrett
2008-12-28 19:04 ` Éric Piel
2008-12-28 19:59   ` Matthew Garrett
2008-12-28 21:24     ` Éric Piel
2008-12-28 21:36       ` Matthew Wilcox
2008-12-28 21:38       ` Matthew Garrett
2009-01-08 12:29 ` Peter Moulder
2009-01-08 13:32   ` Matthew Garrett
     [not found] <fa.v5U3CdNO/bF+SC9Lx2IrNK0ksBw@ifi.uio.no>
     [not found] ` <fa./Q0ErjvWHKMrOCYUQaeuJBQ1U8A@ifi.uio.no>
     [not found]   ` <fa.pfgwZ2DZZy7psm2o5/f7mrtpRUA@ifi.uio.no>
     [not found]     ` <fa./KluIoJB1+QtfX+SyKcE+SysfKU@ifi.uio.no>
     [not found]       ` <fa.YKGFdZah7xr94yJzEWemIAnOKNA@ifi.uio.no>
2008-12-28 22:53         ` Sitsofe Wheeler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).