f2fs: avoid very large discard command
authorJaegeuk Kim <jaegeuk@kernel.org>
Thu, 23 Feb 2017 03:10:35 +0000 (19:10 -0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Mon, 27 Feb 2017 17:59:20 +0000 (09:59 -0800)
This patch adds MAX_DISCARD_BLOCKS() to avoid issuing too much large single
discard command.

Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/f2fs.h
fs/f2fs/segment.c

index 146cc71ff91c56d4fb5a50ab0bdf0b3559acc464..2ce9fba27918cc87026ecffabd72c6f2e45ca2fd 100644 (file)
@@ -133,7 +133,8 @@ enum {
                (SM_I(sbi)->trim_sections * (sbi)->segs_per_sec)
 #define BATCHED_TRIM_BLOCKS(sbi)       \
                (BATCHED_TRIM_SEGMENTS(sbi) << (sbi)->log_blocks_per_seg)
-
+#define MAX_DISCARD_BLOCKS(sbi)                                                \
+               ((1 << (sbi)->log_blocks_per_seg) * (sbi)->segs_per_sec)
 #define DISCARD_ISSUE_RATE     8
 #define DEF_CP_INTERVAL                        60      /* 60 secs */
 #define DEF_IDLE_INTERVAL              5       /* 5 secs */
index d780ecccc4ac170c1fbf936f06178b3307016ecf..028db55375a45fe05300b04a3f0e4c5fbbe080bf 100644 (file)
@@ -886,7 +886,8 @@ static void __add_discard_entry(struct f2fs_sb_info *sbi,
        if (!list_empty(head)) {
                last = list_last_entry(head, struct discard_entry, list);
                if (START_BLOCK(sbi, cpc->trim_start) + start ==
-                                               last->blkaddr + last->len) {
+                               last->blkaddr + last->len &&
+                               last->len < MAX_DISCARD_BLOCKS(sbi)) {
                        last->len += end - start;
                        goto done;
                }