Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 346711
b: refs/heads/master
c: 9247f31
h: refs/heads/master
i:
  346709: 176c0b2
  346707: 67cb771
  346703: a8bdc95
v: v3
  • Loading branch information
Miao Xie authored and Chris Mason committed Dec 17, 2012
1 parent 2065947 commit 6f00df1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 905b0dda06a064db08b8a814e968786ff3c4cc19
refs/heads/master: 9247f3170b2c3d648707c93bbebcd763fac17c06
2 changes: 2 additions & 0 deletions trunk/fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3505,6 +3505,8 @@ void btrfs_get_block_group_info(struct list_head *groups_list,
struct btrfs_ioctl_space_info *space);

/* file.c */
int btrfs_auto_defrag_init(void);
void btrfs_auto_defrag_exit(void);
int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
struct inode *inode);
int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info);
Expand Down
28 changes: 24 additions & 4 deletions trunk/fs/btrfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "compat.h"
#include "volumes.h"

static struct kmem_cache *btrfs_inode_defrag_cachep;
/*
* when auto defrag is enabled we
* queue up these defrag structs to remember which
Expand Down Expand Up @@ -127,7 +128,7 @@ static void __btrfs_add_inode_defrag(struct inode *inode,
return;

exists:
kfree(defrag);
kmem_cache_free(btrfs_inode_defrag_cachep, defrag);
return;

}
Expand Down Expand Up @@ -157,7 +158,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
else
transid = BTRFS_I(inode)->root->last_trans;

defrag = kzalloc(sizeof(*defrag), GFP_NOFS);
defrag = kmem_cache_zalloc(btrfs_inode_defrag_cachep, GFP_NOFS);
if (!defrag)
return -ENOMEM;

Expand All @@ -169,7 +170,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
if (!test_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags))
__btrfs_add_inode_defrag(inode, defrag);
else
kfree(defrag);
kmem_cache_free(btrfs_inode_defrag_cachep, defrag);
spin_unlock(&root->fs_info->defrag_inodes_lock);
return 0;
}
Expand Down Expand Up @@ -315,7 +316,8 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)
next:
spin_lock(&fs_info->defrag_inodes_lock);
next_free:
kfree(defrag);
if (defrag)
kmem_cache_free(btrfs_inode_defrag_cachep, defrag);
}
spin_unlock(&fs_info->defrag_inodes_lock);

Expand Down Expand Up @@ -2293,3 +2295,21 @@ const struct file_operations btrfs_file_operations = {
.compat_ioctl = btrfs_ioctl,
#endif
};

void btrfs_auto_defrag_exit(void)
{
if (btrfs_inode_defrag_cachep)
kmem_cache_destroy(btrfs_inode_defrag_cachep);
}

int btrfs_auto_defrag_init(void)
{
btrfs_inode_defrag_cachep = kmem_cache_create("btrfs_inode_defrag",
sizeof(struct inode_defrag), 0,
SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
NULL);
if (!btrfs_inode_defrag_cachep)
return -ENOMEM;

return 0;
}
9 changes: 8 additions & 1 deletion trunk/fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1680,10 +1680,14 @@ static int __init init_btrfs_fs(void)
if (err)
goto free_ordered_data;

err = btrfs_interface_init();
err = btrfs_auto_defrag_init();
if (err)
goto free_delayed_inode;

err = btrfs_interface_init();
if (err)
goto free_auto_defrag;

err = register_filesystem(&btrfs_fs_type);
if (err)
goto unregister_ioctl;
Expand All @@ -1695,6 +1699,8 @@ static int __init init_btrfs_fs(void)

unregister_ioctl:
btrfs_interface_exit();
free_auto_defrag:
btrfs_auto_defrag_exit();
free_delayed_inode:
btrfs_delayed_inode_exit();
free_ordered_data:
Expand All @@ -1714,6 +1720,7 @@ static int __init init_btrfs_fs(void)
static void __exit exit_btrfs_fs(void)
{
btrfs_destroy_cachep();
btrfs_auto_defrag_exit();
btrfs_delayed_inode_exit();
ordered_data_exit();
extent_map_exit();
Expand Down

0 comments on commit 6f00df1

Please sign in to comment.