f2fs: avoid allocating failure in bio_alloc

This patch add macro MAX_BIO_BLOCKS to limit value of npages in
f2fs_bio_alloc, it can avoid allocating failure in bio_alloc caused by
npages is larger than BIO_MAX_PAGES.

Signed-off-by: Yu Chao <chao2.yu@samsung.com>
Reviewed-by: Gu Zheng <guz.fnst@cn.fujitsu.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
This commit is contained in:
Chao Yu 2013-09-22 15:50:50 +08:00 committed by Jaegeuk Kim
parent a57e564d14
commit cc7b1bb173
2 changed files with 5 additions and 1 deletions

View File

@ -657,6 +657,7 @@ static void submit_write_page(struct f2fs_sb_info *sbi, struct page *page,
block_t blk_addr, enum page_type type) block_t blk_addr, enum page_type type)
{ {
struct block_device *bdev = sbi->sb->s_bdev; struct block_device *bdev = sbi->sb->s_bdev;
int bio_blocks;
verify_block_addr(sbi, blk_addr); verify_block_addr(sbi, blk_addr);
@ -676,7 +677,8 @@ static void submit_write_page(struct f2fs_sb_info *sbi, struct page *page,
goto retry; goto retry;
} }
sbi->bio[type] = f2fs_bio_alloc(bdev, max_hw_blocks(sbi)); bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi));
sbi->bio[type] = f2fs_bio_alloc(bdev, bio_blocks);
sbi->bio[type]->bi_sector = SECTOR_FROM_BLOCK(sbi, blk_addr); sbi->bio[type]->bi_sector = SECTOR_FROM_BLOCK(sbi, blk_addr);
sbi->bio[type]->bi_private = priv; sbi->bio[type]->bi_private = priv;
/* /*

View File

@ -90,6 +90,8 @@
(blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) (blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
#define SECTOR_TO_BLOCK(sbi, sectors) \ #define SECTOR_TO_BLOCK(sbi, sectors) \
(sectors >> ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) (sectors >> ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
#define MAX_BIO_BLOCKS(max_hw_blocks) \
(min((int)max_hw_blocks, BIO_MAX_PAGES))
/* during checkpoint, bio_private is used to synchronize the last bio */ /* during checkpoint, bio_private is used to synchronize the last bio */
struct bio_private { struct bio_private {