Commit cc7b1bb173676621b092b61d22d8d12b05efb5e8
Committed by
Jaegeuk Kim
1 parent
a57e564d14
Exists in
master
and in
16 other branches
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>
Showing 2 changed files with 5 additions and 1 deletions Side-by-side Diff
fs/f2fs/segment.c
... | ... | @@ -657,6 +657,7 @@ |
657 | 657 | block_t blk_addr, enum page_type type) |
658 | 658 | { |
659 | 659 | struct block_device *bdev = sbi->sb->s_bdev; |
660 | + int bio_blocks; | |
660 | 661 | |
661 | 662 | verify_block_addr(sbi, blk_addr); |
662 | 663 | |
... | ... | @@ -676,7 +677,8 @@ |
676 | 677 | goto retry; |
677 | 678 | } |
678 | 679 | |
679 | - sbi->bio[type] = f2fs_bio_alloc(bdev, max_hw_blocks(sbi)); | |
680 | + bio_blocks = MAX_BIO_BLOCKS(max_hw_blocks(sbi)); | |
681 | + sbi->bio[type] = f2fs_bio_alloc(bdev, bio_blocks); | |
680 | 682 | sbi->bio[type]->bi_sector = SECTOR_FROM_BLOCK(sbi, blk_addr); |
681 | 683 | sbi->bio[type]->bi_private = priv; |
682 | 684 | /* |
fs/f2fs/segment.h
... | ... | @@ -90,6 +90,8 @@ |
90 | 90 | (blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) |
91 | 91 | #define SECTOR_TO_BLOCK(sbi, sectors) \ |
92 | 92 | (sectors >> ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) |
93 | +#define MAX_BIO_BLOCKS(max_hw_blocks) \ | |
94 | + (min((int)max_hw_blocks, BIO_MAX_PAGES)) | |
93 | 95 | |
94 | 96 | /* during checkpoint, bio_private is used to synchronize the last bio */ |
95 | 97 | struct bio_private { |