Clean up typo in patch but remove it for now.
[ext4-patch-queue.git] / ext4-add-lazytime-mount-option
blob49fd102975fe6d3a1649a4b1eaa5b012e2272a03
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             | 10 ++++++++
19  include/trace/events/ext4.h | 30 ++++++++++++++++++++++
20  3 files changed, 102 insertions(+), 3 deletions(-)
22 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
23 index 5653fa4..6327b28 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 +                              I_DIRTY_SYNC | I_DIRTY_DATASYNC)) ||
43 +           ((inode->i_state & I_DIRTY_TIME) == 0))
44 +               return 0;
45 +       spin_lock(&inode->i_lock);
46 +       if (((inode->i_state & (I_FREEING | I_WILL_FREE | I_NEW |
47 +                               I_DIRTY_SYNC | I_DIRTY_DATASYNC)) == 0) &&
48 +           (inode->i_state & I_DIRTY_TIME)) {
49 +               struct ext4_inode_info  *ei = EXT4_I(inode);
51 +               inode->i_state &= ~I_DIRTY_TIME;
52 +               spin_unlock(&inode->i_lock);
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..5310ec9 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 @@ -5013,6 +5022,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
149         }
150  #endif
152 +       *flags = (*flags & ~MS_LAZYTIME) | (sb->s_flags & MS_LAZYTIME);
153         ext4_msg(sb, KERN_INFO, "re-mounted. Opts: %s", orig_data);
154         kfree(orig_data);
155         return 0;
156 diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
157 index 6cfb841..6e5abd6 100644
158 --- a/include/trace/events/ext4.h
159 +++ b/include/trace/events/ext4.h
160 @@ -73,6 +73,36 @@ struct extent_status;
161         { FALLOC_FL_ZERO_RANGE,         "ZERO_RANGE"})
164 +TRACE_EVENT(ext4_other_inode_update_time,
165 +       TP_PROTO(struct inode *inode, ino_t orig_ino),
167 +       TP_ARGS(inode, orig_ino),
169 +       TP_STRUCT__entry(
170 +               __field(        dev_t,  dev                     )
171 +               __field(        ino_t,  ino                     )
172 +               __field(        ino_t,  orig_ino                )
173 +               __field(        uid_t,  uid                     )
174 +               __field(        gid_t,  gid                     )
175 +               __field(        __u16, mode                     )
176 +       ),
178 +       TP_fast_assign(
179 +               __entry->orig_ino = orig_ino;
180 +               __entry->dev    = inode->i_sb->s_dev;
181 +               __entry->ino    = inode->i_ino;
182 +               __entry->uid    = i_uid_read(inode);
183 +               __entry->gid    = i_gid_read(inode);
184 +               __entry->mode   = inode->i_mode;
185 +       ),
187 +       TP_printk("dev %d,%d orig_ino %lu ino %lu mode 0%o uid %u gid %u",
188 +                 MAJOR(__entry->dev), MINOR(__entry->dev),
189 +                 (unsigned long) __entry->orig_ino,
190 +                 (unsigned long) __entry->ino, __entry->mode,
191 +                 __entry->uid, __entry->gid)
194  TRACE_EVENT(ext4_free_inode,
195         TP_PROTO(struct inode *inode),