@@ -473,14 +473,15 @@ static int check_valid_map(struct f2fs_sb_info *sbi,
473473 * On validity, copy that node with cold status, otherwise (invalid node)
474474 * ignore that.
475475 */
476- static void gc_node_segment (struct f2fs_sb_info * sbi ,
476+ static int gc_node_segment (struct f2fs_sb_info * sbi ,
477477 struct f2fs_summary * sum , unsigned int segno , int gc_type )
478478{
479479 struct f2fs_summary * entry ;
480480 block_t start_addr ;
481481 int off ;
482482 int phase = 0 ;
483483 bool fggc = (gc_type == FG_GC );
484+ int submitted = 0 ;
484485
485486 start_addr = START_BLOCK (sbi , segno );
486487
@@ -494,10 +495,11 @@ static void gc_node_segment(struct f2fs_sb_info *sbi,
494495 nid_t nid = le32_to_cpu (entry -> nid );
495496 struct page * node_page ;
496497 struct node_info ni ;
498+ int err ;
497499
498500 /* stop BG_GC if there is not enough free sections. */
499501 if (gc_type == BG_GC && has_not_enough_free_secs (sbi , 0 , 0 ))
500- return ;
502+ return submitted ;
501503
502504 if (check_valid_map (sbi , segno , off ) == 0 )
503505 continue ;
@@ -534,7 +536,9 @@ static void gc_node_segment(struct f2fs_sb_info *sbi,
534536 continue ;
535537 }
536538
537- f2fs_move_node_page (node_page , gc_type );
539+ err = f2fs_move_node_page (node_page , gc_type );
540+ if (!err && gc_type == FG_GC )
541+ submitted ++ ;
538542 stat_inc_node_blk_count (sbi , 1 , gc_type );
539543 }
540544
@@ -543,6 +547,7 @@ static void gc_node_segment(struct f2fs_sb_info *sbi,
543547
544548 if (fggc )
545549 atomic_dec (& sbi -> wb_sync_req [NODE ]);
550+ return submitted ;
546551}
547552
548553/*
@@ -678,7 +683,7 @@ static int ra_data_block(struct inode *inode, pgoff_t index)
678683 * Move data block via META_MAPPING while keeping locked data page.
679684 * This can be used to move blocks, aka LBAs, directly on disk.
680685 */
681- static void move_data_block (struct inode * inode , block_t bidx ,
686+ static int move_data_block (struct inode * inode , block_t bidx ,
682687 int gc_type , unsigned int segno , int off )
683688{
684689 struct f2fs_io_info fio = {
@@ -697,25 +702,29 @@ static void move_data_block(struct inode *inode, block_t bidx,
697702 struct node_info ni ;
698703 struct page * page , * mpage ;
699704 block_t newaddr ;
700- int err ;
705+ int err = 0 ;
701706 bool lfs_mode = test_opt (fio .sbi , LFS );
702707
703708 /* do not read out */
704709 page = f2fs_grab_cache_page (inode -> i_mapping , bidx , false);
705710 if (!page )
706- return ;
711+ return - ENOMEM ;
707712
708- if (!check_valid_map (F2FS_I_SB (inode ), segno , off ))
713+ if (!check_valid_map (F2FS_I_SB (inode ), segno , off )) {
714+ err = - ENOENT ;
709715 goto out ;
716+ }
710717
711718 if (f2fs_is_atomic_file (inode )) {
712719 F2FS_I (inode )-> i_gc_failures [GC_FAILURE_ATOMIC ]++ ;
713720 F2FS_I_SB (inode )-> skipped_atomic_files [gc_type ]++ ;
721+ err = - EAGAIN ;
714722 goto out ;
715723 }
716724
717725 if (f2fs_is_pinned_file (inode )) {
718726 f2fs_pin_file_control (inode , true);
727+ err = - EAGAIN ;
719728 goto out ;
720729 }
721730
@@ -726,6 +735,7 @@ static void move_data_block(struct inode *inode, block_t bidx,
726735
727736 if (unlikely (dn .data_blkaddr == NULL_ADDR )) {
728737 ClearPageUptodate (page );
738+ err = - ENOENT ;
729739 goto put_out ;
730740 }
731741
@@ -808,6 +818,7 @@ static void move_data_block(struct inode *inode, block_t bidx,
808818 fio .new_blkaddr = newaddr ;
809819 f2fs_submit_page_write (& fio );
810820 if (fio .retry ) {
821+ err = - EAGAIN ;
811822 if (PageWriteback (fio .encrypted_page ))
812823 end_page_writeback (fio .encrypted_page );
813824 goto put_page_out ;
@@ -831,34 +842,42 @@ static void move_data_block(struct inode *inode, block_t bidx,
831842 f2fs_put_dnode (& dn );
832843out :
833844 f2fs_put_page (page , 1 );
845+ return err ;
834846}
835847
836- static void move_data_page (struct inode * inode , block_t bidx , int gc_type ,
848+ static int move_data_page (struct inode * inode , block_t bidx , int gc_type ,
837849 unsigned int segno , int off )
838850{
839851 struct page * page ;
852+ int err = 0 ;
840853
841854 page = f2fs_get_lock_data_page (inode , bidx , true);
842855 if (IS_ERR (page ))
843- return ;
856+ return PTR_ERR ( page ) ;
844857
845- if (!check_valid_map (F2FS_I_SB (inode ), segno , off ))
858+ if (!check_valid_map (F2FS_I_SB (inode ), segno , off )) {
859+ err = - ENOENT ;
846860 goto out ;
861+ }
847862
848863 if (f2fs_is_atomic_file (inode )) {
849864 F2FS_I (inode )-> i_gc_failures [GC_FAILURE_ATOMIC ]++ ;
850865 F2FS_I_SB (inode )-> skipped_atomic_files [gc_type ]++ ;
866+ err = - EAGAIN ;
851867 goto out ;
852868 }
853869 if (f2fs_is_pinned_file (inode )) {
854870 if (gc_type == FG_GC )
855871 f2fs_pin_file_control (inode , true);
872+ err = - EAGAIN ;
856873 goto out ;
857874 }
858875
859876 if (gc_type == BG_GC ) {
860- if (PageWriteback (page ))
877+ if (PageWriteback (page )) {
878+ err = - EAGAIN ;
861879 goto out ;
880+ }
862881 set_page_dirty (page );
863882 set_cold_data (page );
864883 } else {
@@ -876,7 +895,6 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
876895 .io_type = FS_GC_DATA_IO ,
877896 };
878897 bool is_dirty = PageDirty (page );
879- int err ;
880898
881899retry :
882900 set_page_dirty (page );
@@ -901,6 +919,7 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
901919 }
902920out :
903921 f2fs_put_page (page , 1 );
922+ return err ;
904923}
905924
906925/*
@@ -910,14 +929,15 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
910929 * If the parent node is not valid or the data block address is different,
911930 * the victim data block is ignored.
912931 */
913- static void gc_data_segment (struct f2fs_sb_info * sbi , struct f2fs_summary * sum ,
932+ static int gc_data_segment (struct f2fs_sb_info * sbi , struct f2fs_summary * sum ,
914933 struct gc_inode_list * gc_list , unsigned int segno , int gc_type )
915934{
916935 struct super_block * sb = sbi -> sb ;
917936 struct f2fs_summary * entry ;
918937 block_t start_addr ;
919938 int off ;
920939 int phase = 0 ;
940+ int submitted = 0 ;
921941
922942 start_addr = START_BLOCK (sbi , segno );
923943
@@ -934,7 +954,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
934954
935955 /* stop BG_GC if there is not enough free sections. */
936956 if (gc_type == BG_GC && has_not_enough_free_secs (sbi , 0 , 0 ))
937- return ;
957+ return submitted ;
938958
939959 if (check_valid_map (sbi , segno , off ) == 0 )
940960 continue ;
@@ -1006,6 +1026,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
10061026 if (inode ) {
10071027 struct f2fs_inode_info * fi = F2FS_I (inode );
10081028 bool locked = false;
1029+ int err ;
10091030
10101031 if (S_ISREG (inode -> i_mode )) {
10111032 if (!down_write_trylock (& fi -> i_gc_rwsem [READ ]))
@@ -1025,12 +1046,16 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
10251046 start_bidx = f2fs_start_bidx_of_node (nofs , inode )
10261047 + ofs_in_node ;
10271048 if (f2fs_post_read_required (inode ))
1028- move_data_block (inode , start_bidx , gc_type ,
1029- segno , off );
1049+ err = move_data_block (inode , start_bidx ,
1050+ gc_type , segno , off );
10301051 else
1031- move_data_page (inode , start_bidx , gc_type ,
1052+ err = move_data_page (inode , start_bidx , gc_type ,
10321053 segno , off );
10331054
1055+ if (!err && (gc_type == FG_GC ||
1056+ f2fs_post_read_required (inode )))
1057+ submitted ++ ;
1058+
10341059 if (locked ) {
10351060 up_write (& fi -> i_gc_rwsem [WRITE ]);
10361061 up_write (& fi -> i_gc_rwsem [READ ]);
@@ -1042,6 +1067,8 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
10421067
10431068 if (++ phase < 5 )
10441069 goto next_step ;
1070+
1071+ return submitted ;
10451072}
10461073
10471074static int __get_victim (struct f2fs_sb_info * sbi , unsigned int * victim ,
@@ -1069,6 +1096,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
10691096 int seg_freed = 0 ;
10701097 unsigned char type = IS_DATASEG (get_seg_entry (sbi , segno )-> type ) ?
10711098 SUM_TYPE_DATA : SUM_TYPE_NODE ;
1099+ int submitted = 0 ;
10721100
10731101 /* readahead multi ssa blocks those have contiguous address */
10741102 if (sbi -> segs_per_sec > 1 )
@@ -1124,10 +1152,11 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
11241152 * - lock_page(sum_page)
11251153 */
11261154 if (type == SUM_TYPE_NODE )
1127- gc_node_segment (sbi , sum -> entries , segno , gc_type );
1128- else
1129- gc_data_segment (sbi , sum -> entries , gc_list , segno ,
1155+ submitted += gc_node_segment (sbi , sum -> entries , segno ,
11301156 gc_type );
1157+ else
1158+ submitted += gc_data_segment (sbi , sum -> entries , gc_list ,
1159+ segno , gc_type );
11311160
11321161 stat_inc_seg_count (sbi , type , gc_type );
11331162
@@ -1138,7 +1167,7 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
11381167 f2fs_put_page (sum_page , 0 );
11391168 }
11401169
1141- if (gc_type == FG_GC )
1170+ if (submitted )
11421171 f2fs_submit_merged_write (sbi ,
11431172 (type == SUM_TYPE_NODE ) ? NODE : DATA );
11441173
0 commit comments