Commit 53863232 authored by Chris Mason's avatar Chris Mason

Btrfs: Lower contention on the csum mutex

This takes the csum mutex deeper in the call chain and releases it
more often.
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 4854ddd0
...@@ -48,6 +48,7 @@ struct btrfs_worker_thread { ...@@ -48,6 +48,7 @@ struct btrfs_worker_thread {
/* number of things on the pending list */ /* number of things on the pending list */
atomic_t num_pending; atomic_t num_pending;
unsigned long sequence; unsigned long sequence;
/* protects the pending list. */ /* protects the pending list. */
...@@ -242,7 +243,7 @@ static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers) ...@@ -242,7 +243,7 @@ static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers)
worker = list_entry(next, struct btrfs_worker_thread, worker_list); worker = list_entry(next, struct btrfs_worker_thread, worker_list);
atomic_inc(&worker->num_pending); atomic_inc(&worker->num_pending);
worker->sequence++; worker->sequence++;
if (worker->sequence % 4 == 0) if (worker->sequence % workers->idle_thresh == 0)
list_move_tail(next, &workers->worker_list); list_move_tail(next, &workers->worker_list);
return worker; return worker;
} }
......
...@@ -1386,7 +1386,14 @@ struct btrfs_root *open_ctree(struct super_block *sb, ...@@ -1386,7 +1386,14 @@ struct btrfs_root *open_ctree(struct super_block *sb,
* devices * devices
*/ */
fs_info->submit_workers.idle_thresh = 64; fs_info->submit_workers.idle_thresh = 64;
fs_info->workers.idle_thresh = 32;
/* fs_info->workers is responsible for checksumming file data
* blocks and metadata. Using a larger idle thresh allows each
* worker thread to operate on things in roughly the order they
* were sent by the writeback daemons, improving overall locality
* of the IO going down the pipe.
*/
fs_info->workers.idle_thresh = 128;
btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1); btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1);
btrfs_init_workers(&fs_info->endio_workers, "endio", btrfs_init_workers(&fs_info->endio_workers, "endio",
......
...@@ -321,6 +321,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ...@@ -321,6 +321,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
file_key.offset = offset; file_key.offset = offset;
btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY);
mutex_lock(&BTRFS_I(inode)->csum_mutex);
item = btrfs_lookup_csum(trans, root, path, objectid, offset, 1); item = btrfs_lookup_csum(trans, root, path, objectid, offset, 1);
if (!IS_ERR(item)) { if (!IS_ERR(item)) {
leaf = path->nodes[0]; leaf = path->nodes[0];
...@@ -367,7 +368,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ...@@ -367,7 +368,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
ret = btrfs_search_slot(trans, root, &file_key, path, ret = btrfs_search_slot(trans, root, &file_key, path,
BTRFS_CRC32_SIZE, 1); BTRFS_CRC32_SIZE, 1);
if (ret < 0) if (ret < 0)
goto fail; goto fail_unlock;
if (ret == 0) { if (ret == 0) {
BUG(); BUG();
} }
...@@ -411,10 +412,10 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ...@@ -411,10 +412,10 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
ret = btrfs_insert_empty_item(trans, root, path, &file_key, ret = btrfs_insert_empty_item(trans, root, path, &file_key,
ins_size); ins_size);
if (ret < 0) if (ret < 0)
goto fail; goto fail_unlock;
if (ret != 0) { if (ret != 0) {
WARN_ON(1); WARN_ON(1);
goto fail; goto fail_unlock;
} }
csum: csum:
leaf = path->nodes[0]; leaf = path->nodes[0];
...@@ -427,6 +428,8 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ...@@ -427,6 +428,8 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
item_end = (struct btrfs_csum_item *)((unsigned char *)item_end + item_end = (struct btrfs_csum_item *)((unsigned char *)item_end +
btrfs_item_size_nr(leaf, path->slots[0])); btrfs_item_size_nr(leaf, path->slots[0]));
eb_token = NULL; eb_token = NULL;
mutex_unlock(&BTRFS_I(inode)->csum_mutex);
cond_resched();
next_sector: next_sector:
if (!eb_token || if (!eb_token ||
...@@ -467,13 +470,18 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ...@@ -467,13 +470,18 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
eb_token = NULL; eb_token = NULL;
} }
btrfs_mark_buffer_dirty(path->nodes[0]); btrfs_mark_buffer_dirty(path->nodes[0]);
cond_resched();
if (total_bytes < sums->len) { if (total_bytes < sums->len) {
btrfs_release_path(root, path); btrfs_release_path(root, path);
goto again; goto again;
} }
fail: out:
btrfs_free_path(path); btrfs_free_path(path);
return ret; return ret;
fail_unlock:
mutex_unlock(&BTRFS_I(inode)->csum_mutex);
goto out;
} }
int btrfs_csum_truncate(struct btrfs_trans_handle *trans, int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
......
...@@ -415,10 +415,8 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans, ...@@ -415,10 +415,8 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
btrfs_set_trans_block_group(trans, inode); btrfs_set_trans_block_group(trans, inode);
list_for_each(cur, list) { list_for_each(cur, list) {
sum = list_entry(cur, struct btrfs_ordered_sum, list); sum = list_entry(cur, struct btrfs_ordered_sum, list);
mutex_lock(&BTRFS_I(inode)->csum_mutex);
btrfs_csum_file_blocks(trans, BTRFS_I(inode)->root, btrfs_csum_file_blocks(trans, BTRFS_I(inode)->root,
inode, sum); inode, sum);
mutex_unlock(&BTRFS_I(inode)->csum_mutex);
} }
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment