btrfs fixes from next
[opensuse:kernel-source.git] / patches.suse / btrfs-8141-use-a-slab-for-ordered-extents-allocation.patch
1 From: Miao Xie <miaox@cn.fujitsu.com>
2 Date: Thu, 6 Sep 2012 04:01:51 -0600
3 Patch-mainline: pending
4 References: FATE#306586
5 Subject: [PATCH] Btrfs: use a slab for ordered extents allocation
6
7 The ordered extent allocation is in the fast path of the IO, so use a slab
8 to improve the speed of the allocation.
9
10  "Size of the struct is 280, so this will fall into the size-512 bucket,
11   giving 8 objects per page, while own slab will pack 14 objects into a page.
12
13   Another benefit I see is to check for leaked objects when the module is
14   removed (and the cache destroy takes place)."
15                                                 -- David Sterba
16
17 Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
18 Signed-off-by: David Sterba <dsterba@suse.cz>
19 ---
20  fs/btrfs/ordered-data.c |   23 +++++++++++++++++++++--
21  fs/btrfs/ordered-data.h |    2 ++
22  fs/btrfs/super.c        |    9 ++++++++-
23  3 files changed, 31 insertions(+), 3 deletions(-)
24
25 diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
26 index 051c7fe..8b11b74 100644
27 --- a/fs/btrfs/ordered-data.c
28 +++ b/fs/btrfs/ordered-data.c
29 @@ -25,6 +25,8 @@
30  #include "btrfs_inode.h"
31  #include "extent_io.h"
32  
33 +static struct kmem_cache *btrfs_ordered_extent_cache;
34 +
35  static u64 entry_end(struct btrfs_ordered_extent *entry)
36  {
37         if (entry->file_offset + entry->len < entry->file_offset)
38 @@ -187,7 +189,7 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
39         struct btrfs_ordered_extent *entry;
40  
41         tree = &BTRFS_I(inode)->ordered_tree;
42 -       entry = kzalloc(sizeof(*entry), GFP_NOFS);
43 +       entry = kmem_cache_zalloc(btrfs_ordered_extent_cache, GFP_NOFS);
44         if (!entry)
45                 return -ENOMEM;
46  
47 @@ -421,7 +423,7 @@ void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry)
48                         list_del(&sum->list);
49                         kfree(sum);
50                 }
51 -               kfree(entry);
52 +               kmem_cache_free(btrfs_ordered_extent_cache, entry);
53         }
54  }
55  
56 @@ -984,3 +986,20 @@ void btrfs_add_ordered_operation(struct btrfs_trans_handle *trans,
57         }
58         spin_unlock(&root->fs_info->ordered_extent_lock);
59  }
60 +
61 +int __init ordered_data_init(void)
62 +{
63 +       btrfs_ordered_extent_cache = kmem_cache_create("btrfs_ordered_extent",
64 +                                    sizeof(struct btrfs_ordered_extent), 0,
65 +                                    SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
66 +                                    NULL);
67 +       if (!btrfs_ordered_extent_cache)
68 +               return -ENOMEM;
69 +       return 0;
70 +}
71 +
72 +void ordered_data_exit(void)
73 +{
74 +       if (btrfs_ordered_extent_cache)
75 +               kmem_cache_destroy(btrfs_ordered_extent_cache);
76 +}
77 diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
78 index e03c560..23ea8db 100644
79 --- a/fs/btrfs/ordered-data.h
80 +++ b/fs/btrfs/ordered-data.h
81 @@ -185,4 +185,6 @@ void btrfs_add_ordered_operation(struct btrfs_trans_handle *trans,
82                                  struct inode *inode);
83  void btrfs_wait_ordered_extents(struct btrfs_root *root,
84                                 int nocow_only, int delay_iput);
85 +int __init ordered_data_init(void);
86 +void ordered_data_exit(void);
87  #endif
88 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
89 index 83d6f9f..06ff1dd 100644
90 --- a/fs/btrfs/super.c
91 +++ b/fs/btrfs/super.c
92 @@ -1620,10 +1620,14 @@ static int __init init_btrfs_fs(void)
93         if (err)
94                 goto free_extent_io;
95  
96 -       err = btrfs_delayed_inode_init();
97 +       err = ordered_data_init();
98         if (err)
99                 goto free_extent_map;
100  
101 +       err = btrfs_delayed_inode_init();
102 +       if (err)
103 +               goto free_ordered_data;
104 +
105         err = btrfs_interface_init();
106         if (err)
107                 goto free_delayed_inode;
108 @@ -1641,6 +1645,8 @@ unregister_ioctl:
109         btrfs_interface_exit();
110  free_delayed_inode:
111         btrfs_delayed_inode_exit();
112 +free_ordered_data:
113 +       ordered_data_exit();
114  free_extent_map:
115         extent_map_exit();
116  free_extent_io:
117 @@ -1657,6 +1663,7 @@ static void __exit exit_btrfs_fs(void)
118  {
119         btrfs_destroy_cachep();
120         btrfs_delayed_inode_exit();
121 +       ordered_data_exit();
122         extent_map_exit();
123         extent_io_exit();
124         btrfs_interface_exit();
125 -- 
126 1.7.9
127