aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-08-15 15:34:18 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:06 -0400
commit53863232ef961778aa414b700ed88a48e8e871e6 (patch)
tree05a74ac264a5fb4f6b8824771f5820ca5907afe5
parent4854ddd0ed0a687fc2d7c45a529c406232e31e7b (diff)
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: Chris Mason <chris.mason@oracle.com>
-rw-r--r--fs/btrfs/async-thread.c3
-rw-r--r--fs/btrfs/disk-io.c9
-rw-r--r--fs/btrfs/file-item.c16
-rw-r--r--fs/btrfs/inode.c2
4 files changed, 22 insertions, 8 deletions
diff --git a/fs/btrfs/async-thread.c b/fs/btrfs/async-thread.c
index 958cd8b5f0d7..2ee301740195 100644
--- a/fs/btrfs/async-thread.c
+++ b/fs/btrfs/async-thread.c
@@ -48,6 +48,7 @@ struct btrfs_worker_thread {
48 48
49 /* number of things on the pending list */ 49 /* number of things on the pending list */
50 atomic_t num_pending; 50 atomic_t num_pending;
51
51 unsigned long sequence; 52 unsigned long sequence;
52 53
53 /* protects the pending list. */ 54 /* protects the pending list. */
@@ -242,7 +243,7 @@ static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers)
242 worker = list_entry(next, struct btrfs_worker_thread, worker_list); 243 worker = list_entry(next, struct btrfs_worker_thread, worker_list);
243 atomic_inc(&worker->num_pending); 244 atomic_inc(&worker->num_pending);
244 worker->sequence++; 245 worker->sequence++;
245 if (worker->sequence % 4 == 0) 246 if (worker->sequence % workers->idle_thresh == 0)
246 list_move_tail(next, &workers->worker_list); 247 list_move_tail(next, &workers->worker_list);
247 return worker; 248 return worker;
248} 249}
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 1aed1f4616b6..92e14dd9bddb 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1386,7 +1386,14 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1386 * devices 1386 * devices
1387 */ 1387 */
1388 fs_info->submit_workers.idle_thresh = 64; 1388 fs_info->submit_workers.idle_thresh = 64;
1389 fs_info->workers.idle_thresh = 32; 1389
1390 /* fs_info->workers is responsible for checksumming file data
1391 * blocks and metadata. Using a larger idle thresh allows each
1392 * worker thread to operate on things in roughly the order they
1393 * were sent by the writeback daemons, improving overall locality
1394 * of the IO going down the pipe.
1395 */
1396 fs_info->workers.idle_thresh = 128;
1390 1397
1391 btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1); 1398 btrfs_init_workers(&fs_info->fixup_workers, "fixup", 1);
1392 btrfs_init_workers(&fs_info->endio_workers, "endio", 1399 btrfs_init_workers(&fs_info->endio_workers, "endio",
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 51aba8cee7ce..9454e0a07c89 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -321,6 +321,7 @@ again:
321 file_key.offset = offset; 321 file_key.offset = offset;
322 btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY); 322 btrfs_set_key_type(&file_key, BTRFS_CSUM_ITEM_KEY);
323 323
324 mutex_lock(&BTRFS_I(inode)->csum_mutex);
324 item = btrfs_lookup_csum(trans, root, path, objectid, offset, 1); 325 item = btrfs_lookup_csum(trans, root, path, objectid, offset, 1);
325 if (!IS_ERR(item)) { 326 if (!IS_ERR(item)) {
326 leaf = path->nodes[0]; 327 leaf = path->nodes[0];
@@ -367,7 +368,7 @@ again:
367 ret = btrfs_search_slot(trans, root, &file_key, path, 368 ret = btrfs_search_slot(trans, root, &file_key, path,
368 BTRFS_CRC32_SIZE, 1); 369 BTRFS_CRC32_SIZE, 1);
369 if (ret < 0) 370 if (ret < 0)
370 goto fail; 371 goto fail_unlock;
371 if (ret == 0) { 372 if (ret == 0) {
372 BUG(); 373 BUG();
373 } 374 }
@@ -411,10 +412,10 @@ insert:
411 ret = btrfs_insert_empty_item(trans, root, path, &file_key, 412 ret = btrfs_insert_empty_item(trans, root, path, &file_key,
412 ins_size); 413 ins_size);
413 if (ret < 0) 414 if (ret < 0)
414 goto fail; 415 goto fail_unlock;
415 if (ret != 0) { 416 if (ret != 0) {
416 WARN_ON(1); 417 WARN_ON(1);
417 goto fail; 418 goto fail_unlock;
418 } 419 }
419csum: 420csum:
420 leaf = path->nodes[0]; 421 leaf = path->nodes[0];
@@ -427,6 +428,8 @@ found:
427 item_end = (struct btrfs_csum_item *)((unsigned char *)item_end + 428 item_end = (struct btrfs_csum_item *)((unsigned char *)item_end +
428 btrfs_item_size_nr(leaf, path->slots[0])); 429 btrfs_item_size_nr(leaf, path->slots[0]));
429 eb_token = NULL; 430 eb_token = NULL;
431 mutex_unlock(&BTRFS_I(inode)->csum_mutex);
432 cond_resched();
430next_sector: 433next_sector:
431 434
432 if (!eb_token || 435 if (!eb_token ||
@@ -467,13 +470,18 @@ next_sector:
467 eb_token = NULL; 470 eb_token = NULL;
468 } 471 }
469 btrfs_mark_buffer_dirty(path->nodes[0]); 472 btrfs_mark_buffer_dirty(path->nodes[0]);
473 cond_resched();
470 if (total_bytes < sums->len) { 474 if (total_bytes < sums->len) {
471 btrfs_release_path(root, path); 475 btrfs_release_path(root, path);
472 goto again; 476 goto again;
473 } 477 }
474fail: 478out:
475 btrfs_free_path(path); 479 btrfs_free_path(path);
476 return ret; 480 return ret;
481
482fail_unlock:
483 mutex_unlock(&BTRFS_I(inode)->csum_mutex);
484 goto out;
477} 485}
478 486
479int btrfs_csum_truncate(struct btrfs_trans_handle *trans, 487int btrfs_csum_truncate(struct btrfs_trans_handle *trans,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 33b990878d84..65107894a5bb 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -415,10 +415,8 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans,
415 btrfs_set_trans_block_group(trans, inode); 415 btrfs_set_trans_block_group(trans, inode);
416 list_for_each(cur, list) { 416 list_for_each(cur, list) {
417 sum = list_entry(cur, struct btrfs_ordered_sum, list); 417 sum = list_entry(cur, struct btrfs_ordered_sum, list);
418 mutex_lock(&BTRFS_I(inode)->csum_mutex);
419 btrfs_csum_file_blocks(trans, BTRFS_I(inode)->root, 418 btrfs_csum_file_blocks(trans, BTRFS_I(inode)->root,
420 inode, sum); 419 inode, sum);
421 mutex_unlock(&BTRFS_I(inode)->csum_mutex);
422 } 420 }
423 return 0; 421 return 0;
424} 422}