@@ -347,20 +347,20 @@ static void __submit_merged_bio(struct f2fs_bio_info *io)
347347 io -> bio = NULL ;
348348}
349349
350- static bool __has_merged_page (struct f2fs_bio_info * io , struct inode * inode ,
350+ static bool __has_merged_page (struct bio * bio , struct inode * inode ,
351351 struct page * page , nid_t ino )
352352{
353353 struct bio_vec * bvec ;
354354 struct page * target ;
355355 struct bvec_iter_all iter_all ;
356356
357- if (!io -> bio )
357+ if (!bio )
358358 return false;
359359
360360 if (!inode && !page && !ino )
361361 return true;
362362
363- bio_for_each_segment_all (bvec , io -> bio , iter_all ) {
363+ bio_for_each_segment_all (bvec , bio , iter_all ) {
364364
365365 if (bvec -> bv_page -> mapping )
366366 target = bvec -> bv_page ;
@@ -411,7 +411,7 @@ static void __submit_merged_write_cond(struct f2fs_sb_info *sbi,
411411 struct f2fs_bio_info * io = sbi -> write_io [btype ] + temp ;
412412
413413 down_read (& io -> io_rwsem );
414- ret = __has_merged_page (io , inode , page , ino );
414+ ret = __has_merged_page (io -> bio , inode , page , ino );
415415 up_read (& io -> io_rwsem );
416416 }
417417 if (ret )
@@ -481,6 +481,61 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
481481 return 0 ;
482482}
483483
484+ int f2fs_merge_page_bio (struct f2fs_io_info * fio )
485+ {
486+ struct bio * bio = * fio -> bio ;
487+ struct page * page = fio -> encrypted_page ?
488+ fio -> encrypted_page : fio -> page ;
489+
490+ if (!f2fs_is_valid_blkaddr (fio -> sbi , fio -> new_blkaddr ,
491+ __is_meta_io (fio ) ? META_GENERIC : DATA_GENERIC ))
492+ return - EFAULT ;
493+
494+ trace_f2fs_submit_page_bio (page , fio );
495+ f2fs_trace_ios (fio , 0 );
496+
497+ if (bio && (* fio -> last_block + 1 != fio -> new_blkaddr ||
498+ !__same_bdev (fio -> sbi , fio -> new_blkaddr , bio ))) {
499+ __submit_bio (fio -> sbi , bio , fio -> type );
500+ bio = NULL ;
501+ }
502+ alloc_new :
503+ if (!bio ) {
504+ bio = __bio_alloc (fio -> sbi , fio -> new_blkaddr , fio -> io_wbc ,
505+ BIO_MAX_PAGES , false, fio -> type , fio -> temp );
506+ bio_set_op_attrs (bio , fio -> op , fio -> op_flags );
507+ }
508+
509+ if (bio_add_page (bio , page , PAGE_SIZE , 0 ) < PAGE_SIZE ) {
510+ __submit_bio (fio -> sbi , bio , fio -> type );
511+ bio = NULL ;
512+ goto alloc_new ;
513+ }
514+
515+ if (fio -> io_wbc )
516+ wbc_account_io (fio -> io_wbc , page , PAGE_SIZE );
517+
518+ inc_page_count (fio -> sbi , WB_DATA_TYPE (page ));
519+
520+ * fio -> last_block = fio -> new_blkaddr ;
521+ * fio -> bio = bio ;
522+
523+ return 0 ;
524+ }
525+
526+ static void f2fs_submit_ipu_bio (struct f2fs_sb_info * sbi , struct bio * * bio ,
527+ struct page * page )
528+ {
529+ if (!bio )
530+ return ;
531+
532+ if (!__has_merged_page (* bio , NULL , page , 0 ))
533+ return ;
534+
535+ __submit_bio (sbi , * bio , DATA );
536+ * bio = NULL ;
537+ }
538+
484539void f2fs_submit_page_write (struct f2fs_io_info * fio )
485540{
486541 struct f2fs_sb_info * sbi = fio -> sbi ;
@@ -1947,6 +2002,8 @@ int f2fs_do_write_data_page(struct f2fs_io_info *fio)
19472002}
19482003
19492004static int __write_data_page (struct page * page , bool * submitted ,
2005+ struct bio * * bio ,
2006+ sector_t * last_block ,
19502007 struct writeback_control * wbc ,
19512008 enum iostat_type io_type )
19522009{
@@ -1972,6 +2029,8 @@ static int __write_data_page(struct page *page, bool *submitted,
19722029 .need_lock = LOCK_RETRY ,
19732030 .io_type = io_type ,
19742031 .io_wbc = wbc ,
2032+ .bio = bio ,
2033+ .last_block = last_block ,
19752034 };
19762035
19772036 trace_f2fs_writepage (page , DATA );
@@ -2070,10 +2129,13 @@ static int __write_data_page(struct page *page, bool *submitted,
20702129
20712130 unlock_page (page );
20722131 if (!S_ISDIR (inode -> i_mode ) && !IS_NOQUOTA (inode ) &&
2073- !F2FS_I (inode )-> cp_task )
2132+ !F2FS_I (inode )-> cp_task ) {
2133+ f2fs_submit_ipu_bio (sbi , bio , page );
20742134 f2fs_balance_fs (sbi , need_balance_fs );
2135+ }
20752136
20762137 if (unlikely (f2fs_cp_error (sbi ))) {
2138+ f2fs_submit_ipu_bio (sbi , bio , page );
20772139 f2fs_submit_merged_write (sbi , DATA );
20782140 submitted = NULL ;
20792141 }
@@ -2100,7 +2162,7 @@ static int __write_data_page(struct page *page, bool *submitted,
21002162static int f2fs_write_data_page (struct page * page ,
21012163 struct writeback_control * wbc )
21022164{
2103- return __write_data_page (page , NULL , wbc , FS_DATA_IO );
2165+ return __write_data_page (page , NULL , NULL , NULL , wbc , FS_DATA_IO );
21042166}
21052167
21062168/*
@@ -2116,6 +2178,8 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
21162178 int done = 0 ;
21172179 struct pagevec pvec ;
21182180 struct f2fs_sb_info * sbi = F2FS_M_SB (mapping );
2181+ struct bio * bio = NULL ;
2182+ sector_t last_block ;
21192183 int nr_pages ;
21202184 pgoff_t uninitialized_var (writeback_index );
21212185 pgoff_t index ;
@@ -2192,17 +2256,20 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
21922256 }
21932257
21942258 if (PageWriteback (page )) {
2195- if (wbc -> sync_mode != WB_SYNC_NONE )
2259+ if (wbc -> sync_mode != WB_SYNC_NONE ) {
21962260 f2fs_wait_on_page_writeback (page ,
21972261 DATA , true, true);
2198- else
2262+ f2fs_submit_ipu_bio (sbi , & bio , page );
2263+ } else {
21992264 goto continue_unlock ;
2265+ }
22002266 }
22012267
22022268 if (!clear_page_dirty_for_io (page ))
22032269 goto continue_unlock ;
22042270
2205- ret = __write_data_page (page , & submitted , wbc , io_type );
2271+ ret = __write_data_page (page , & submitted , & bio ,
2272+ & last_block , wbc , io_type );
22062273 if (unlikely (ret )) {
22072274 /*
22082275 * keep nr_to_write, since vfs uses this to
@@ -2251,6 +2318,9 @@ static int f2fs_write_cache_pages(struct address_space *mapping,
22512318 if (nwritten )
22522319 f2fs_submit_merged_write_cond (F2FS_M_SB (mapping ), mapping -> host ,
22532320 NULL , 0 , DATA );
2321+ /* submit cached bio of IPU write */
2322+ if (bio )
2323+ __submit_bio (sbi , bio , DATA );
22542324
22552325 return ret ;
22562326}
0 commit comments