Skip to content

Commit 777e6bd

Browse files
committed
Btrfs: Transaction commit: don't use filemap_fdatawait
After writing out all the remaining btree blocks in the transaction, the commit code would use filemap_fdatawait to make sure it was all on disk. This means it would wait for blocks written by other procs as well. The new code walks the list of blocks for this transaction again and waits only for those required by this transaction. Signed-off-by: Chris Mason <chris.mason@oracle.com>
1 parent 0986fe9 commit 777e6bd

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

‎fs/btrfs/disk-io.c‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
429429
return 0;
430430
}
431431

432-
static int congested_async(struct btrfs_fs_info *info, int iodone)
432+
int btrfs_congested_async(struct btrfs_fs_info *info, int iodone)
433433
{
434434
int limit = 256 * info->fs_devices->open_devices;
435435

@@ -438,9 +438,6 @@ static int congested_async(struct btrfs_fs_info *info, int iodone)
438438
if (atomic_read(&info->nr_async_submits) > limit)
439439
return 1;
440440

441-
limit = 8192 * info->fs_devices->open_devices;
442-
if (iodone)
443-
limit = (limit * 3) / 2;
444441
return atomic_read(&info->nr_async_bios) > limit;
445442
}
446443

@@ -454,7 +451,7 @@ static void run_one_async_submit(struct btrfs_work *work)
454451
atomic_dec(&fs_info->nr_async_submits);
455452

456453
if ((async->bio->bi_rw & (1 << BIO_RW)) &&
457-
!congested_async(fs_info, 1)) {
454+
!btrfs_congested_async(fs_info, 1)) {
458455
clear_bdi_congested(&fs_info->bdi, WRITE);
459456
}
460457
async->submit_bio_hook(async->inode, async->rw, async->bio,
@@ -963,7 +960,7 @@ static int btrfs_congested_fn(void *congested_data, int bdi_bits)
963960
struct backing_dev_info *bdi;
964961

965962
if ((bdi_bits & (1 << BDI_write_congested)) &&
966-
congested_async(info, 0))
963+
btrfs_congested_async(info, 0))
967964
return 1;
968965

969966
list_for_each(cur, &info->fs_devices->devices) {
@@ -1844,7 +1841,7 @@ void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr)
18441841
struct extent_io_tree *tree;
18451842
u64 num_dirty;
18461843
u64 start = 0;
1847-
unsigned long thresh = 16 * 1024 * 1024;
1844+
unsigned long thresh = 2 * 1024 * 1024;
18481845
tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree;
18491846

18501847
if (current_is_pdflush())

‎fs/btrfs/disk-io.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,5 @@ int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
7272
int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode,
7373
int rw, struct bio *bio, int mirror_num,
7474
extent_submit_bio_hook_t *submit_bio_hook);
75+
int btrfs_congested_async(struct btrfs_fs_info *info, int iodone);
7576
#endif

‎fs/btrfs/transaction.c‎

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
303303
struct btrfs_root *root)
304304
{
305305
int ret;
306-
int err;
306+
int err = 0;
307307
int werr = 0;
308308
struct extent_io_tree *dirty_pages;
309309
struct page *page;
310310
struct inode *btree_inode = root->fs_info->btree_inode;
311-
u64 start;
311+
u64 start = 0;
312312
u64 end;
313313
unsigned long index;
314314

@@ -317,12 +317,15 @@ int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
317317
}
318318
dirty_pages = &trans->transaction->dirty_pages;
319319
while(1) {
320-
ret = find_first_extent_bit(dirty_pages, 0, &start, &end,
320+
ret = find_first_extent_bit(dirty_pages, start, &start, &end,
321321
EXTENT_DIRTY);
322322
if (ret)
323323
break;
324-
clear_extent_dirty(dirty_pages, start, end, GFP_NOFS);
325324
while(start <= end) {
325+
if (btrfs_congested_async(root->fs_info, 0))
326+
congestion_wait(WRITE, HZ/10);
327+
cond_resched();
328+
326329
index = start >> PAGE_CACHE_SHIFT;
327330
start = (u64)(index + 1) << PAGE_CACHE_SHIFT;
328331
page = find_lock_page(btree_inode->i_mapping, index);
@@ -343,7 +346,30 @@ int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
343346
page_cache_release(page);
344347
}
345348
}
346-
err = filemap_fdatawait(btree_inode->i_mapping);
349+
while(1) {
350+
ret = find_first_extent_bit(dirty_pages, 0, &start, &end,
351+
EXTENT_DIRTY);
352+
if (ret)
353+
break;
354+
355+
clear_extent_dirty(dirty_pages, start, end, GFP_NOFS);
356+
while(start <= end) {
357+
index = start >> PAGE_CACHE_SHIFT;
358+
start = (u64)(index + 1) << PAGE_CACHE_SHIFT;
359+
page = find_get_page(btree_inode->i_mapping, index);
360+
if (!page)
361+
continue;
362+
if (PageDirty(page)) {
363+
lock_page(page);
364+
err = write_one_page(page, 0);
365+
if (err)
366+
werr = err;
367+
}
368+
wait_on_page_writeback(page);
369+
page_cache_release(page);
370+
cond_resched();
371+
}
372+
}
347373
if (err)
348374
werr = err;
349375
return werr;

0 commit comments

Comments
 (0)