f2fs: issue discard with finally produced len and minlen
authorJaegeuk Kim <jaegeuk@kernel.org>
Fri, 1 May 2015 05:50:06 +0000 (22:50 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 28 May 2015 22:41:39 +0000 (15:41 -0700)
This patch determines to issue discard commands by comparing given minlen and
the length of produced final candidates.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/checkpoint.c
fs/f2fs/f2fs.h
fs/f2fs/segment.c

index 55b65e52aaea27673f4825090a24f5cb238ab9e0..a61d4b06e05a07c2b6dd9365e06c20553361c574 100644 (file)
@@ -1043,7 +1043,7 @@ static void do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        if (unlikely(f2fs_cp_error(sbi)))
                return;
 
-       clear_prefree_segments(sbi);
+       clear_prefree_segments(sbi, cpc);
        clear_sbi_flag(sbi, SBI_IS_DIRTY);
 }
 
index 98fc719f5250e60b33aa5acc99571f99015b1357..0b8c4543cac85d60b7412a0a231cae8eb4bdaad3 100644 (file)
@@ -1628,7 +1628,7 @@ int create_flush_cmd_control(struct f2fs_sb_info *);
 void destroy_flush_cmd_control(struct f2fs_sb_info *);
 void invalidate_blocks(struct f2fs_sb_info *, block_t);
 void refresh_sit_entry(struct f2fs_sb_info *, block_t, block_t);
-void clear_prefree_segments(struct f2fs_sb_info *);
+void clear_prefree_segments(struct f2fs_sb_info *, struct cp_control *);
 void release_discard_addrs(struct f2fs_sb_info *);
 void discard_next_dnode(struct f2fs_sb_info *, block_t);
 int npages_for_summary_flush(struct f2fs_sb_info *, bool);
index d31fbf64f7aabcbd75f72a8b2bdfc87bc29da674..61d06b74e8285672ec0104eb82a16c41c9d89153 100644 (file)
@@ -552,10 +552,6 @@ static void add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc)
                        break;
 
                end = __find_rev_next_zero_bit(dmap, max_blocks, start + 1);
-
-               if (force && end - start < cpc->trim_minlen)
-                       continue;
-
                __add_discard_entry(sbi, cpc, se, start, end);
        }
 }
@@ -586,7 +582,7 @@ static void set_prefree_as_free_segments(struct f2fs_sb_info *sbi)
        mutex_unlock(&dirty_i->seglist_lock);
 }
 
-void clear_prefree_segments(struct f2fs_sb_info *sbi)
+void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 {
        struct list_head *head = &(SM_I(sbi)->discard_list);
        struct discard_entry *entry, *this;
@@ -619,7 +615,10 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi)
 
        /* send small discards */
        list_for_each_entry_safe(entry, this, head, list) {
+               if (cpc->reason == CP_DISCARD && entry->len < cpc->trim_minlen)
+                       goto skip;
                f2fs_issue_discard(sbi, entry->blkaddr, entry->len);
+skip:
                list_del(&entry->list);
                SM_I(sbi)->nr_discards -= entry->len;
                kmem_cache_free(discard_entry_slab, entry);
@@ -1061,8 +1060,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
        unsigned int start_segno, end_segno;
        struct cp_control cpc;
 
-       if (range->minlen > SEGMENT_SIZE(sbi) || start >= MAX_BLKADDR(sbi) ||
-                                               range->len < sbi->blocksize)
+       if (start >= MAX_BLKADDR(sbi) || range->len < sbi->blocksize)
                return -EINVAL;
 
        cpc.trimmed = 0;
@@ -1074,7 +1072,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range)
        end_segno = (end >= MAX_BLKADDR(sbi)) ? MAIN_SEGS(sbi) - 1 :
                                                GET_SEGNO(sbi, end);
        cpc.reason = CP_DISCARD;
-       cpc.trim_minlen = F2FS_BYTES_TO_BLK(range->minlen);
+       cpc.trim_minlen = max_t(__u64, 1, F2FS_BYTES_TO_BLK(range->minlen));
 
        /* do checkpoint to issue discard commands safely */
        for (; start_segno <= end_segno; start_segno = cpc.trim_end + 1) {