aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2012-09-06 06:01:51 -0400
committerChris Mason <chris.mason@fusionio.com>2012-10-01 15:19:11 -0400
commit6352b91da1a2108bb8cc5115e8714f90d706f15f (patch)
tree41897bbe836bb7f8b2bbfef24528407d1c79b8b0
parentb9a8cc5bef963b76c5b6c3016b7e91988a3e758b (diff)
Btrfs: use a slab for ordered extents allocation
The ordered extent allocation is in the fast path of the IO, so use a slab to improve the speed of the allocation. "Size of the struct is 280, so this will fall into the size-512 bucket, giving 8 objects per page, while own slab will pack 14 objects into a page. Another benefit I see is to check for leaked objects when the module is removed (and the cache destroy takes place)." -- David Sterba Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
-rw-r--r--fs/btrfs/ordered-data.c23
-rw-r--r--fs/btrfs/ordered-data.h2
-rw-r--r--fs/btrfs/super.c9
3 files changed, 31 insertions, 3 deletions
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index cd8ecb73c05c..e2b3d994ec01 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -25,6 +25,8 @@
25#include "btrfs_inode.h" 25#include "btrfs_inode.h"
26#include "extent_io.h" 26#include "extent_io.h"
27 27
28static struct kmem_cache *btrfs_ordered_extent_cache;
29
28static u64 entry_end(struct btrfs_ordered_extent *entry) 30static u64 entry_end(struct btrfs_ordered_extent *entry)
29{ 31{
30 if (entry->file_offset + entry->len < entry->file_offset) 32 if (entry->file_offset + entry->len < entry->file_offset)
@@ -187,7 +189,7 @@ static int __btrfs_add_ordered_extent(struct inode *inode, u64 file_offset,
187 struct btrfs_ordered_extent *entry; 189 struct btrfs_ordered_extent *entry;
188 190
189 tree = &BTRFS_I(inode)->ordered_tree; 191 tree = &BTRFS_I(inode)->ordered_tree;
190 entry = kzalloc(sizeof(*entry), GFP_NOFS); 192 entry = kmem_cache_zalloc(btrfs_ordered_extent_cache, GFP_NOFS);
191 if (!entry) 193 if (!entry)
192 return -ENOMEM; 194 return -ENOMEM;
193 195
@@ -421,7 +423,7 @@ void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry)
421 list_del(&sum->list); 423 list_del(&sum->list);
422 kfree(sum); 424 kfree(sum);
423 } 425 }
424 kfree(entry); 426 kmem_cache_free(btrfs_ordered_extent_cache, entry);
425 } 427 }
426} 428}
427 429
@@ -958,3 +960,20 @@ void btrfs_add_ordered_operation(struct btrfs_trans_handle *trans,
958 } 960 }
959 spin_unlock(&root->fs_info->ordered_extent_lock); 961 spin_unlock(&root->fs_info->ordered_extent_lock);
960} 962}
963
964int __init ordered_data_init(void)
965{
966 btrfs_ordered_extent_cache = kmem_cache_create("btrfs_ordered_extent",
967 sizeof(struct btrfs_ordered_extent), 0,
968 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
969 NULL);
970 if (!btrfs_ordered_extent_cache)
971 return -ENOMEM;
972 return 0;
973}
974
975void ordered_data_exit(void)
976{
977 if (btrfs_ordered_extent_cache)
978 kmem_cache_destroy(btrfs_ordered_extent_cache);
979}
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index c2443a431ca5..d1ddaeff1356 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -192,4 +192,6 @@ void btrfs_add_ordered_operation(struct btrfs_trans_handle *trans,
192 struct inode *inode); 192 struct inode *inode);
193void btrfs_wait_ordered_extents(struct btrfs_root *root, 193void btrfs_wait_ordered_extents(struct btrfs_root *root,
194 int nocow_only, int delay_iput); 194 int nocow_only, int delay_iput);
195int __init ordered_data_init(void);
196void ordered_data_exit(void);
195#endif 197#endif
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 83d6f9f9c220..06ff1dd0f9b7 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1620,10 +1620,14 @@ static int __init init_btrfs_fs(void)
1620 if (err) 1620 if (err)
1621 goto free_extent_io; 1621 goto free_extent_io;
1622 1622
1623 err = btrfs_delayed_inode_init(); 1623 err = ordered_data_init();
1624 if (err) 1624 if (err)
1625 goto free_extent_map; 1625 goto free_extent_map;
1626 1626
1627 err = btrfs_delayed_inode_init();
1628 if (err)
1629 goto free_ordered_data;
1630
1627 err = btrfs_interface_init(); 1631 err = btrfs_interface_init();
1628 if (err) 1632 if (err)
1629 goto free_delayed_inode; 1633 goto free_delayed_inode;
@@ -1641,6 +1645,8 @@ unregister_ioctl:
1641 btrfs_interface_exit(); 1645 btrfs_interface_exit();
1642free_delayed_inode: 1646free_delayed_inode:
1643 btrfs_delayed_inode_exit(); 1647 btrfs_delayed_inode_exit();
1648free_ordered_data:
1649 ordered_data_exit();
1644free_extent_map: 1650free_extent_map:
1645 extent_map_exit(); 1651 extent_map_exit();
1646free_extent_io: 1652free_extent_io:
@@ -1657,6 +1663,7 @@ static void __exit exit_btrfs_fs(void)
1657{ 1663{
1658 btrfs_destroy_cachep(); 1664 btrfs_destroy_cachep();
1659 btrfs_delayed_inode_exit(); 1665 btrfs_delayed_inode_exit();
1666 ordered_data_exit();
1660 extent_map_exit(); 1667 extent_map_exit();
1661 extent_io_exit(); 1668 extent_io_exit();
1662 btrfs_interface_exit(); 1669 btrfs_interface_exit();