aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChao Yu <yuchao0@huawei.com>2018-09-12 19:40:53 -0400
committerJaegeuk Kim <jaegeuk@kernel.org>2018-10-16 12:36:59 -0400
commit48018b4cfd07dd2df9a067fb3a6a3221c19eed11 (patch)
treec4b5d1d2b4486d0fec7dfee36f93f43d9ebbcb8b
parent4354994f097d068a894aa1a0860da54571df3582 (diff)
f2fs: submit cached bio to avoid endless PageWriteback
When migrating encrypted block from background GC thread, we only add them into f2fs inner bio cache, but forget to submit the cached bio, it may cause potential deadlock when we are waiting page writebacked, fix it. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/f2fs.h2
-rw-r--r--fs/f2fs/gc.c71
-rw-r--r--fs/f2fs/node.c13
3 files changed, 61 insertions, 25 deletions
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index ff540f523a3b..bf81c60e12b8 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2911,7 +2911,7 @@ struct page *f2fs_new_node_page(struct dnode_of_data *dn, unsigned int ofs);
2911void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid); 2911void f2fs_ra_node_page(struct f2fs_sb_info *sbi, nid_t nid);
2912struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid); 2912struct page *f2fs_get_node_page(struct f2fs_sb_info *sbi, pgoff_t nid);
2913struct page *f2fs_get_node_page_ra(struct page *parent, int start); 2913struct page *f2fs_get_node_page_ra(struct page *parent, int start);
2914void f2fs_move_node_page(struct page *node_page, int gc_type); 2914int f2fs_move_node_page(struct page *node_page, int gc_type);
2915int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode, 2915int f2fs_fsync_node_pages(struct f2fs_sb_info *sbi, struct inode *inode,
2916 struct writeback_control *wbc, bool atomic, 2916 struct writeback_control *wbc, bool atomic,
2917 unsigned int *seq_id); 2917 unsigned int *seq_id);
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 78288c54b68c..a07241fb8537 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -473,7 +473,7 @@ static int check_valid_map(struct f2fs_sb_info *sbi,
473 * On validity, copy that node with cold status, otherwise (invalid node) 473 * On validity, copy that node with cold status, otherwise (invalid node)
474 * ignore that. 474 * ignore that.
475 */ 475 */
476static void gc_node_segment(struct f2fs_sb_info *sbi, 476static int gc_node_segment(struct f2fs_sb_info *sbi,
477 struct f2fs_summary *sum, unsigned int segno, int gc_type) 477 struct f2fs_summary *sum, unsigned int segno, int gc_type)
478{ 478{
479 struct f2fs_summary *entry; 479 struct f2fs_summary *entry;
@@ -481,6 +481,7 @@ static void gc_node_segment(struct f2fs_sb_info *sbi,
481 int off; 481 int off;
482 int phase = 0; 482 int phase = 0;
483 bool fggc = (gc_type == FG_GC); 483 bool fggc = (gc_type == FG_GC);
484 int submitted = 0;
484 485
485 start_addr = START_BLOCK(sbi, segno); 486 start_addr = START_BLOCK(sbi, segno);
486 487
@@ -494,10 +495,11 @@ next_step:
494 nid_t nid = le32_to_cpu(entry->nid); 495 nid_t nid = le32_to_cpu(entry->nid);
495 struct page *node_page; 496 struct page *node_page;
496 struct node_info ni; 497 struct node_info ni;
498 int err;
497 499
498 /* stop BG_GC if there is not enough free sections. */ 500 /* stop BG_GC if there is not enough free sections. */
499 if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) 501 if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0))
500 return; 502 return submitted;
501 503
502 if (check_valid_map(sbi, segno, off) == 0) 504 if (check_valid_map(sbi, segno, off) == 0)
503 continue; 505 continue;
@@ -534,7 +536,9 @@ next_step:
534 continue; 536 continue;
535 } 537 }
536 538
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++;
538 stat_inc_node_blk_count(sbi, 1, gc_type); 542 stat_inc_node_blk_count(sbi, 1, gc_type);
539 } 543 }
540 544
@@ -543,6 +547,7 @@ next_step:
543 547
544 if (fggc) 548 if (fggc)
545 atomic_dec(&sbi->wb_sync_req[NODE]); 549 atomic_dec(&sbi->wb_sync_req[NODE]);
550 return submitted;
546} 551}
547 552
548/* 553/*
@@ -678,7 +683,7 @@ put_page:
678 * Move data block via META_MAPPING while keeping locked data page. 683 * Move data block via META_MAPPING while keeping locked data page.
679 * This can be used to move blocks, aka LBAs, directly on disk. 684 * This can be used to move blocks, aka LBAs, directly on disk.
680 */ 685 */
681static void move_data_block(struct inode *inode, block_t bidx, 686static int move_data_block(struct inode *inode, block_t bidx,
682 int gc_type, unsigned int segno, int off) 687 int gc_type, unsigned int segno, int off)
683{ 688{
684 struct f2fs_io_info fio = { 689 struct f2fs_io_info fio = {
@@ -697,25 +702,29 @@ static void move_data_block(struct inode *inode, block_t bidx,
697 struct node_info ni; 702 struct node_info ni;
698 struct page *page, *mpage; 703 struct page *page, *mpage;
699 block_t newaddr; 704 block_t newaddr;
700 int err; 705 int err = 0;
701 bool lfs_mode = test_opt(fio.sbi, LFS); 706 bool lfs_mode = test_opt(fio.sbi, LFS);
702 707
703 /* do not read out */ 708 /* do not read out */
704 page = f2fs_grab_cache_page(inode->i_mapping, bidx, false); 709 page = f2fs_grab_cache_page(inode->i_mapping, bidx, false);
705 if (!page) 710 if (!page)
706 return; 711 return -ENOMEM;
707 712
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;
709 goto out; 715 goto out;
716 }
710 717
711 if (f2fs_is_atomic_file(inode)) { 718 if (f2fs_is_atomic_file(inode)) {
712 F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC]++; 719 F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC]++;
713 F2FS_I_SB(inode)->skipped_atomic_files[gc_type]++; 720 F2FS_I_SB(inode)->skipped_atomic_files[gc_type]++;
721 err = -EAGAIN;
714 goto out; 722 goto out;
715 } 723 }
716 724
717 if (f2fs_is_pinned_file(inode)) { 725 if (f2fs_is_pinned_file(inode)) {
718 f2fs_pin_file_control(inode, true); 726 f2fs_pin_file_control(inode, true);
727 err = -EAGAIN;
719 goto out; 728 goto out;
720 } 729 }
721 730
@@ -726,6 +735,7 @@ static void move_data_block(struct inode *inode, block_t bidx,
726 735
727 if (unlikely(dn.data_blkaddr == NULL_ADDR)) { 736 if (unlikely(dn.data_blkaddr == NULL_ADDR)) {
728 ClearPageUptodate(page); 737 ClearPageUptodate(page);
738 err = -ENOENT;
729 goto put_out; 739 goto put_out;
730 } 740 }
731 741
@@ -808,6 +818,7 @@ write_page:
808 fio.new_blkaddr = newaddr; 818 fio.new_blkaddr = newaddr;
809 f2fs_submit_page_write(&fio); 819 f2fs_submit_page_write(&fio);
810 if (fio.retry) { 820 if (fio.retry) {
821 err = -EAGAIN;
811 if (PageWriteback(fio.encrypted_page)) 822 if (PageWriteback(fio.encrypted_page))
812 end_page_writeback(fio.encrypted_page); 823 end_page_writeback(fio.encrypted_page);
813 goto put_page_out; 824 goto put_page_out;
@@ -831,34 +842,42 @@ put_out:
831 f2fs_put_dnode(&dn); 842 f2fs_put_dnode(&dn);
832out: 843out:
833 f2fs_put_page(page, 1); 844 f2fs_put_page(page, 1);
845 return err;
834} 846}
835 847
836static void move_data_page(struct inode *inode, block_t bidx, int gc_type, 848static int move_data_page(struct inode *inode, block_t bidx, int gc_type,
837 unsigned int segno, int off) 849 unsigned int segno, int off)
838{ 850{
839 struct page *page; 851 struct page *page;
852 int err = 0;
840 853
841 page = f2fs_get_lock_data_page(inode, bidx, true); 854 page = f2fs_get_lock_data_page(inode, bidx, true);
842 if (IS_ERR(page)) 855 if (IS_ERR(page))
843 return; 856 return PTR_ERR(page);
844 857
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;
846 goto out; 860 goto out;
861 }
847 862
848 if (f2fs_is_atomic_file(inode)) { 863 if (f2fs_is_atomic_file(inode)) {
849 F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC]++; 864 F2FS_I(inode)->i_gc_failures[GC_FAILURE_ATOMIC]++;
850 F2FS_I_SB(inode)->skipped_atomic_files[gc_type]++; 865 F2FS_I_SB(inode)->skipped_atomic_files[gc_type]++;
866 err = -EAGAIN;
851 goto out; 867 goto out;
852 } 868 }
853 if (f2fs_is_pinned_file(inode)) { 869 if (f2fs_is_pinned_file(inode)) {
854 if (gc_type == FG_GC) 870 if (gc_type == FG_GC)
855 f2fs_pin_file_control(inode, true); 871 f2fs_pin_file_control(inode, true);
872 err = -EAGAIN;
856 goto out; 873 goto out;
857 } 874 }
858 875
859 if (gc_type == BG_GC) { 876 if (gc_type == BG_GC) {
860 if (PageWriteback(page)) 877 if (PageWriteback(page)) {
878 err = -EAGAIN;
861 goto out; 879 goto out;
880 }
862 set_page_dirty(page); 881 set_page_dirty(page);
863 set_cold_data(page); 882 set_cold_data(page);
864 } else { 883 } else {
@@ -876,7 +895,6 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
876 .io_type = FS_GC_DATA_IO, 895 .io_type = FS_GC_DATA_IO,
877 }; 896 };
878 bool is_dirty = PageDirty(page); 897 bool is_dirty = PageDirty(page);
879 int err;
880 898
881retry: 899retry:
882 set_page_dirty(page); 900 set_page_dirty(page);
@@ -901,6 +919,7 @@ retry:
901 } 919 }
902out: 920out:
903 f2fs_put_page(page, 1); 921 f2fs_put_page(page, 1);
922 return err;
904} 923}
905 924
906/* 925/*
@@ -910,7 +929,7 @@ out:
910 * If the parent node is not valid or the data block address is different, 929 * If the parent node is not valid or the data block address is different,
911 * the victim data block is ignored. 930 * the victim data block is ignored.
912 */ 931 */
913static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, 932static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
914 struct gc_inode_list *gc_list, unsigned int segno, int gc_type) 933 struct gc_inode_list *gc_list, unsigned int segno, int gc_type)
915{ 934{
916 struct super_block *sb = sbi->sb; 935 struct super_block *sb = sbi->sb;
@@ -918,6 +937,7 @@ static void gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum,
918 block_t start_addr; 937 block_t start_addr;
919 int off; 938 int off;
920 int phase = 0; 939 int phase = 0;
940 int submitted = 0;
921 941
922 start_addr = START_BLOCK(sbi, segno); 942 start_addr = START_BLOCK(sbi, segno);
923 943
@@ -934,7 +954,7 @@ next_step:
934 954
935 /* stop BG_GC if there is not enough free sections. */ 955 /* stop BG_GC if there is not enough free sections. */
936 if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0)) 956 if (gc_type == BG_GC && has_not_enough_free_secs(sbi, 0, 0))
937 return; 957 return submitted;
938 958
939 if (check_valid_map(sbi, segno, off) == 0) 959 if (check_valid_map(sbi, segno, off) == 0)
940 continue; 960 continue;
@@ -1006,6 +1026,7 @@ next_step:
1006 if (inode) { 1026 if (inode) {
1007 struct f2fs_inode_info *fi = F2FS_I(inode); 1027 struct f2fs_inode_info *fi = F2FS_I(inode);
1008 bool locked = false; 1028 bool locked = false;
1029 int err;
1009 1030
1010 if (S_ISREG(inode->i_mode)) { 1031 if (S_ISREG(inode->i_mode)) {
1011 if (!down_write_trylock(&fi->i_gc_rwsem[READ])) 1032 if (!down_write_trylock(&fi->i_gc_rwsem[READ]))
@@ -1025,12 +1046,16 @@ next_step:
1025 start_bidx = f2fs_start_bidx_of_node(nofs, inode) 1046 start_bidx = f2fs_start_bidx_of_node(nofs, inode)
1026 + ofs_in_node; 1047 + ofs_in_node;
1027 if (f2fs_post_read_required(inode)) 1048 if (f2fs_post_read_required(inode))
1028 move_data_block(inode, start_bidx, gc_type, 1049 err = move_data_block(inode, start_bidx,
1029 segno, off); 1050 gc_type, segno, off);
1030 else 1051 else
1031 move_data_page(inode, start_bidx, gc_type, 1052 err = move_data_page(inode, start_bidx, gc_type,
1032 segno, off); 1053 segno, off);
1033 1054
1055 if (!err && (gc_type == FG_GC ||
1056 f2fs_post_read_required(inode)))
1057 submitted++;
1058
1034 if (locked) { 1059 if (locked) {
1035 up_write(&fi->i_gc_rwsem[WRITE]); 1060 up_write(&fi->i_gc_rwsem[WRITE]);
1036 up_write(&fi->i_gc_rwsem[READ]); 1061 up_write(&fi->i_gc_rwsem[READ]);
@@ -1042,6 +1067,8 @@ next_step:
1042 1067
1043 if (++phase < 5) 1068 if (++phase < 5)
1044 goto next_step; 1069 goto next_step;
1070
1071 return submitted;
1045} 1072}
1046 1073
1047static int __get_victim(struct f2fs_sb_info *sbi, unsigned int *victim, 1074static 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,
1069 int seg_freed = 0; 1096 int seg_freed = 0;
1070 unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ? 1097 unsigned char type = IS_DATASEG(get_seg_entry(sbi, segno)->type) ?
1071 SUM_TYPE_DATA : SUM_TYPE_NODE; 1098 SUM_TYPE_DATA : SUM_TYPE_NODE;
1099 int submitted = 0;
1072 1100
1073 /* readahead multi ssa blocks those have contiguous address */ 1101 /* readahead multi ssa blocks those have contiguous address */
1074 if (sbi->segs_per_sec > 1) 1102 if (sbi->segs_per_sec > 1)
@@ -1124,10 +1152,11 @@ static int do_garbage_collect(struct f2fs_sb_info *sbi,
1124 * - lock_page(sum_page) 1152 * - lock_page(sum_page)
1125 */ 1153 */
1126 if (type == SUM_TYPE_NODE) 1154 if (type == SUM_TYPE_NODE)
1127 gc_node_segment(sbi, sum->entries, segno, gc_type); 1155 submitted += gc_node_segment(sbi, sum->entries, segno,
1128 else
1129 gc_data_segment(sbi, sum->entries, gc_list, segno,
1130 gc_type); 1156 gc_type);
1157 else
1158 submitted += gc_data_segment(sbi, sum->entries, gc_list,
1159 segno, gc_type);
1131 1160
1132 stat_inc_seg_count(sbi, type, gc_type); 1161 stat_inc_seg_count(sbi, type, gc_type);
1133 1162
@@ -1138,7 +1167,7 @@ next:
1138 f2fs_put_page(sum_page, 0); 1167 f2fs_put_page(sum_page, 0);
1139 } 1168 }
1140 1169
1141 if (gc_type == FG_GC) 1170 if (submitted)
1142 f2fs_submit_merged_write(sbi, 1171 f2fs_submit_merged_write(sbi,
1143 (type == SUM_TYPE_NODE) ? NODE : DATA); 1172 (type == SUM_TYPE_NODE) ? NODE : DATA);
1144 1173
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index b1e3ff8147f6..8f5719767178 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -1587,8 +1587,10 @@ redirty_out:
1587 return AOP_WRITEPAGE_ACTIVATE; 1587 return AOP_WRITEPAGE_ACTIVATE;
1588} 1588}
1589 1589
1590void f2fs_move_node_page(struct page *node_page, int gc_type) 1590int f2fs_move_node_page(struct page *node_page, int gc_type)
1591{ 1591{
1592 int err = 0;
1593
1592 if (gc_type == FG_GC) { 1594 if (gc_type == FG_GC) {
1593 struct writeback_control wbc = { 1595 struct writeback_control wbc = {
1594 .sync_mode = WB_SYNC_ALL, 1596 .sync_mode = WB_SYNC_ALL,
@@ -1600,12 +1602,16 @@ void f2fs_move_node_page(struct page *node_page, int gc_type)
1600 f2fs_wait_on_page_writeback(node_page, NODE, true); 1602 f2fs_wait_on_page_writeback(node_page, NODE, true);
1601 1603
1602 f2fs_bug_on(F2FS_P_SB(node_page), PageWriteback(node_page)); 1604 f2fs_bug_on(F2FS_P_SB(node_page), PageWriteback(node_page));
1603 if (!clear_page_dirty_for_io(node_page)) 1605 if (!clear_page_dirty_for_io(node_page)) {
1606 err = -EAGAIN;
1604 goto out_page; 1607 goto out_page;
1608 }
1605 1609
1606 if (__write_node_page(node_page, false, NULL, 1610 if (__write_node_page(node_page, false, NULL,
1607 &wbc, false, FS_GC_NODE_IO, NULL)) 1611 &wbc, false, FS_GC_NODE_IO, NULL)) {
1612 err = -EAGAIN;
1608 unlock_page(node_page); 1613 unlock_page(node_page);
1614 }
1609 goto release_page; 1615 goto release_page;
1610 } else { 1616 } else {
1611 /* set page dirty and write it */ 1617 /* set page dirty and write it */
@@ -1616,6 +1622,7 @@ out_page:
1616 unlock_page(node_page); 1622 unlock_page(node_page);
1617release_page: 1623release_page:
1618 f2fs_put_page(node_page, 0); 1624 f2fs_put_page(node_page, 0);
1625 return err;
1619} 1626}
1620 1627
1621static int f2fs_write_node_page(struct page *page, 1628static int f2fs_write_node_page(struct page *page,