V3 version of Jan's Extent Status Cache improvements
[ext4-patch-queue.git] / dont-let-dirty-time-inodes-get-more-than-a-day-stale
blob7988c889cb79cf643bd0d3e91bdea8e5b06c482b
1 vfs: don't let the dirty time inodes get more than a day stale
3 Guarantee that the on-disk timestamps will be no more than 24 hours
4 stale.
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 ---
8  fs/fs-writeback.c  |  1 +
9  fs/inode.c         | 28 +++++++++++++++++++++++-----
10  include/linux/fs.h |  1 +
11  3 files changed, 25 insertions(+), 5 deletions(-)
13 diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
14 index ce7de22..eb04277 100644
15 --- a/fs/fs-writeback.c
16 +++ b/fs/fs-writeback.c
17 @@ -1141,6 +1141,7 @@ void __mark_inode_dirty(struct inode *inode, int flags)
18         if (flags & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) {
19                 trace_writeback_dirty_inode_start(inode, flags);
21 +               inode->i_ts_dirty_day = 0;
22                 if (sb->s_op->dirty_inode)
23                         sb->s_op->dirty_inode(inode, flags);
25 diff --git a/fs/inode.c b/fs/inode.c
26 index 2093a84..321c7d7 100644
27 --- a/fs/inode.c
28 +++ b/fs/inode.c
29 @@ -1511,6 +1511,8 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
30   */
31  static int update_time(struct inode *inode, struct timespec *time, int flags)
32  {
33 +       struct timespec uptime;
34 +       unsigned short days_since_boot;
35         int ret;
37         if (inode->i_op->update_time) {
38 @@ -1525,17 +1527,33 @@ static int update_time(struct inode *inode, struct timespec *time, int flags)
39                 if (flags & S_CTIME)
40                         inode->i_ctime = *time;
41                 if (flags & S_MTIME)
42 -                       inode->i_mtime = *time;
43 +               inode->i_mtime = *time;
44         }
45 +       /*
46 +        * If i_ts_dirty_day is zero, then either we have not deferred
47 +        * timestamp updates, or the system has been up for less than
48 +        * a day (so days_since_boot is zero), so we defer timestamp
49 +        * updates in that case and set the I_DIRTY_TIME flag.  If a
50 +        * day or more has passed, then i_ts_dirty_day will be
51 +        * different from days_since_boot, and then we should update
52 +        * the on-disk inode and then we can clear i_ts_dirty_day.
53 +        */
54         if ((inode->i_sb->s_flags & MS_LAZYTIME) &&
55             !(flags & S_VERSION)) {
56                 if (inode->i_state & I_DIRTY_TIME)
57                         return 0;
58 -               spin_lock(&inode->i_lock);
59 -               inode->i_state |= I_DIRTY_TIME;
60 -               spin_unlock(&inode->i_lock);
61 -               return 0;
62 +               get_monotonic_boottime(&uptime);
63 +               days_since_boot = div_u64(uptime.tv_sec, 86400);
64 +               if (!inode->i_ts_dirty_day ||
65 +                   inode->i_ts_dirty_day == days_since_boot) {
66 +                       spin_lock(&inode->i_lock);
67 +                       inode->i_state |= I_DIRTY_TIME;
68 +                       spin_unlock(&inode->i_lock);
69 +                       inode->i_ts_dirty_day = days_since_boot;
70 +                       return 0;
71 +               }
72         }
73 +       inode->i_ts_dirty_day = 0;
74         if (inode->i_op->write_time)
75                 return inode->i_op->write_time(inode);
76         mark_inode_dirty_sync(inode);
77 diff --git a/include/linux/fs.h b/include/linux/fs.h
78 index 489b2f2..e3574cd 100644
79 --- a/include/linux/fs.h
80 +++ b/include/linux/fs.h
81 @@ -575,6 +575,7 @@ struct inode {
82         struct timespec         i_ctime;
83         spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
84         unsigned short          i_bytes;
85 +       unsigned short          i_ts_dirty_day;
86         unsigned int            i_blkbits;
87         blkcnt_t                i_blocks;