Skip to content

Commit

Permalink
Btrfs: Wait for async bio submissions to make some progress at queue …
Browse files Browse the repository at this point in the history
…time

Before, the btrfs bdi congestion function was used to test for too many
async bios.  This keeps that check to throttle pdflush, but also
adds a check while queuing bios.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
  • Loading branch information
Chris Mason committed Sep 25, 2008
1 parent 4d1b5fb commit b64a285
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
16 changes: 9 additions & 7 deletions fs/btrfs/disk-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ int btrfs_bio_wq_end_io(struct btrfs_fs_info *info, struct bio *bio,
return 0;
}

static unsigned long async_submit_limit(struct btrfs_fs_info *info)
unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info)
{
unsigned long limit = min_t(unsigned long,
info->workers.max_workers,
Expand All @@ -439,7 +439,8 @@ static unsigned long async_submit_limit(struct btrfs_fs_info *info)

int btrfs_congested_async(struct btrfs_fs_info *info, int iodone)
{
return atomic_read(&info->nr_async_bios) > async_submit_limit(info);
return atomic_read(&info->nr_async_bios) >
btrfs_async_submit_limit(info);
}

static void run_one_async_submit(struct btrfs_work *work)
Expand All @@ -451,12 +452,13 @@ static void run_one_async_submit(struct btrfs_work *work)
async = container_of(work, struct async_submit_bio, work);
fs_info = BTRFS_I(async->inode)->root->fs_info;

limit = async_submit_limit(fs_info);
limit = btrfs_async_submit_limit(fs_info);
limit = limit * 2 / 3;

atomic_dec(&fs_info->nr_async_submits);

if (atomic_read(&fs_info->nr_async_submits) < limit)
if (atomic_read(&fs_info->nr_async_submits) < limit &&
waitqueue_active(&fs_info->async_submit_wait))
wake_up(&fs_info->async_submit_wait);

async->submit_bio_hook(async->inode, async->rw, async->bio,
Expand All @@ -469,7 +471,7 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode,
extent_submit_bio_hook_t *submit_bio_hook)
{
struct async_submit_bio *async;
int limit = async_submit_limit(fs_info);
int limit = btrfs_async_submit_limit(fs_info);

async = kmalloc(sizeof(*async), GFP_NOFS);
if (!async)
Expand Down Expand Up @@ -1863,10 +1865,10 @@ void btrfs_btree_balance_dirty(struct btrfs_root *root, unsigned long nr)
struct extent_io_tree *tree;
u64 num_dirty;
u64 start = 0;
unsigned long thresh = 12 * 1024 * 1024;
unsigned long thresh = 96 * 1024 * 1024;
tree = &BTRFS_I(root->fs_info->btree_inode)->io_tree;

if (current_is_pdflush())
if (current_is_pdflush() || current->flags & PF_MEMALLOC)
return;

num_dirty = count_range_bits(tree, &start, (u64)-1,
Expand Down
1 change: 1 addition & 0 deletions fs/btrfs/disk-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ int btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct inode *inode,
int rw, struct bio *bio, int mirror_num,
extent_submit_bio_hook_t *submit_bio_hook);
int btrfs_congested_async(struct btrfs_fs_info *info, int iodone);
unsigned long btrfs_async_submit_limit(struct btrfs_fs_info *info);
#endif
2 changes: 0 additions & 2 deletions fs/btrfs/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ int btrfs_write_and_wait_transaction(struct btrfs_trans_handle *trans,
if (ret)
break;
while(start <= end) {
if (btrfs_congested_async(root->fs_info, 0))
congestion_wait(WRITE, HZ/10);
cond_resched();

index = start >> PAGE_CACHE_SHIFT;
Expand Down
18 changes: 17 additions & 1 deletion fs/btrfs/volumes.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,18 @@ int run_scheduled_bios(struct btrfs_device *device)
{
struct bio *pending;
struct backing_dev_info *bdi;
struct btrfs_fs_info *fs_info;
struct bio *tail;
struct bio *cur;
int again = 0;
unsigned long num_run = 0;
unsigned long limit;

bdi = device->bdev->bd_inode->i_mapping->backing_dev_info;
fs_info = device->dev_root->fs_info;
limit = btrfs_async_submit_limit(fs_info);
limit = limit * 2 / 3;

loop:
spin_lock(&device->io_lock);

Expand Down Expand Up @@ -179,7 +185,11 @@ int run_scheduled_bios(struct btrfs_device *device)
cur = pending;
pending = pending->bi_next;
cur->bi_next = NULL;
atomic_dec(&device->dev_root->fs_info->nr_async_bios);
atomic_dec(&fs_info->nr_async_bios);

if (atomic_read(&fs_info->nr_async_bios) < limit &&
waitqueue_active(&fs_info->async_submit_wait))
wake_up(&fs_info->async_submit_wait);

BUG_ON(atomic_read(&cur->bi_cnt) == 0);
bio_get(cur);
Expand Down Expand Up @@ -2135,6 +2145,7 @@ int schedule_bio(struct btrfs_root *root, struct btrfs_device *device,
int rw, struct bio *bio)
{
int should_queue = 1;
unsigned long limit;

/* don't bother with additional async steps for reads, right now */
if (!(rw & (1 << BIO_RW))) {
Expand Down Expand Up @@ -2171,6 +2182,11 @@ int schedule_bio(struct btrfs_root *root, struct btrfs_device *device,
if (should_queue)
btrfs_queue_worker(&root->fs_info->submit_workers,
&device->work);

limit = btrfs_async_submit_limit(root->fs_info);
wait_event_timeout(root->fs_info->async_submit_wait,
(atomic_read(&root->fs_info->nr_async_bios) < limit),
HZ/10);
return 0;
}

Expand Down

0 comments on commit b64a285

Please sign in to comment.