Commit 3cd8a23948b29301f8f67b8d70c5c18fabbc05e1
1 parent
457d08ee4f
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
f2fs: cleanup the f2fs_bio_alloc routine
Do cleanup more for better code readability. - Change the parameter set of f2fs_bio_alloc() This function should allocate a bio only since it is not something like f2fs_bio_init(). Instead, the caller should initialize the allocated bio. - Introduce SECTOR_FROM_BLOCK This macro translates a block address to its sector address. Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com> Reviewed-by: Namjae Jeon <namjae.jeon@samsung.com>
Showing 4 changed files with 25 additions and 18 deletions Side-by-side Diff
fs/f2fs/data.c
... | ... | @@ -343,11 +343,12 @@ |
343 | 343 | down_read(&sbi->bio_sem); |
344 | 344 | |
345 | 345 | /* Allocate a new bio */ |
346 | - bio = f2fs_bio_alloc(bdev, blk_addr << (sbi->log_blocksize - 9), | |
347 | - 1, GFP_NOFS | __GFP_HIGH); | |
346 | + bio = f2fs_bio_alloc(bdev, 1); | |
348 | 347 | |
349 | 348 | /* Initialize the bio */ |
349 | + bio->bi_sector = SECTOR_FROM_BLOCK(sbi, blk_addr); | |
350 | 350 | bio->bi_end_io = read_end_io; |
351 | + | |
351 | 352 | if (bio_add_page(bio, page, PAGE_CACHE_SIZE, 0) < PAGE_CACHE_SIZE) { |
352 | 353 | kfree(bio->bi_private); |
353 | 354 | bio_put(bio); |
fs/f2fs/f2fs.h
... | ... | @@ -924,7 +924,7 @@ |
924 | 924 | int npages_for_summary_flush(struct f2fs_sb_info *); |
925 | 925 | void allocate_new_segments(struct f2fs_sb_info *); |
926 | 926 | struct page *get_sum_page(struct f2fs_sb_info *, unsigned int); |
927 | -struct bio *f2fs_bio_alloc(struct block_device *, sector_t, int, gfp_t); | |
927 | +struct bio *f2fs_bio_alloc(struct block_device *, int); | |
928 | 928 | void f2fs_submit_bio(struct f2fs_sb_info *, enum page_type, bool sync); |
929 | 929 | int write_meta_page(struct f2fs_sb_info *, struct page *, |
930 | 930 | struct writeback_control *); |
fs/f2fs/segment.c
... | ... | @@ -643,23 +643,21 @@ |
643 | 643 | bio_put(bio); |
644 | 644 | } |
645 | 645 | |
646 | -struct bio *f2fs_bio_alloc(struct block_device *bdev, sector_t first_sector, | |
647 | - int nr_vecs, gfp_t gfp_flags) | |
646 | +struct bio *f2fs_bio_alloc(struct block_device *bdev, int npages) | |
648 | 647 | { |
649 | 648 | struct bio *bio; |
650 | - | |
651 | - /* allocate new bio */ | |
652 | - bio = bio_alloc(gfp_flags, nr_vecs); | |
653 | - | |
654 | - bio->bi_bdev = bdev; | |
655 | - bio->bi_sector = first_sector; | |
649 | + struct bio_private *priv; | |
656 | 650 | retry: |
657 | - bio->bi_private = kmalloc(sizeof(struct bio_private), | |
658 | - GFP_NOFS | __GFP_HIGH); | |
659 | - if (!bio->bi_private) { | |
651 | + priv = kmalloc(sizeof(struct bio_private), GFP_NOFS); | |
652 | + if (!priv) { | |
660 | 653 | cond_resched(); |
661 | 654 | goto retry; |
662 | 655 | } |
656 | + | |
657 | + /* No failure on bio allocation */ | |
658 | + bio = bio_alloc(GFP_NOIO, npages); | |
659 | + bio->bi_bdev = bdev; | |
660 | + bio->bi_private = priv; | |
663 | 661 | return bio; |
664 | 662 | } |
665 | 663 | |
... | ... | @@ -711,10 +709,15 @@ |
711 | 709 | if (sbi->bio[type] && sbi->last_block_in_bio[type] != blk_addr - 1) |
712 | 710 | do_submit_bio(sbi, type, false); |
713 | 711 | alloc_new: |
714 | - if (sbi->bio[type] == NULL) | |
715 | - sbi->bio[type] = f2fs_bio_alloc(bdev, | |
716 | - blk_addr << (sbi->log_blocksize - 9), | |
717 | - bio_get_nr_vecs(bdev), GFP_NOFS | __GFP_HIGH); | |
712 | + if (sbi->bio[type] == NULL) { | |
713 | + sbi->bio[type] = f2fs_bio_alloc(bdev, bio_get_nr_vecs(bdev)); | |
714 | + sbi->bio[type]->bi_sector = SECTOR_FROM_BLOCK(sbi, blk_addr); | |
715 | + /* | |
716 | + * The end_io will be assigned at the sumbission phase. | |
717 | + * Until then, let bio_add_page() merge consecutive IOs as much | |
718 | + * as possible. | |
719 | + */ | |
720 | + } | |
718 | 721 | |
719 | 722 | if (bio_add_page(sbi->bio[type], page, PAGE_CACHE_SIZE, 0) < |
720 | 723 | PAGE_CACHE_SIZE) { |
fs/f2fs/segment.h
... | ... | @@ -82,6 +82,9 @@ |
82 | 82 | (BITS_TO_LONGS(nr) * sizeof(unsigned long)) |
83 | 83 | #define TOTAL_SEGS(sbi) (SM_I(sbi)->main_segments) |
84 | 84 | |
85 | +#define SECTOR_FROM_BLOCK(sbi, blk_addr) \ | |
86 | + (blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE)) | |
87 | + | |
85 | 88 | /* during checkpoint, bio_private is used to synchronize the last bio */ |
86 | 89 | struct bio_private { |
87 | 90 | struct f2fs_sb_info *sbi; |