diff options
author | David Sterba <dsterba@suse.com> | 2017-06-06 17:06:06 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2017-06-21 19:03:38 +0200 |
commit | e0ae999414238aa9c0a116844813982effb68a02 (patch) | |
tree | b127434d66d6eea75a6132b3e5b8176c2608e9d9 /fs/btrfs/disk-io.c | |
parent | fdb1388994e2ed0e1512006244022c721c650c5b (diff) | |
download | linux-stable-e0ae999414238aa9c0a116844813982effb68a02.tar.gz linux-stable-e0ae999414238aa9c0a116844813982effb68a02.tar.bz2 linux-stable-e0ae999414238aa9c0a116844813982effb68a02.zip |
btrfs: preallocate device flush bio
For devices that support flushing, we allocate a bio, submit, wait for
it and then free it. The bio allocation does not fail so ENOMEM is not a
problem but we still may unnecessarily stress the allocation subsystem.
Instead, we can allocate the bio at the same time we allocate the device
and reuse it each time we need to flush the barriers. The bio is reset
before each use. Reference counting is simplified to just device
allocation (get) and freeing (put).
The bio used to be submitted through the integrity checker which will
find out that bio has no data attached and call submit_bio.
Status of the bio in flight needs to be tracked separately in case the
device caches get switched off between write and wait.
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 2ac0a35f4450..bfcbab3a7607 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -3481,9 +3481,7 @@ static int write_dev_supers(struct btrfs_device *device, */ static void btrfs_end_empty_barrier(struct bio *bio) { - if (bio->bi_private) - complete(bio->bi_private); - bio_put(bio); + complete(bio->bi_private); } /* @@ -3493,26 +3491,20 @@ static void btrfs_end_empty_barrier(struct bio *bio) static void write_dev_flush(struct btrfs_device *device) { struct request_queue *q = bdev_get_queue(device->bdev); - struct bio *bio; + struct bio *bio = device->flush_bio; if (!test_bit(QUEUE_FLAG_WC, &q->queue_flags)) return; - /* - * one reference for us, and we leave it for the - * caller - */ - device->flush_bio = NULL; - bio = btrfs_io_bio_alloc(0); + bio_reset(bio); bio->bi_end_io = btrfs_end_empty_barrier; bio->bi_bdev = device->bdev; bio->bi_opf = REQ_OP_WRITE | REQ_SYNC | REQ_PREFLUSH; init_completion(&device->flush_wait); bio->bi_private = &device->flush_wait; - device->flush_bio = bio; - bio_get(bio); - btrfsic_submit_bio(bio); + submit_bio(bio); + device->flush_bio_sent = 1; } /* @@ -3523,9 +3515,10 @@ static int wait_dev_flush(struct btrfs_device *device) int ret = 0; struct bio *bio = device->flush_bio; - if (!bio) + if (!device->flush_bio_sent) return 0; + device->flush_bio_sent = 0; wait_for_completion(&device->flush_wait); if (bio->bi_error) { @@ -3534,10 +3527,6 @@ static int wait_dev_flush(struct btrfs_device *device) BTRFS_DEV_STAT_FLUSH_ERRS); } - /* drop the reference from the wait == 0 run */ - bio_put(bio); - device->flush_bio = NULL; - return ret; } |