Drop btrfs and xfs support for the lazyatime features for now
[ext4-patch-queue.git] / ext4-add-lazytime-mount-option
blob67f5e4beb95b3a5b994323288bbf2bc4d722e05a
1 ext4: add optimization for the lazytime mount option
3 Add an optimization for the MS_LAZYTIME mount option so that we will
4 opportunistically write out any inodes with the I_DIRTY_TIME flag set
5 in a particular inode table block when we need to update some inode in
6 that inode table block anyway.
8 Also add some temporary code so that we can set the lazytime mount
9 option without needing a modified /sbin/mount program which can set
10 MS_LAZYTIME.  We can eventually make this go away once util-linux has
11 added support.
13 Google-Bug-Id: 18297052
15 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
16 ---
17  fs/ext4/inode.c             | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
18  fs/ext4/super.c             |  9 +++++++++
19  include/trace/events/ext4.h | 30 +++++++++++++++++++++++++++
20  3 files changed, 101 insertions(+), 3 deletions(-)
22 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
23 index 5653fa4..b9ef4aae 100644
24 --- a/fs/ext4/inode.c
25 +++ b/fs/ext4/inode.c
26 @@ -4139,6 +4139,65 @@ static int ext4_inode_blocks_set(handle_t *handle,
27         return 0;
28  }
30 +struct other_inode {
31 +       unsigned long           orig_ino;
32 +       struct ext4_inode       *raw_inode;
33 +};
35 +static int other_inode_match(struct inode * inode, unsigned long ino,
36 +                            void *data)
38 +       struct other_inode *oi = (struct other_inode *) data;
40 +       if ((inode->i_ino != ino) ||
41 +           (inode->i_state & (I_FREEING | I_WILL_FREE | I_NEW)) ||
42 +           ((inode->i_state & I_DIRTY_TIME) == 0))
43 +               return 0;
44 +       spin_lock(&inode->i_lock);
45 +       if (((inode->i_state & (I_FREEING | I_WILL_FREE | I_NEW)) == 0) &&
46 +           (inode->i_state & I_DIRTY_TIME)) {
47 +               struct ext4_inode_info  *ei = EXT4_I(inode);
49 +               inode->i_state &= ~I_DIRTY_TIME;
50 +               inode->i_ts_dirty_day = 0;
51 +               spin_unlock(&inode->i_lock);
52 +               inode_requeue_dirtytime(inode);
54 +               spin_lock(&ei->i_raw_lock);
55 +               EXT4_INODE_SET_XTIME(i_ctime, inode, oi->raw_inode);
56 +               EXT4_INODE_SET_XTIME(i_mtime, inode, oi->raw_inode);
57 +               EXT4_INODE_SET_XTIME(i_atime, inode, oi->raw_inode);
58 +               ext4_inode_csum_set(inode, oi->raw_inode, ei);
59 +               spin_unlock(&ei->i_raw_lock);
60 +               trace_ext4_other_inode_update_time(inode, oi->orig_ino);
61 +               return -1;
62 +       }
63 +       spin_unlock(&inode->i_lock);
64 +       return -1;
67 +/*
68 + * Opportunistically update the other time fields for other inodes in
69 + * the same inode table block.
70 + */
71 +static void ext4_update_other_inodes_time(struct super_block *sb,
72 +                                         unsigned long orig_ino, char *buf)
74 +       struct other_inode oi;
75 +       unsigned long ino;
76 +       int i, inodes_per_block = EXT4_SB(sb)->s_inodes_per_block;
77 +       int inode_size = EXT4_INODE_SIZE(sb);
79 +       oi.orig_ino = orig_ino;
80 +       ino = orig_ino & ~(inodes_per_block - 1);
81 +       for (i = 0; i < inodes_per_block; i++, ino++, buf += inode_size) {
82 +               if (ino == orig_ino)
83 +                       continue;
84 +               oi.raw_inode = (struct ext4_inode *) buf;
85 +               (void) find_inode_nowait(sb, ino, other_inode_match, &oi);
86 +       }
89  /*
90   * Post the struct inode info into an on-disk inode location in the
91   * buffer-cache.  This gobbles the caller's reference to the
92 @@ -4237,7 +4296,6 @@ static int ext4_do_update_inode(handle_t *handle,
93                 for (block = 0; block < EXT4_N_BLOCKS; block++)
94                         raw_inode->i_block[block] = ei->i_data[block];
95         }
97         if (likely(!test_opt2(inode->i_sb, HURD_COMPAT))) {
98                 raw_inode->i_disk_version = cpu_to_le32(inode->i_version);
99                 if (ei->i_extra_isize) {
100 @@ -4248,10 +4306,11 @@ static int ext4_do_update_inode(handle_t *handle,
101                                 cpu_to_le16(ei->i_extra_isize);
102                 }
103         }
105         ext4_inode_csum_set(inode, raw_inode, ei);
107         spin_unlock(&ei->i_raw_lock);
108 +       if (inode->i_sb->s_flags & MS_LAZYTIME)
109 +               ext4_update_other_inodes_time(inode->i_sb, inode->i_ino,
110 +                                             bh->b_data);
112         BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
113         rc = ext4_handle_dirty_metadata(handle, NULL, bh);
114 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
115 index 58859bc..93a2b7a 100644
116 --- a/fs/ext4/super.c
117 +++ b/fs/ext4/super.c
118 @@ -1132,6 +1132,7 @@ enum {
119         Opt_noquota, Opt_barrier, Opt_nobarrier, Opt_err,
120         Opt_usrquota, Opt_grpquota, Opt_i_version,
121         Opt_stripe, Opt_delalloc, Opt_nodelalloc, Opt_mblk_io_submit,
122 +       Opt_lazytime, Opt_nolazytime,
123         Opt_nomblk_io_submit, Opt_block_validity, Opt_noblock_validity,
124         Opt_inode_readahead_blks, Opt_journal_ioprio,
125         Opt_dioread_nolock, Opt_dioread_lock,
126 @@ -1195,6 +1196,8 @@ static const match_table_t tokens = {
127         {Opt_i_version, "i_version"},
128         {Opt_stripe, "stripe=%u"},
129         {Opt_delalloc, "delalloc"},
130 +       {Opt_lazytime, "lazytime"},
131 +       {Opt_nolazytime, "nolazytime"},
132         {Opt_nodelalloc, "nodelalloc"},
133         {Opt_removed, "mblk_io_submit"},
134         {Opt_removed, "nomblk_io_submit"},
135 @@ -1452,6 +1455,12 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
136         case Opt_i_version:
137                 sb->s_flags |= MS_I_VERSION;
138                 return 1;
139 +       case Opt_lazytime:
140 +               sb->s_flags |= MS_LAZYTIME;
141 +               return 1;
142 +       case Opt_nolazytime:
143 +               sb->s_flags &= ~MS_LAZYTIME;
144 +               return 1;
145         }
147         for (m = ext4_mount_opts; m->token != Opt_err; m++)
148 diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
149 index 6cfb841..6e5abd6 100644
150 --- a/include/trace/events/ext4.h
151 +++ b/include/trace/events/ext4.h
152 @@ -73,6 +73,36 @@ struct extent_status;
153         { FALLOC_FL_ZERO_RANGE,         "ZERO_RANGE"})
156 +TRACE_EVENT(ext4_other_inode_update_time,
157 +       TP_PROTO(struct inode *inode, ino_t orig_ino),
159 +       TP_ARGS(inode, orig_ino),
161 +       TP_STRUCT__entry(
162 +               __field(        dev_t,  dev                     )
163 +               __field(        ino_t,  ino                     )
164 +               __field(        ino_t,  orig_ino                )
165 +               __field(        uid_t,  uid                     )
166 +               __field(        gid_t,  gid                     )
167 +               __field(        __u16, mode                     )
168 +       ),
170 +       TP_fast_assign(
171 +               __entry->orig_ino = orig_ino;
172 +               __entry->dev    = inode->i_sb->s_dev;
173 +               __entry->ino    = inode->i_ino;
174 +               __entry->uid    = i_uid_read(inode);
175 +               __entry->gid    = i_gid_read(inode);
176 +               __entry->mode   = inode->i_mode;
177 +       ),
179 +       TP_printk("dev %d,%d orig_ino %lu ino %lu mode 0%o uid %u gid %u",
180 +                 MAJOR(__entry->dev), MINOR(__entry->dev),
181 +                 (unsigned long) __entry->orig_ino,
182 +                 (unsigned long) __entry->ino, __entry->mode,
183 +                 __entry->uid, __entry->gid)
186  TRACE_EVENT(ext4_free_inode,
187         TP_PROTO(struct inode *inode),