f2fs: do not use discard_map for hard disks
authorJaegeuk Kim <jaegeuk@kernel.org>
Tue, 2 Aug 2016 17:56:40 +0000 (10:56 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 24 Aug 2016 17:16:14 +0000 (10:16 -0700)
We don't need to keep discard_map, if disk does not support discard command.

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

index badd407bb622a5db00630bb1a0fdb994cbb015cb..af69d6bcfc3fc726c21b2f7d3fb8f72874e5db2b 100644 (file)
@@ -154,7 +154,9 @@ static void update_mem_info(struct f2fs_sb_info *sbi)
        si->base_mem += sizeof(struct sit_info);
        si->base_mem += MAIN_SEGS(sbi) * sizeof(struct seg_entry);
        si->base_mem += f2fs_bitmap_size(MAIN_SEGS(sbi));
-       si->base_mem += 3 * SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi);
+       si->base_mem += 2 * SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi);
+       if (f2fs_discard_en(sbi))
+               si->base_mem += SIT_VBLOCK_MAP_SIZE * MAIN_SEGS(sbi);
        si->base_mem += SIT_VBLOCK_MAP_SIZE;
        if (sbi->segs_per_sec > 1)
                si->base_mem += MAIN_SECS(sbi) * sizeof(struct sec_entry);
index 14f5fe2b841e2e7d4e699072cc2aeb6e1c14c645..f478cb6ec37897268eb8460e758eccb101b763c9 100644 (file)
@@ -1072,6 +1072,13 @@ static inline void clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
        cp->ckpt_flags = cpu_to_le32(ckpt_flags);
 }
 
+static inline bool f2fs_discard_en(struct f2fs_sb_info *sbi)
+{
+       struct request_queue *q = bdev_get_queue(sbi->sb->s_bdev);
+
+       return blk_queue_discard(q);
+}
+
 static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
 {
        down_read(&sbi->cp_rwsem);
index a46296f57b026e650f2a82950ae7f63a02fd2fb0..59f578b68000c43ac6a78ab3860fe2eb8a568fae 100644 (file)
@@ -660,7 +660,7 @@ static void add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc)
        bool force = (cpc->reason == CP_DISCARD);
        int i;
 
-       if (se->valid_blocks == max_blocks)
+       if (se->valid_blocks == max_blocks || !f2fs_discard_en(sbi))
                return;
 
        if (!force) {
@@ -818,12 +818,14 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
        if (del > 0) {
                if (f2fs_test_and_set_bit(offset, se->cur_valid_map))
                        f2fs_bug_on(sbi, 1);
-               if (!f2fs_test_and_set_bit(offset, se->discard_map))
+               if (f2fs_discard_en(sbi) &&
+                       !f2fs_test_and_set_bit(offset, se->discard_map))
                        sbi->discard_blks--;
        } else {
                if (!f2fs_test_and_clear_bit(offset, se->cur_valid_map))
                        f2fs_bug_on(sbi, 1);
-               if (f2fs_test_and_clear_bit(offset, se->discard_map))
+               if (f2fs_discard_en(sbi) &&
+                       f2fs_test_and_clear_bit(offset, se->discard_map))
                        sbi->discard_blks++;
        }
        if (!f2fs_test_bit(offset, se->ckpt_valid_map))
@@ -2127,12 +2129,16 @@ static int build_sit_info(struct f2fs_sb_info *sbi)
                        = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
                sit_i->sentries[start].ckpt_valid_map
                        = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
-               sit_i->sentries[start].discard_map
-                       = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
                if (!sit_i->sentries[start].cur_valid_map ||
-                               !sit_i->sentries[start].ckpt_valid_map ||
-                               !sit_i->sentries[start].discard_map)
+                               !sit_i->sentries[start].ckpt_valid_map)
                        return -ENOMEM;
+
+               if (f2fs_discard_en(sbi)) {
+                       sit_i->sentries[start].discard_map
+                               = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
+                       if (!sit_i->sentries[start].discard_map)
+                               return -ENOMEM;
+               }
        }
 
        sit_i->tmp_map = kzalloc(SIT_VBLOCK_MAP_SIZE, GFP_KERNEL);
@@ -2276,8 +2282,12 @@ got_it:
                        seg_info_from_raw_sit(se, &sit);
 
                        /* build discard map only one time */
-                       memcpy(se->discard_map, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE);
-                       sbi->discard_blks += sbi->blocks_per_seg - se->valid_blocks;
+                       if (f2fs_discard_en(sbi)) {
+                               memcpy(se->discard_map, se->cur_valid_map,
+                                                       SIT_VBLOCK_MAP_SIZE);
+                               sbi->discard_blks += sbi->blocks_per_seg -
+                                                       se->valid_blocks;
+                       }
 
                        if (sbi->segs_per_sec > 1) {
                                struct sec_entry *e = get_sec_entry(sbi, start);