aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/disk-io.c
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2013-01-29 05:10:51 -0500
committerJosef Bacik <jbacik@fusionio.com>2013-02-20 12:59:05 -0500
commit963d678b0f7649300e3a67f2513ca9d830c6e303 (patch)
tree4f7568f541891a7bbe8b279c98d21aec1cabe06f /fs/btrfs/disk-io.c
parente2d845211eda9cf296e8edf6724b3d541f4fbfd5 (diff)
Btrfs: use percpu counter for fs_info->delalloc_bytes
fs_info->delalloc_bytes is accessed very frequently, so use percpu counter instead of the u64 variant for it to reduce the lock contention. This patch also fixed the problem that we access the variant without the lock protection.At worst, we would not flush the delalloc inodes, and just return ENOSPC error when we still have some free space in the fs. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r--fs/btrfs/disk-io.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 34ace168eebc..2c9498aefe86 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2010,10 +2010,16 @@ int open_ctree(struct super_block *sb,
2010 fs_info->dirty_metadata_batch = PAGE_CACHE_SIZE * 2010 fs_info->dirty_metadata_batch = PAGE_CACHE_SIZE *
2011 (1 + ilog2(nr_cpu_ids)); 2011 (1 + ilog2(nr_cpu_ids));
2012 2012
2013 ret = percpu_counter_init(&fs_info->delalloc_bytes, 0);
2014 if (ret) {
2015 err = ret;
2016 goto fail_dirty_metadata_bytes;
2017 }
2018
2013 fs_info->btree_inode = new_inode(sb); 2019 fs_info->btree_inode = new_inode(sb);
2014 if (!fs_info->btree_inode) { 2020 if (!fs_info->btree_inode) {
2015 err = -ENOMEM; 2021 err = -ENOMEM;
2016 goto fail_dirty_metadata_bytes; 2022 goto fail_delalloc_bytes;
2017 } 2023 }
2018 2024
2019 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS); 2025 mapping_set_gfp_mask(fs_info->btree_inode->i_mapping, GFP_NOFS);
@@ -2269,6 +2275,7 @@ int open_ctree(struct super_block *sb,
2269 sectorsize = btrfs_super_sectorsize(disk_super); 2275 sectorsize = btrfs_super_sectorsize(disk_super);
2270 stripesize = btrfs_super_stripesize(disk_super); 2276 stripesize = btrfs_super_stripesize(disk_super);
2271 fs_info->dirty_metadata_batch = leafsize * (1 + ilog2(nr_cpu_ids)); 2277 fs_info->dirty_metadata_batch = leafsize * (1 + ilog2(nr_cpu_ids));
2278 fs_info->delalloc_batch = sectorsize * 512 * (1 + ilog2(nr_cpu_ids));
2272 2279
2273 /* 2280 /*
2274 * mixed block groups end up with duplicate but slightly offset 2281 * mixed block groups end up with duplicate but slightly offset
@@ -2731,6 +2738,8 @@ fail_iput:
2731 2738
2732 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); 2739 invalidate_inode_pages2(fs_info->btree_inode->i_mapping);
2733 iput(fs_info->btree_inode); 2740 iput(fs_info->btree_inode);
2741fail_delalloc_bytes:
2742 percpu_counter_destroy(&fs_info->delalloc_bytes);
2734fail_dirty_metadata_bytes: 2743fail_dirty_metadata_bytes:
2735 percpu_counter_destroy(&fs_info->dirty_metadata_bytes); 2744 percpu_counter_destroy(&fs_info->dirty_metadata_bytes);
2736fail_bdi: 2745fail_bdi:
@@ -3362,9 +3371,9 @@ int close_ctree(struct btrfs_root *root)
3362 3371
3363 btrfs_free_qgroup_config(root->fs_info); 3372 btrfs_free_qgroup_config(root->fs_info);
3364 3373
3365 if (fs_info->delalloc_bytes) { 3374 if (percpu_counter_sum(&fs_info->delalloc_bytes)) {
3366 printk(KERN_INFO "btrfs: at unmount delalloc count %llu\n", 3375 printk(KERN_INFO "btrfs: at unmount delalloc count %lld\n",
3367 (unsigned long long)fs_info->delalloc_bytes); 3376 percpu_counter_sum(&fs_info->delalloc_bytes));
3368 } 3377 }
3369 3378
3370 free_extent_buffer(fs_info->extent_root->node); 3379 free_extent_buffer(fs_info->extent_root->node);
@@ -3412,6 +3421,7 @@ int close_ctree(struct btrfs_root *root)
3412 btrfs_mapping_tree_free(&fs_info->mapping_tree); 3421 btrfs_mapping_tree_free(&fs_info->mapping_tree);
3413 3422
3414 percpu_counter_destroy(&fs_info->dirty_metadata_bytes); 3423 percpu_counter_destroy(&fs_info->dirty_metadata_bytes);
3424 percpu_counter_destroy(&fs_info->delalloc_bytes);
3415 bdi_destroy(&fs_info->bdi); 3425 bdi_destroy(&fs_info->bdi);
3416 cleanup_srcu_struct(&fs_info->subvol_srcu); 3426 cleanup_srcu_struct(&fs_info->subvol_srcu);
3417 3427