fs: ext4: fsync: optimize double-fsync() a bunch

There are cases where EXT4 is a bit too conservative sending barriers down to
the disk; there are cases where the transaction in progress is not the one
that sent the barrier (in other words: the fsync is for a file for which the
IO happened more time ago and all data was already sent to the disk).

For that case, a more performing tradeoff can be made on SSD devices (which
have the ability to flush their dram caches in a hurry on a power fail event)
where the barrier gets sent to the disk, but we don't need to wait for the
barrier to complete. Any consecutive IO will block on the barrier correctly.

Signed-off-by: Diab Neiroukh <lazerl0rd@thezest.dev>
This commit is contained in:
Arjan van de Ven 2016-04-09 22:41:37 +00:00 committed by spakkkk
parent 6ff225f1cd
commit de7528f5bd
5 changed files with 71 additions and 1 deletions

View File

@ -938,6 +938,25 @@ int submit_bio_wait(struct bio *bio)
} }
EXPORT_SYMBOL(submit_bio_wait); EXPORT_SYMBOL(submit_bio_wait);
static void submit_bio_nowait_endio(struct bio *bio)
{
bio_put(bio);
}
/**
* submit_bio_nowait - submit a bio for fire-and-forget
* @bio: The &struct bio which describes the I/O
*
* Simple wrapper around submit_bio() that takes care of bio_put() on completion
*/
void submit_bio_nowait(struct bio *bio)
{
bio->bi_end_io = submit_bio_nowait_endio;
bio->bi_opf |= REQ_SYNC;
submit_bio(bio);
}
EXPORT_SYMBOL(submit_bio_nowait);
/** /**
* bio_advance - increment/complete a bio by some number of bytes * bio_advance - increment/complete a bio by some number of bytes
* @bio: bio to advance * @bio: bio to advance

View File

@ -577,6 +577,47 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
} }
EXPORT_SYMBOL(blkdev_issue_flush); EXPORT_SYMBOL(blkdev_issue_flush);
/**
* blkdev_issue_flush_nowait - queue a flush
* @bdev: blockdev to issue flush for
* @gfp_mask: memory allocation flags (for bio_alloc)
* @error_sector: error sector
*
* Description:
* Issue a flush for the block device in question. Caller can supply
* room for storing the error offset in case of a flush error, if they
* wish to. If WAIT flag is not passed then caller may check only what
* request was pushed in some internal queue for later handling.
*/
void blkdev_issue_flush_nowait(struct block_device *bdev, gfp_t gfp_mask)
{
struct request_queue *q;
struct bio *bio;
if (bdev->bd_disk == NULL)
return;
q = bdev_get_queue(bdev);
if (!q)
return;
/*
* some block devices may not have their queue correctly set up here
* (e.g. loop device without a backing file) and so issuing a flush
* here will panic. Ensure there is a request function before issuing
* the flush.
*/
if (!q->make_request_fn)
return;
bio = bio_alloc(gfp_mask, 0);
bio_set_dev(bio, bdev);
bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
submit_bio_nowait(bio);
}
EXPORT_SYMBOL(blkdev_issue_flush_nowait);
struct blk_flush_queue *blk_alloc_flush_queue(struct request_queue *q, struct blk_flush_queue *blk_alloc_flush_queue(struct request_queue *q,
int node, int cmd_size, gfp_t flags) int node, int cmd_size, gfp_t flags)
{ {

View File

@ -152,7 +152,11 @@ int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
ret = jbd2_complete_transaction(journal, commit_tid); ret = jbd2_complete_transaction(journal, commit_tid);
if (needs_barrier) { if (needs_barrier) {
issue_flush: issue_flush:
err = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL); err = 0;
if (!blk_queue_nonrot(bdev_get_queue(inode->i_sb->s_bdev)))
err = blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
else
blkdev_issue_flush_nowait(inode->i_sb->s_bdev, GFP_KERNEL);
if (!ret) if (!ret)
ret = err; ret = err;
} }

View File

@ -469,6 +469,7 @@ struct request_queue;
extern int bio_phys_segments(struct request_queue *, struct bio *); extern int bio_phys_segments(struct request_queue *, struct bio *);
extern int submit_bio_wait(struct bio *bio); extern int submit_bio_wait(struct bio *bio);
extern void submit_bio_nowait(struct bio *bio);
extern void bio_advance(struct bio *, unsigned); extern void bio_advance(struct bio *, unsigned);
extern void bio_init(struct bio *bio, struct bio_vec *table, extern void bio_init(struct bio *bio, struct bio_vec *table,

View File

@ -1399,6 +1399,7 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
} }
extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *); extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *);
extern void blkdev_issue_flush_nowait(struct block_device *, gfp_t);
extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
sector_t nr_sects, gfp_t gfp_mask, struct page *page); sector_t nr_sects, gfp_t gfp_mask, struct page *page);
@ -2111,6 +2112,10 @@ static inline int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
return 0; return 0;
} }
static inline void blkdev_issue_flush_nowait(struct block_device *bdev, gfp_t gfp_mask)
{
}
#endif /* CONFIG_BLOCK */ #endif /* CONFIG_BLOCK */
#endif #endif