Update lazytime patches
[ext4-patch-queue.git] / vfs-add-lazytime-mount-option
blob77026d513d485f1002271e120733eb04efed7719
1 vfs: add support for a lazytime mount option
3 Add a new mount option which enables a new "lazytime" mode.  This mode
4 causes atime, mtime, and ctime updates to only be made to the
5 in-memory version of the inode.  The on-disk times will only get
6 updated when (a) if the inode needs to be updated for some non-time
7 related change, (b) if userspace calls fsync(), syncfs() or sync(), or
8 (c) just before an undeleted inode is evicted from memory.
10 This is OK according to POSIX because there are no guarantees after a
11 crash unless userspace explicitly requests via a fsync(2) call.
13 For workloads which feature a large number of random write to a
14 preallocated file, the lazytime mount option significantly reduces
15 writes to the inode table.  The repeated 4k writes to a single block
16 will result in undesirable stress on flash devices and SMR disk
17 drives.  Even on conventional HDD's, the repeated writes to the inode
18 table block will trigger Adjacent Track Interference (ATI) remediation
19 latencies, which very negatively impact long tail latencies --- which
20 is a very big deal for web serving tiers (for example).
22 Google-Bug-Id: 18297052
24 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
25 ---
26  fs/ext4/inode.c                  |  6 +++++
27  fs/fs-writeback.c                | 64 +++++++++++++++++++++++++++++++++++---------
28  fs/gfs2/file.c                   |  4 +--
29  fs/inode.c                       | 56 +++++++++++++++++++++++++++-----------
30  fs/jfs/file.c                    |  2 +-
31  fs/libfs.c                       |  2 +-
32  fs/proc_namespace.c              |  1 +
33  fs/sync.c                        |  8 ++++++
34  include/linux/backing-dev.h      |  1 +
35  include/linux/fs.h               |  5 ++++
36  include/trace/events/writeback.h | 60 ++++++++++++++++++++++++++++++++++++++++-
37  include/uapi/linux/fs.h          |  4 ++-
38  mm/backing-dev.c                 | 10 +++++--
39  13 files changed, 187 insertions(+), 36 deletions(-)
41 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
42 index 5653fa4..628df5b 100644
43 --- a/fs/ext4/inode.c
44 +++ b/fs/ext4/inode.c
45 @@ -4840,11 +4840,17 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode)
46   * If the inode is marked synchronous, we don't honour that here - doing
47   * so would cause a commit on atime updates, which we don't bother doing.
48   * We handle synchronous inodes at the highest possible level.
49 + *
50 + * If only the I_DIRTY_TIME flag is set, we can skip everything.  If
51 + * I_DIRTY_TIME and I_DIRTY_SYNC is set, the only inode fields we need
52 + * to copy into the on-disk inode structure are the timestamp files.
53   */
54  void ext4_dirty_inode(struct inode *inode, int flags)
55  {
56         handle_t *handle;
58 +       if (flags == I_DIRTY_TIME)
59 +               return;
60         handle = ext4_journal_start(inode, EXT4_HT_INODE, 2);
61         if (IS_ERR(handle))
62                 goto out;
63 diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
64 index ef9bef1..d7ce58b 100644
65 --- a/fs/fs-writeback.c
66 +++ b/fs/fs-writeback.c
67 @@ -247,14 +247,19 @@ static bool inode_dirtied_after(struct inode *inode, unsigned long t)
68         return ret;
69  }
71 +#define EXPIRE_DIRTY_ATIME 0x0001
73  /*
74   * Move expired (dirtied before work->older_than_this) dirty inodes from
75   * @delaying_queue to @dispatch_queue.
76   */
77  static int move_expired_inodes(struct list_head *delaying_queue,
78                                struct list_head *dispatch_queue,
79 +                              int flags,
80                                struct wb_writeback_work *work)
81  {
82 +       unsigned long *older_than_this = NULL;
83 +       unsigned long expire_time;
84         LIST_HEAD(tmp);
85         struct list_head *pos, *node;
86         struct super_block *sb = NULL;
87 @@ -262,13 +267,21 @@ static int move_expired_inodes(struct list_head *delaying_queue,
88         int do_sb_sort = 0;
89         int moved = 0;
91 +       if ((flags & EXPIRE_DIRTY_ATIME) == 0)
92 +               older_than_this = work->older_than_this;
93 +       else if ((work->reason == WB_REASON_SYNC) == 0) {
94 +               expire_time = jiffies - (HZ * 86400);
95 +               older_than_this = &expire_time;
96 +       }
97         while (!list_empty(delaying_queue)) {
98                 inode = wb_inode(delaying_queue->prev);
99 -               if (work->older_than_this &&
100 -                   inode_dirtied_after(inode, *work->older_than_this))
101 +               if (older_than_this &&
102 +                   inode_dirtied_after(inode, *older_than_this))
103                         break;
104                 list_move(&inode->i_wb_list, &tmp);
105                 moved++;
106 +               if (flags & EXPIRE_DIRTY_ATIME)
107 +                       set_bit(__I_DIRTY_TIME_EXPIRED, &inode->i_state);
108                 if (sb_is_blkdev_sb(inode->i_sb))
109                         continue;
110                 if (sb && sb != inode->i_sb)
111 @@ -309,9 +322,12 @@ out:
112  static void queue_io(struct bdi_writeback *wb, struct wb_writeback_work *work)
114         int moved;
116         assert_spin_locked(&wb->list_lock);
117         list_splice_init(&wb->b_more_io, &wb->b_io);
118 -       moved = move_expired_inodes(&wb->b_dirty, &wb->b_io, work);
119 +       moved = move_expired_inodes(&wb->b_dirty, &wb->b_io, 0, work);
120 +       moved += move_expired_inodes(&wb->b_dirty_time, &wb->b_io,
121 +                                    EXPIRE_DIRTY_ATIME, work);
122         trace_writeback_queue_io(wb, work, moved);
125 @@ -435,6 +451,8 @@ static void requeue_inode(struct inode *inode, struct bdi_writeback *wb,
126                  * updates after data IO completion.
127                  */
128                 redirty_tail(inode, wb);
129 +       } else if (inode->i_state & I_DIRTY_TIME) {
130 +               list_move(&inode->i_wb_list, &wb->b_dirty_time);
131         } else {
132                 /* The inode is clean. Remove from writeback lists. */
133                 list_del_init(&inode->i_wb_list);
134 @@ -482,11 +500,18 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
135         /* Clear I_DIRTY_PAGES if we've written out all dirty pages */
136         if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
137                 inode->i_state &= ~I_DIRTY_PAGES;
138 -       dirty = inode->i_state & I_DIRTY;
139 -       inode->i_state &= ~(I_DIRTY_SYNC | I_DIRTY_DATASYNC);
140 +       dirty = inode->i_state & (I_DIRTY_SYNC | I_DIRTY_DATASYNC);
141 +       if ((dirty && (inode->i_state & I_DIRTY_TIME)) ||
142 +           (inode->i_state & I_DIRTY_TIME_EXPIRED)) {
143 +               dirty |= I_DIRTY_TIME | I_DIRTY_TIME_EXPIRED;
144 +               trace_writeback_lazytime(inode);
145 +       }
146 +       inode->i_state &= ~dirty;
147         spin_unlock(&inode->i_lock);
148 +       if (dirty & I_DIRTY_TIME)
149 +               mark_inode_dirty_sync(inode);
150         /* Don't write the inode if only I_DIRTY_PAGES was set */
151 -       if (dirty & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) {
152 +       if (dirty) {
153                 int err = write_inode(inode, wbc);
154                 if (ret == 0)
155                         ret = err;
156 @@ -534,7 +559,7 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,
157          * make sure inode is on some writeback list and leave it there unless
158          * we have completely cleaned the inode.
159          */
160 -       if (!(inode->i_state & I_DIRTY) &&
161 +       if (!(inode->i_state & I_DIRTY_ALL) &&
162             (wbc->sync_mode != WB_SYNC_ALL ||
163              !mapping_tagged(inode->i_mapping, PAGECACHE_TAG_WRITEBACK)))
164                 goto out;
165 @@ -549,7 +574,7 @@ writeback_single_inode(struct inode *inode, struct bdi_writeback *wb,
166          * If inode is clean, remove it from writeback lists. Otherwise don't
167          * touch it. See comment above for explanation.
168          */
169 -       if (!(inode->i_state & I_DIRTY))
170 +       if (!(inode->i_state & I_DIRTY_ALL))
171                 list_del_init(&inode->i_wb_list);
172         spin_unlock(&wb->list_lock);
173         inode_sync_complete(inode);
174 @@ -691,7 +716,7 @@ static long writeback_sb_inodes(struct super_block *sb,
175                 wrote += write_chunk - wbc.nr_to_write;
176                 spin_lock(&wb->list_lock);
177                 spin_lock(&inode->i_lock);
178 -               if (!(inode->i_state & I_DIRTY))
179 +               if (!(inode->i_state & I_DIRTY_ALL))
180                         wrote++;
181                 requeue_inode(inode, wb, &wbc);
182                 inode_sync_complete(inode);
183 @@ -1129,16 +1154,20 @@ static noinline void block_dump___mark_inode_dirty(struct inode *inode)
184   * page->mapping->host, so the page-dirtying time is recorded in the internal
185   * blockdev inode.
186   */
187 +#define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC)
188  void __mark_inode_dirty(struct inode *inode, int flags)
190         struct super_block *sb = inode->i_sb;
191         struct backing_dev_info *bdi = NULL;
192 +       int dirtytime;
194 +       trace_writeback_mark_inode_dirty(inode, flags);
196         /*
197          * Don't do this for I_DIRTY_PAGES - that doesn't actually
198          * dirty the inode itself
199          */
200 -       if (flags & (I_DIRTY_SYNC | I_DIRTY_DATASYNC)) {
201 +       if (flags & (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_TIME)) {
202                 trace_writeback_dirty_inode_start(inode, flags);
204                 if (sb->s_op->dirty_inode)
205 @@ -1146,6 +1175,9 @@ void __mark_inode_dirty(struct inode *inode, int flags)
207                 trace_writeback_dirty_inode(inode, flags);
208         }
209 +       if (flags & I_DIRTY_INODE)
210 +               flags &= ~I_DIRTY_TIME;
211 +       dirtytime = flags & I_DIRTY_TIME;
213         /*
214          * make sure that changes are seen by all cpus before we test i_state
215 @@ -1154,16 +1186,22 @@ void __mark_inode_dirty(struct inode *inode, int flags)
216         smp_mb();
218         /* avoid the locking if we can */
219 -       if ((inode->i_state & flags) == flags)
220 +       if (((inode->i_state & flags) == flags) ||
221 +           (dirtytime && (inode->i_state & I_DIRTY_INODE)))
222                 return;
224         if (unlikely(block_dump))
225                 block_dump___mark_inode_dirty(inode);
227         spin_lock(&inode->i_lock);
228 +       if (dirtytime && (inode->i_state & I_DIRTY_INODE))
229 +               return;
230         if ((inode->i_state & flags) != flags) {
231                 const int was_dirty = inode->i_state & I_DIRTY;
233 +               if ((flags & I_DIRTY_INODE) && (inode->i_state & I_DIRTY_TIME))
234 +                       inode->i_state &= ~I_DIRTY_TIME;
236                 inode->i_state |= flags;
238                 /*
239 @@ -1210,8 +1248,10 @@ void __mark_inode_dirty(struct inode *inode, int flags)
240                         }
242                         inode->dirtied_when = jiffies;
243 -                       list_move(&inode->i_wb_list, &bdi->wb.b_dirty);
244 +                       list_move(&inode->i_wb_list, dirtytime ?
245 +                                 &bdi->wb.b_dirty_time : &bdi->wb.b_dirty);
246                         spin_unlock(&bdi->wb.list_lock);
247 +                       trace_writeback_dirty_inode_enqueue(inode);
249                         if (wakeup_bdi)
250                                 bdi_wakeup_thread_delayed(bdi);
251 diff --git a/fs/gfs2/file.c b/fs/gfs2/file.c
252 index 80dd44d..e584bf9 100644
253 --- a/fs/gfs2/file.c
254 +++ b/fs/gfs2/file.c
255 @@ -654,7 +654,7 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
257         struct address_space *mapping = file->f_mapping;
258         struct inode *inode = mapping->host;
259 -       int sync_state = inode->i_state & I_DIRTY;
260 +       int sync_state = inode->i_state & I_DIRTY_ALL;
261         struct gfs2_inode *ip = GFS2_I(inode);
262         int ret = 0, ret1 = 0;
264 @@ -667,7 +667,7 @@ static int gfs2_fsync(struct file *file, loff_t start, loff_t end,
265         if (!gfs2_is_jdata(ip))
266                 sync_state &= ~I_DIRTY_PAGES;
267         if (datasync)
268 -               sync_state &= ~I_DIRTY_SYNC;
269 +               sync_state &= ~(I_DIRTY_SYNC | I_DIRTY_TIME);
271         if (sync_state) {
272                 ret = sync_inode_metadata(inode, 1);
273 diff --git a/fs/inode.c b/fs/inode.c
274 index 26753ba..dc48a23 100644
275 --- a/fs/inode.c
276 +++ b/fs/inode.c
277 @@ -18,6 +18,7 @@
278  #include <linux/buffer_head.h> /* for inode_has_buffers */
279  #include <linux/ratelimit.h>
280  #include <linux/list_lru.h>
281 +#include <trace/events/writeback.h>
282  #include "internal.h"
284  /*
285 @@ -30,7 +31,7 @@
286   * inode_sb_list_lock protects:
287   *   sb->s_inodes, inode->i_sb_list
288   * bdi->wb.list_lock protects:
289 - *   bdi->wb.b_{dirty,io,more_io}, inode->i_wb_list
290 + *   bdi->wb.b_{dirty,io,more_io,dirty_time}, inode->i_wb_list
291   * inode_hash_lock protects:
292   *   inode_hashtable, inode->i_hash
293   *
294 @@ -414,7 +415,8 @@ static void inode_lru_list_add(struct inode *inode)
295   */
296  void inode_add_lru(struct inode *inode)
298 -       if (!(inode->i_state & (I_DIRTY | I_SYNC | I_FREEING | I_WILL_FREE)) &&
299 +       if (!(inode->i_state & (I_DIRTY_ALL | I_SYNC |
300 +                               I_FREEING | I_WILL_FREE)) &&
301             !atomic_read(&inode->i_count) && inode->i_sb->s_flags & MS_ACTIVE)
302                 inode_lru_list_add(inode);
304 @@ -645,7 +647,7 @@ int invalidate_inodes(struct super_block *sb, bool kill_dirty)
305                         spin_unlock(&inode->i_lock);
306                         continue;
307                 }
308 -               if (inode->i_state & I_DIRTY && !kill_dirty) {
309 +               if (inode->i_state & I_DIRTY_ALL && !kill_dirty) {
310                         spin_unlock(&inode->i_lock);
311                         busy = 1;
312                         continue;
313 @@ -1430,11 +1432,20 @@ static void iput_final(struct inode *inode)
314   */
315  void iput(struct inode *inode)
317 -       if (inode) {
318 -               BUG_ON(inode->i_state & I_CLEAR);
320 -               if (atomic_dec_and_lock(&inode->i_count, &inode->i_lock))
321 -                       iput_final(inode);
322 +       if (!inode)
323 +               return;
324 +       BUG_ON(inode->i_state & I_CLEAR);
325 +retry:
326 +       if (atomic_dec_and_lock(&inode->i_count, &inode->i_lock)) {
327 +               if (inode->i_nlink && (inode->i_state & I_DIRTY_TIME)) {
328 +                       atomic_inc(&inode->i_count);
329 +                       inode->i_state &= ~I_DIRTY_TIME;
330 +                       spin_unlock(&inode->i_lock);
331 +                       trace_writeback_lazytime_iput(inode);
332 +                       mark_inode_dirty_sync(inode);
333 +                       goto retry;
334 +               }
335 +               iput_final(inode);
336         }
338  EXPORT_SYMBOL(iput);
339 @@ -1493,14 +1504,9 @@ static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
340         return 0;
344 - * This does the actual work of updating an inodes time or version.  Must have
345 - * had called mnt_want_write() before calling this.
346 - */
347 -static int update_time(struct inode *inode, struct timespec *time, int flags)
348 +int generic_update_time(struct inode *inode, struct timespec *time, int flags)
350 -       if (inode->i_op->update_time)
351 -               return inode->i_op->update_time(inode, time, flags);
352 +       int iflags = I_DIRTY_TIME;
354         if (flags & S_ATIME)
355                 inode->i_atime = *time;
356 @@ -1510,9 +1516,27 @@ static int update_time(struct inode *inode, struct timespec *time, int flags)
357                 inode->i_ctime = *time;
358         if (flags & S_MTIME)
359                 inode->i_mtime = *time;
360 -       mark_inode_dirty_sync(inode);
362 +       if (!(inode->i_sb->s_flags & MS_LAZYTIME) || (flags & S_VERSION))
363 +               iflags |= I_DIRTY_SYNC;
364 +       __mark_inode_dirty(inode, iflags);
365         return 0;
367 +EXPORT_SYMBOL(generic_update_time);
370 + * This does the actual work of updating an inodes time or version.  Must have
371 + * had called mnt_want_write() before calling this.
372 + */
373 +static int update_time(struct inode *inode, struct timespec *time, int flags)
375 +       int (*update_time)(struct inode *, struct timespec *, int);
377 +       update_time = inode->i_op->update_time ? inode->i_op->update_time :
378 +               generic_update_time;
380 +       return update_time(inode, time, flags);
383  /**
384   *     touch_atime     -       update the access time
385 diff --git a/fs/jfs/file.c b/fs/jfs/file.c
386 index 33aa0cc..10815f8 100644
387 --- a/fs/jfs/file.c
388 +++ b/fs/jfs/file.c
389 @@ -39,7 +39,7 @@ int jfs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
390                 return rc;
392         mutex_lock(&inode->i_mutex);
393 -       if (!(inode->i_state & I_DIRTY) ||
394 +       if (!(inode->i_state & I_DIRTY_ALL) ||
395             (datasync && !(inode->i_state & I_DIRTY_DATASYNC))) {
396                 /* Make sure committed changes hit the disk */
397                 jfs_flush_journal(JFS_SBI(inode->i_sb)->log, 1);
398 diff --git a/fs/libfs.c b/fs/libfs.c
399 index 171d284..7cb9cef 100644
400 --- a/fs/libfs.c
401 +++ b/fs/libfs.c
402 @@ -948,7 +948,7 @@ int __generic_file_fsync(struct file *file, loff_t start, loff_t end,
404         mutex_lock(&inode->i_mutex);
405         ret = sync_mapping_buffers(inode->i_mapping);
406 -       if (!(inode->i_state & I_DIRTY))
407 +       if (!(inode->i_state & I_DIRTY_ALL))
408                 goto out;
409         if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
410                 goto out;
411 diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
412 index 73ca174..f98234a 100644
413 --- a/fs/proc_namespace.c
414 +++ b/fs/proc_namespace.c
415 @@ -44,6 +44,7 @@ static int show_sb_opts(struct seq_file *m, struct super_block *sb)
416                 { MS_SYNCHRONOUS, ",sync" },
417                 { MS_DIRSYNC, ",dirsync" },
418                 { MS_MANDLOCK, ",mand" },
419 +               { MS_LAZYTIME, ",lazytime" },
420                 { 0, NULL }
421         };
422         const struct proc_fs_info *fs_infop;
423 diff --git a/fs/sync.c b/fs/sync.c
424 index bdc729d..6ac7bf0 100644
425 --- a/fs/sync.c
426 +++ b/fs/sync.c
427 @@ -177,8 +177,16 @@ SYSCALL_DEFINE1(syncfs, int, fd)
428   */
429  int vfs_fsync_range(struct file *file, loff_t start, loff_t end, int datasync)
431 +       struct inode *inode = file->f_mapping->host;
433         if (!file->f_op->fsync)
434                 return -EINVAL;
435 +       if (!datasync && (inode->i_state & I_DIRTY_TIME)) {
436 +               spin_lock(&inode->i_lock);
437 +               inode->i_state &= ~I_DIRTY_TIME;
438 +               spin_unlock(&inode->i_lock);
439 +               mark_inode_dirty_sync(inode);
440 +       }
441         return file->f_op->fsync(file, start, end, datasync);
443  EXPORT_SYMBOL(vfs_fsync_range);
444 diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h
445 index 5da6012..4cdf733 100644
446 --- a/include/linux/backing-dev.h
447 +++ b/include/linux/backing-dev.h
448 @@ -55,6 +55,7 @@ struct bdi_writeback {
449         struct list_head b_dirty;       /* dirty inodes */
450         struct list_head b_io;          /* parked for writeback */
451         struct list_head b_more_io;     /* parked for more writeback */
452 +       struct list_head b_dirty_time;  /* time stamps are dirty */
453         spinlock_t list_lock;           /* protects the b_* lists */
454  };
456 diff --git a/include/linux/fs.h b/include/linux/fs.h
457 index 9ab779e..bf00e98 100644
458 --- a/include/linux/fs.h
459 +++ b/include/linux/fs.h
460 @@ -1720,8 +1720,12 @@ struct super_operations {
461  #define __I_DIO_WAKEUP         9
462  #define I_DIO_WAKEUP           (1 << I_DIO_WAKEUP)
463  #define I_LINKABLE             (1 << 10)
464 +#define I_DIRTY_TIME           (1 << 11)
465 +#define __I_DIRTY_TIME_EXPIRED 12
466 +#define I_DIRTY_TIME_EXPIRED   (1 << __I_DIRTY_TIME_EXPIRED)
468  #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
469 +#define I_DIRTY_ALL (I_DIRTY | I_DIRTY_TIME)
471  extern void __mark_inode_dirty(struct inode *, int);
472  static inline void mark_inode_dirty(struct inode *inode)
473 @@ -1884,6 +1888,7 @@ extern int current_umask(void);
475  extern void ihold(struct inode * inode);
476  extern void iput(struct inode *);
477 +extern int generic_update_time(struct inode *, struct timespec *, int);
479  static inline struct inode *file_inode(const struct file *f)
481 diff --git a/include/trace/events/writeback.h b/include/trace/events/writeback.h
482 index cee02d6..5ecb4c2 100644
483 --- a/include/trace/events/writeback.h
484 +++ b/include/trace/events/writeback.h
485 @@ -18,6 +18,8 @@
486                 {I_FREEING,             "I_FREEING"},           \
487                 {I_CLEAR,               "I_CLEAR"},             \
488                 {I_SYNC,                "I_SYNC"},              \
489 +               {I_DIRTY_TIME,          "I_DIRTY_TIME"},        \
490 +               {I_DIRTY_TIME_EXPIRED,  "I_DIRTY_TIME_EXPIRED"}, \
491                 {I_REFERENCED,          "I_REFERENCED"}         \
492         )
494 @@ -68,6 +70,7 @@ DECLARE_EVENT_CLASS(writeback_dirty_inode_template,
495         TP_STRUCT__entry (
496                 __array(char, name, 32)
497                 __field(unsigned long, ino)
498 +               __field(unsigned long, state)
499                 __field(unsigned long, flags)
500         ),
502 @@ -78,16 +81,25 @@ DECLARE_EVENT_CLASS(writeback_dirty_inode_template,
503                 strncpy(__entry->name,
504                         bdi->dev ? dev_name(bdi->dev) : "(unknown)", 32);
505                 __entry->ino            = inode->i_ino;
506 +               __entry->state          = inode->i_state;
507                 __entry->flags          = flags;
508         ),
510 -       TP_printk("bdi %s: ino=%lu flags=%s",
511 +       TP_printk("bdi %s: ino=%lu state=%s flags=%s",
512                 __entry->name,
513                 __entry->ino,
514 +               show_inode_state(__entry->state),
515                 show_inode_state(__entry->flags)
516         )
517  );
519 +DEFINE_EVENT(writeback_dirty_inode_template, writeback_mark_inode_dirty,
521 +       TP_PROTO(struct inode *inode, int flags),
523 +       TP_ARGS(inode, flags)
526  DEFINE_EVENT(writeback_dirty_inode_template, writeback_dirty_inode_start,
528         TP_PROTO(struct inode *inode, int flags),
529 @@ -598,6 +610,52 @@ DEFINE_EVENT(writeback_single_inode_template, writeback_single_inode,
530         TP_ARGS(inode, wbc, nr_to_write)
531  );
533 +DECLARE_EVENT_CLASS(writeback_lazytime_template,
534 +       TP_PROTO(struct inode *inode),
536 +       TP_ARGS(inode),
538 +       TP_STRUCT__entry(
539 +               __field(        dev_t,  dev                     )
540 +               __field(unsigned long,  ino                     )
541 +               __field(unsigned long,  state                   )
542 +               __field(        __u16, mode                     )
543 +               __field(unsigned long, dirtied_when             )
544 +       ),
546 +       TP_fast_assign(
547 +               __entry->dev    = inode->i_sb->s_dev;
548 +               __entry->ino    = inode->i_ino;
549 +               __entry->state  = inode->i_state;
550 +               __entry->mode   = inode->i_mode;
551 +               __entry->dirtied_when = inode->dirtied_when;
552 +       ),
554 +       TP_printk("dev %d,%d ino %lu dirtied %lu state %s mode 0%o",
555 +                 MAJOR(__entry->dev), MINOR(__entry->dev),
556 +                 __entry->ino, __entry->dirtied_when,
557 +                 show_inode_state(__entry->state), __entry->mode)
560 +DEFINE_EVENT(writeback_lazytime_template, writeback_lazytime,
561 +       TP_PROTO(struct inode *inode),
563 +       TP_ARGS(inode)
566 +DEFINE_EVENT(writeback_lazytime_template, writeback_lazytime_iput,
567 +       TP_PROTO(struct inode *inode),
569 +       TP_ARGS(inode)
572 +DEFINE_EVENT(writeback_lazytime_template, writeback_dirty_inode_enqueue,
574 +       TP_PROTO(struct inode *inode),
576 +       TP_ARGS(inode)
579  #endif /* _TRACE_WRITEBACK_H */
581  /* This part must be outside protection */
582 diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
583 index 3735fa0..9b964a5 100644
584 --- a/include/uapi/linux/fs.h
585 +++ b/include/uapi/linux/fs.h
586 @@ -90,6 +90,7 @@ struct inodes_stat_t {
587  #define MS_KERNMOUNT   (1<<22) /* this is a kern_mount call */
588  #define MS_I_VERSION   (1<<23) /* Update inode I_version field */
589  #define MS_STRICTATIME (1<<24) /* Always perform atime updates */
590 +#define MS_LAZYTIME    (1<<25) /* Update the on-disk [acm]times lazily */
592  /* These sb flags are internal to the kernel */
593  #define MS_NOSEC       (1<<28)
594 @@ -100,7 +101,8 @@ struct inodes_stat_t {
595  /*
596   * Superblock flags that can be altered by MS_REMOUNT
597   */
598 -#define MS_RMT_MASK    (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION)
599 +#define MS_RMT_MASK    (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|\
600 +                        MS_LAZYTIME)
602  /*
603   * Old magic mount flag and mask
604 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
605 index 0ae0df5..915feea 100644
606 --- a/mm/backing-dev.c
607 +++ b/mm/backing-dev.c
608 @@ -69,10 +69,10 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
609         unsigned long background_thresh;
610         unsigned long dirty_thresh;
611         unsigned long bdi_thresh;
612 -       unsigned long nr_dirty, nr_io, nr_more_io;
613 +       unsigned long nr_dirty, nr_io, nr_more_io, nr_dirty_time;
614         struct inode *inode;
616 -       nr_dirty = nr_io = nr_more_io = 0;
617 +       nr_dirty = nr_io = nr_more_io = nr_dirty_time = 0;
618         spin_lock(&wb->list_lock);
619         list_for_each_entry(inode, &wb->b_dirty, i_wb_list)
620                 nr_dirty++;
621 @@ -80,6 +80,9 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
622                 nr_io++;
623         list_for_each_entry(inode, &wb->b_more_io, i_wb_list)
624                 nr_more_io++;
625 +       list_for_each_entry(inode, &wb->b_dirty_time, i_wb_list)
626 +               if (inode->i_state & I_DIRTY_TIME)
627 +                       nr_dirty_time++;
628         spin_unlock(&wb->list_lock);
630         global_dirty_limits(&background_thresh, &dirty_thresh);
631 @@ -98,6 +101,7 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
632                    "b_dirty:            %10lu\n"
633                    "b_io:               %10lu\n"
634                    "b_more_io:          %10lu\n"
635 +                  "b_dirty_time:       %10lu\n"
636                    "bdi_list:           %10u\n"
637                    "state:              %10lx\n",
638                    (unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)),
639 @@ -111,6 +115,7 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
640                    nr_dirty,
641                    nr_io,
642                    nr_more_io,
643 +                  nr_dirty_time,
644                    !list_empty(&bdi->bdi_list), bdi->state);
645  #undef K
647 @@ -418,6 +423,7 @@ static void bdi_wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi)
648         INIT_LIST_HEAD(&wb->b_dirty);
649         INIT_LIST_HEAD(&wb->b_io);
650         INIT_LIST_HEAD(&wb->b_more_io);
651 +       INIT_LIST_HEAD(&wb->b_dirty_time);
652         spin_lock_init(&wb->list_lock);
653         INIT_DELAYED_WORK(&wb->dwork, bdi_writeback_workfn);