Skip to content

Commit cc116a2

Browse files
Jaegeuk KimHashcode
authored andcommitted
f2fs: modify the number of issued pages to merge IOs
When testing f2fs on an SSD, I found some 128 page IOs followed by 1 page IO were issued by f2fs_write_node_pages. This means that there were some mishandling flows which degrades performance. Previous f2fs_write_node_pages determines the number of pages to be written, nr_to_write, as follows. 1. The bio_get_nr_vecs returns 129 pages. 2. The bio_alloc makes a room for 128 pages. 3. The initial 128 pages go into one bio. 4. The existing bio is submitted, and a new bio is prepared for the last 1 page. 5. Finally, sync_node_pages submits the last 1 page bio. The problem is from the use of bio_get_nr_vecs, so this patch replace it with max_hw_blocks using queue_max_sectors. Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
1 parent d65fb0f commit cc116a2

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

fs/f2fs/node.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,6 @@ static int f2fs_write_node_pages(struct address_space *mapping,
11711171
struct writeback_control *wbc)
11721172
{
11731173
struct f2fs_sb_info *sbi = F2FS_SB(mapping->host->i_sb);
1174-
struct block_device *bdev = sbi->sb->s_bdev;
11751174
long nr_to_write = wbc->nr_to_write;
11761175

11771176
/* First check balancing cached NAT entries */
@@ -1185,10 +1184,9 @@ static int f2fs_write_node_pages(struct address_space *mapping,
11851184
return 0;
11861185

11871186
/* if mounting is failed, skip writing node pages */
1188-
wbc->nr_to_write = bio_get_nr_vecs(bdev);
1187+
wbc->nr_to_write = max_hw_blocks(sbi);
11891188
sync_node_pages(sbi, 0, wbc);
1190-
wbc->nr_to_write = nr_to_write -
1191-
(bio_get_nr_vecs(bdev) - wbc->nr_to_write);
1189+
wbc->nr_to_write = nr_to_write - (max_hw_blocks(sbi) - wbc->nr_to_write);
11921190
return 0;
11931191
}
11941192

fs/f2fs/segment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ static void submit_write_page(struct f2fs_sb_info *sbi, struct page *page,
734734
do_submit_bio(sbi, type, false);
735735
alloc_new:
736736
if (sbi->bio[type] == NULL) {
737-
sbi->bio[type] = f2fs_bio_alloc(bdev, bio_get_nr_vecs(bdev));
737+
sbi->bio[type] = f2fs_bio_alloc(bdev, max_hw_blocks(sbi));
738738
sbi->bio[type]->bi_sector = SECTOR_FROM_BLOCK(sbi, blk_addr);
739739
/*
740740
* The end_io will be assigned at the sumbission phase.

fs/f2fs/segment.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* it under the terms of the GNU General Public License version 2 as
99
* published by the Free Software Foundation.
1010
*/
11+
#include <linux/blkdev.h>
12+
1113
/* constant macro */
1214
#define NULL_SEGNO ((unsigned int)(~0))
1315
#define NULL_SECNO ((unsigned int)(~0))
@@ -86,6 +88,8 @@
8688

8789
#define SECTOR_FROM_BLOCK(sbi, blk_addr) \
8890
(blk_addr << ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
91+
#define SECTOR_TO_BLOCK(sbi, sectors) \
92+
(sectors >> ((sbi)->log_blocksize - F2FS_LOG_SECTOR_SIZE))
8993

9094
/* during checkpoint, bio_private is used to synchronize the last bio */
9195
struct bio_private {
@@ -624,3 +628,10 @@ static inline bool sec_usage_check(struct f2fs_sb_info *sbi, unsigned int secno)
624628
return true;
625629
return false;
626630
}
631+
632+
static inline unsigned int max_hw_blocks(struct f2fs_sb_info *sbi)
633+
{
634+
struct block_device *bdev = sbi->sb->s_bdev;
635+
struct request_queue *q = bdev_get_queue(bdev);
636+
return SECTOR_TO_BLOCK(sbi, queue_max_sectors(q));
637+
}

0 commit comments

Comments
 (0)