diff options
author | Tao Ma <boyu.mt@taobao.com> | 2011-07-11 00:03:38 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2011-07-11 00:03:38 -0400 |
commit | 3d56b8d2c74cc3f375ce332b3ac3519e009d79ee (patch) | |
tree | 47c13dc80779a3d8d93902897a500b056375689c /fs/ext4/ext4.h | |
parent | b3d4c2b10b68d205d3eb1b5c17dcb4649a502798 (diff) |
ext4: Speed up FITRIM by recording flags in ext4_group_info
In ext4, when FITRIM is called every time, we iterate all the
groups and do trim one by one. It is a bit time wasting if the
group has been trimmed and there is no change since the last
trim.
So this patch adds a new flag in ext4_group_info->bb_state to
indicate that the group has been trimmed, and it will be cleared
if some blocks is freed(in release_blocks_on_commit). Another
trim_minlen is added in ext4_sb_info to record the last minlen
we use to trim the volume, so that if the caller provide a small
one, we will go on the trim regardless of the bb_state.
A simple test with my intel x25m ssd:
df -h shows:
/dev/sdb1 40G 21G 17G 56% /mnt/ext4
Block size: 4096
run the FITRIM with the following parameter:
range.start = 0;
range.len = UINT64_MAX;
range.minlen = 1048576;
without the patch:
[root@boyu-tm linux-2.6]# time ./ftrim /mnt/ext4/a
real 0m5.505s
user 0m0.000s
sys 0m1.224s
[root@boyu-tm linux-2.6]# time ./ftrim /mnt/ext4/a
real 0m5.359s
user 0m0.000s
sys 0m1.178s
[root@boyu-tm linux-2.6]# time ./ftrim /mnt/ext4/a
real 0m5.228s
user 0m0.000s
sys 0m1.151s
with the patch:
[root@boyu-tm linux-2.6]# time ./ftrim /mnt/ext4/a
real 0m5.625s
user 0m0.000s
sys 0m1.269s
[root@boyu-tm linux-2.6]# time ./ftrim /mnt/ext4/a
real 0m0.002s
user 0m0.000s
sys 0m0.001s
[root@boyu-tm linux-2.6]# time ./ftrim /mnt/ext4/a
real 0m0.002s
user 0m0.000s
sys 0m0.001s
A big improvement for the 2nd and 3rd run.
Even after I delete some big image files, it is still much
faster than iterating the whole disk.
[root@boyu-tm test]# time ./ftrim /mnt/ext4/a
real 0m1.217s
user 0m0.000s
sys 0m0.196s
Cc: Lukas Czerner <lczerner@redhat.com>
Reviewed-by: Andreas Dilger <adilger.kernel@dilger.ca>
Signed-off-by: Tao Ma <boyu.mt@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Diffstat (limited to 'fs/ext4/ext4.h')
-rw-r--r-- | fs/ext4/ext4.h | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index d13f3b50988..62cee2b6fe7 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h | |||
@@ -1215,6 +1215,9 @@ struct ext4_sb_info { | |||
1215 | 1215 | ||
1216 | /* Kernel thread for multiple mount protection */ | 1216 | /* Kernel thread for multiple mount protection */ |
1217 | struct task_struct *s_mmp_tsk; | 1217 | struct task_struct *s_mmp_tsk; |
1218 | |||
1219 | /* record the last minlen when FITRIM is called. */ | ||
1220 | atomic_t s_last_trim_minblks; | ||
1218 | }; | 1221 | }; |
1219 | 1222 | ||
1220 | static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) | 1223 | static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) |
@@ -2080,11 +2083,19 @@ struct ext4_group_info { | |||
2080 | * 5 free 8-block regions. */ | 2083 | * 5 free 8-block regions. */ |
2081 | }; | 2084 | }; |
2082 | 2085 | ||
2083 | #define EXT4_GROUP_INFO_NEED_INIT_BIT 0 | 2086 | #define EXT4_GROUP_INFO_NEED_INIT_BIT 0 |
2087 | #define EXT4_GROUP_INFO_WAS_TRIMMED_BIT 1 | ||
2084 | 2088 | ||
2085 | #define EXT4_MB_GRP_NEED_INIT(grp) \ | 2089 | #define EXT4_MB_GRP_NEED_INIT(grp) \ |
2086 | (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) | 2090 | (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) |
2087 | 2091 | ||
2092 | #define EXT4_MB_GRP_WAS_TRIMMED(grp) \ | ||
2093 | (test_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) | ||
2094 | #define EXT4_MB_GRP_SET_TRIMMED(grp) \ | ||
2095 | (set_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) | ||
2096 | #define EXT4_MB_GRP_CLEAR_TRIMMED(grp) \ | ||
2097 | (clear_bit(EXT4_GROUP_INFO_WAS_TRIMMED_BIT, &((grp)->bb_state))) | ||
2098 | |||
2088 | #define EXT4_MAX_CONTENTION 8 | 2099 | #define EXT4_MAX_CONTENTION 8 |
2089 | #define EXT4_CONTENTION_THRESHOLD 2 | 2100 | #define EXT4_CONTENTION_THRESHOLD 2 |
2090 | 2101 | ||