aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin K. Petersen2012-09-18 11:19:28 -0500
committerJens Axboe2012-09-20 07:31:49 -0500
commit579e8f3c7b2ecf7db91398d942d76457a3ddba21 (patch)
treef41d7d469cb427550656f1d1d2c3b5215a9ea0aa /block/blk-lib.c
parent4363ac7c13a9a4b763c6e8d9fdbfc2468f3b8ca4 (diff)
downloadkernel-common-579e8f3c7b2ecf7db91398d942d76457a3ddba21.tar.gz
kernel-common-579e8f3c7b2ecf7db91398d942d76457a3ddba21.tar.xz
kernel-common-579e8f3c7b2ecf7db91398d942d76457a3ddba21.zip
block: Make blkdev_issue_zeroout use WRITE SAME
If the device supports WRITE SAME, use that to optimize zeroing of blocks. If the device does not support WRITE SAME or if the operation fails, fall back to writing zeroes the old-fashioned way. Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Acked-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/blk-lib.c')
-rw-r--r--block/blk-lib.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/block/blk-lib.c b/block/blk-lib.c
index a062543c58a..9373b58dfab 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -214,7 +214,7 @@ EXPORT_SYMBOL(blkdev_issue_write_same);
214 * Generate and issue number of bios with zerofiled pages. 214 * Generate and issue number of bios with zerofiled pages.
215 */ 215 */
216 216
217int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, 217int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
218 sector_t nr_sects, gfp_t gfp_mask) 218 sector_t nr_sects, gfp_t gfp_mask)
219{ 219{
220 int ret; 220 int ret;
@@ -264,4 +264,32 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
264 264
265 return ret; 265 return ret;
266} 266}
267
268/**
269 * blkdev_issue_zeroout - zero-fill a block range
270 * @bdev: blockdev to write
271 * @sector: start sector
272 * @nr_sects: number of sectors to write
273 * @gfp_mask: memory allocation flags (for bio_alloc)
274 *
275 * Description:
276 * Generate and issue number of bios with zerofiled pages.
277 */
278
279int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
280 sector_t nr_sects, gfp_t gfp_mask)
281{
282 if (bdev_write_same(bdev)) {
283 unsigned char bdn[BDEVNAME_SIZE];
284
285 if (!blkdev_issue_write_same(bdev, sector, nr_sects, gfp_mask,
286 ZERO_PAGE(0)))
287 return 0;
288
289 bdevname(bdev, bdn);
290 pr_err("%s: WRITE SAME failed. Manually zeroing.\n", bdn);
291 }
292
293 return __blkdev_issue_zeroout(bdev, sector, nr_sects, gfp_mask);
294}
267EXPORT_SYMBOL(blkdev_issue_zeroout); 295EXPORT_SYMBOL(blkdev_issue_zeroout);