Whamcloud - gitweb
LU-13004 modules: replace lnet_kiov_t with struct bio_vec
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel7.3 / ext4-disable-mb-cache.patch
1 mbcache provides absolutely no value for Lustre xattrs (because
2 they are unique and cannot be shared between files) and as we can
3 see it has a noticable overhead in some cases. In the past there
4 was a CONFIG_MBCACHE option that would allow it to be disabled,
5 but this was removed in newer kernels, so we will need to patch
6 ldiskfs to fix this.
7
8 Index: linux-stage/fs/ext4/ext4.h
9 ===================================================================
10 --- linux-stage.orig/fs/ext4/ext4.h
11 +++ linux-stage/fs/ext4/ext4.h
12 @@ -963,6 +963,7 @@ struct ext4_inode_info {
13  /*
14   * Mount flags set via mount options or defaults
15   */
16 +#define EXT4_MOUNT_NO_MBCACHE          0x00001 /* Disable mbcache */
17  #define EXT4_MOUNT_DIRDATA             0x00002 /* Data in directory entries*/
18  #define EXT4_MOUNT_GRPID               0x00004 /* Create files with directory's group */
19  #define EXT4_MOUNT_DEBUG               0x00008 /* Some debugging messages */
20 Index: linux-stage/fs/ext4/super.c
21 ===================================================================
22 --- linux-stage.orig/fs/ext4/super.c
23 +++ linux-stage/fs/ext4/super.c
24 @@ -1161,6 +1161,7 @@ enum {
25         Opt_nomblk_io_submit, Opt_block_validity, Opt_noblock_validity,
26         Opt_inode_readahead_blks, Opt_journal_ioprio,
27         Opt_dioread_nolock, Opt_dioread_lock,
28 +       Opt_no_mbcache,
29         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
30         Opt_max_dir_size_kb, Opt_nojournal_checksum,
31  };
32 @@ -1238,6 +1239,7 @@ static const match_table_t tokens = {
33         {Opt_discard, "discard"},
34         {Opt_nodiscard, "nodiscard"},
35         {Opt_init_itable, "init_itable=%u"},
36 +       {Opt_no_mbcache, "no_mbcache"},
37         {Opt_init_itable, "init_itable"},
38         {Opt_noinit_itable, "noinit_itable"},
39         {Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
40 @@ -1400,6 +1402,7 @@ static const struct mount_opts {
41         {Opt_noauto_da_alloc, EXT4_MOUNT_NO_AUTO_DA_ALLOC, MOPT_SET},
42         {Opt_auto_da_alloc, EXT4_MOUNT_NO_AUTO_DA_ALLOC, MOPT_CLEAR},
43         {Opt_noinit_itable, EXT4_MOUNT_INIT_INODE_TABLE, MOPT_CLEAR},
44 +       {Opt_no_mbcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
45         {Opt_commit, 0, MOPT_GTE0},
46         {Opt_max_batch_time, 0, MOPT_GTE0},
47         {Opt_min_batch_time, 0, MOPT_GTE0},
48 Index: linux-stage/fs/ext4/xattr.c
49 ===================================================================
50 --- linux-stage.orig/fs/ext4/xattr.c
51 +++ linux-stage/fs/ext4/xattr.c
52 @@ -81,7 +81,8 @@
53  # define ea_bdebug(bh, fmt, ...)       no_printk(fmt, ##__VA_ARGS__)
54  #endif
55  
56 -static void ext4_xattr_cache_insert(struct buffer_head *);
57 +static void ext4_xattr_cache_insert(struct super_block *,
58 +                                   struct buffer_head *);
59  static struct buffer_head *ext4_xattr_cache_find(struct inode *,
60                                                  struct ext4_xattr_header *,
61                                                  struct mb_cache_entry **);
62 @@ -405,7 +406,7 @@ bad_block:
63                 error = -EIO;
64                 goto cleanup;
65         }
66 -       ext4_xattr_cache_insert(bh);
67 +       ext4_xattr_cache_insert(inode->i_sb, bh);
68         entry = BFIRST(bh);
69         error = ext4_xattr_find_entry(&entry, name_index, name, bh->b_size, 1,
70                                       inode);
71 @@ -569,7 +570,7 @@ ext4_xattr_block_list(struct dentry *den
72                 error = -EIO;
73                 goto cleanup;
74         }
75 -       ext4_xattr_cache_insert(bh);
76 +       ext4_xattr_cache_insert(inode->i_sb, bh);
77         error = ext4_xattr_list_entries(dentry, BFIRST(bh), buffer, buffer_size);
78  
79  cleanup:
80 @@ -667,7 +668,9 @@ ext4_xattr_release_block(handle_t *handl
81         struct mb_cache_entry *ce = NULL;
82         int error = 0;
83  
84 -       ce = mb_cache_entry_get(ext4_xattr_cache, bh->b_bdev, bh->b_blocknr);
85 +       if (!test_opt(inode->i_sb, NO_MBCACHE))
86 +               ce = mb_cache_entry_get(ext4_xattr_cache, bh->b_bdev,
87 +                                       bh->b_blocknr);
88         BUFFER_TRACE(bh, "get_write_access");
89         error = ext4_journal_get_write_access(handle, bh);
90         if (error)
91 @@ -1082,8 +1085,10 @@ ext4_xattr_block_set(handle_t *handle, s
92  #define header(x) ((struct ext4_xattr_header *)(x))
93  
94         if (s->base) {
95 -               ce = mb_cache_entry_get(ext4_xattr_cache, bs->bh->b_bdev,
96 -                                       bs->bh->b_blocknr);
97 +               if (!test_opt(inode->i_sb, NO_MBCACHE))
98 +                       ce = mb_cache_entry_get(ext4_xattr_cache,
99 +                                               bs->bh->b_bdev,
100 +                                               bs->bh->b_blocknr);
101                 BUFFER_TRACE(bs->bh, "get_write_access");
102                 error = ext4_journal_get_write_access(handle, bs->bh);
103                 if (error)
104 @@ -1101,7 +1106,7 @@ ext4_xattr_block_set(handle_t *handle, s
105                                 if (!IS_LAST_ENTRY(s->first))
106                                         ext4_xattr_rehash(header(s->base),
107                                                           s->here);
108 -                               ext4_xattr_cache_insert(bs->bh);
109 +                               ext4_xattr_cache_insert(sb, bs->bh);
110                         }
111                         unlock_buffer(bs->bh);
112                         if (error == -EIO)
113 @@ -1185,7 +1190,8 @@ inserted:
114                                 if (error)
115                                         goto cleanup_dquot;
116                         }
117 -                       mb_cache_entry_release(ce);
118 +                       if (ce)
119 +                               mb_cache_entry_release(ce);
120                         ce = NULL;
121                 } else if (bs->bh && s->base == bs->bh->b_data) {
122                         /* We were modifying this block in-place. */
123 @@ -1238,7 +1244,7 @@ getblk_failed:
124                         memcpy(new_bh->b_data, s->base, new_bh->b_size);
125                         set_buffer_uptodate(new_bh);
126                         unlock_buffer(new_bh);
127 -                       ext4_xattr_cache_insert(new_bh);
128 +                       ext4_xattr_cache_insert(sb, new_bh);
129                         error = ext4_handle_dirty_xattr_block(handle,
130                                                               inode, new_bh);
131                         if (error)
132 @@ -2022,12 +2028,15 @@ ext4_xattr_put_super(struct super_block
133   * Returns 0, or a negative error number on failure.
134   */
135  static void
136 -ext4_xattr_cache_insert(struct buffer_head *bh)
137 +ext4_xattr_cache_insert(struct super_block *sb, struct buffer_head *bh)
138  {
139         __u32 hash = le32_to_cpu(BHDR(bh)->h_hash);
140         struct mb_cache_entry *ce;
141         int error;
142  
143 +       if (test_opt(sb, NO_MBCACHE))
144 +               return;
145 +
146         ce = mb_cache_entry_alloc(ext4_xattr_cache, GFP_NOFS);
147         if (!ce) {
148                 ea_bdebug(bh, "out of memory");
149 @@ -2100,6 +2109,8 @@ ext4_xattr_cache_find(struct inode *inod
150         __u32 hash = le32_to_cpu(header->h_hash);
151         struct mb_cache_entry *ce;
152  
153 +       if (test_opt(inode->i_sb, NO_MBCACHE))
154 +               return NULL;
155         if (!header->h_hash)
156                 return NULL;  /* never share */
157         ea_idebug(inode, "looking for cached blocks [%x]", (int)hash);