linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] f2fs: allow cpc->reason to indicate more than one reason
@ 2017-04-27 12:40 Chao Yu
  2017-04-27 12:40 ` [PATCH 2/2] f2fs: introduce CP_TRIMMED_FLAG to avoid unneeded discard Chao Yu
  0 siblings, 1 reply; 4+ messages in thread
From: Chao Yu @ 2017-04-27 12:40 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, chao, Chao Yu

Change to use different bits of cpc->reason to indicate different status,
so cpc->reason can indicate more than one reason.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fs/f2fs/checkpoint.c | 14 +++++++-------
 fs/f2fs/f2fs.h       | 16 +++++++---------
 fs/f2fs/segment.c    |  8 ++++----
 3 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 800be94f8cb3..27578903eeb6 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1054,17 +1054,17 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 
 	spin_lock(&sbi->cp_lock);
 
-	if (cpc->reason == CP_UMOUNT &&
+	if ((cpc->reason & CP_UMOUNT) &&
 			le32_to_cpu(ckpt->cp_pack_total_block_count) >
 			sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks)
 		disable_nat_bits(sbi, false);
 
-	if (cpc->reason == CP_UMOUNT)
+	if (cpc->reason & CP_UMOUNT)
 		__set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
 	else
 		__clear_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
 
-	if (cpc->reason == CP_FASTBOOT)
+	if (cpc->reason & CP_FASTBOOT)
 		__set_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
 	else
 		__clear_ckpt_flags(ckpt, CP_FASTBOOT_FLAG);
@@ -1272,8 +1272,8 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	mutex_lock(&sbi->cp_mutex);
 
 	if (!is_sbi_flag_set(sbi, SBI_IS_DIRTY) &&
-		(cpc->reason == CP_FASTBOOT || cpc->reason == CP_SYNC ||
-		(cpc->reason == CP_DISCARD && !sbi->discard_blks)))
+		((cpc->reason & CP_FASTBOOT) || (cpc->reason & CP_SYNC) ||
+		((cpc->reason & CP_DISCARD) && !sbi->discard_blks)))
 		goto out;
 	if (unlikely(f2fs_cp_error(sbi))) {
 		err = -EIO;
@@ -1295,7 +1295,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	f2fs_flush_merged_bios(sbi);
 
 	/* this is the case of multiple fstrims without any changes */
-	if (cpc->reason == CP_DISCARD) {
+	if (cpc->reason & CP_DISCARD) {
 		if (!exist_trim_candidates(sbi, cpc)) {
 			unblock_operations(sbi);
 			goto out;
@@ -1333,7 +1333,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	unblock_operations(sbi);
 	stat_inc_cp_count(sbi->stat_info);
 
-	if (cpc->reason == CP_RECOVERY)
+	if (cpc->reason & CP_RECOVERY)
 		f2fs_msg(sbi->sb, KERN_NOTICE,
 			"checkpoint: version = %llx", ckpt_ver);
 
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index bf48213642ab..453eaa943a21 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -125,13 +125,11 @@ enum {
 	SIT_BITMAP
 };
 
-enum {
-	CP_UMOUNT,
-	CP_FASTBOOT,
-	CP_SYNC,
-	CP_RECOVERY,
-	CP_DISCARD,
-};
+#define	CP_UMOUNT	0x00000001
+#define	CP_FASTBOOT	0x00000002
+#define	CP_SYNC		0x00000004
+#define	CP_RECOVERY	0x00000008
+#define	CP_DISCARD	0x00000010
 
 #define DEF_BATCHED_TRIM_SECTIONS	2048
 #define BATCHED_TRIM_SEGMENTS(sbi)	\
@@ -1264,7 +1262,7 @@ static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
 {
 	bool set = is_set_ckpt_flags(sbi, CP_NAT_BITS_FLAG);
 
-	return (cpc) ? (cpc->reason == CP_UMOUNT) && set : set;
+	return (cpc) ? (cpc->reason & CP_UMOUNT) && set : set;
 }
 
 static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
@@ -1300,7 +1298,7 @@ static inline int __get_cp_reason(struct f2fs_sb_info *sbi)
 
 static inline bool __remain_node_summaries(int reason)
 {
-	return (reason == CP_UMOUNT || reason == CP_FASTBOOT);
+	return (reason & (CP_UMOUNT | CP_FASTBOOT));
 }
 
 static inline bool __exist_node_summaries(struct f2fs_sb_info *sbi)
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index b0babb73a076..a2cd10cdff60 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -1167,7 +1167,7 @@ static bool add_discard_addrs(struct f2fs_sb_info *sbi, struct cp_control *cpc,
 	unsigned long *discard_map = (unsigned long *)se->discard_map;
 	unsigned long *dmap = SIT_I(sbi)->tmp_map;
 	unsigned int start = 0, end = -1;
-	bool force = (cpc->reason == CP_DISCARD);
+	bool force = (cpc->reason & CP_DISCARD);
 	struct discard_entry *de = NULL;
 	struct list_head *head = &SM_I(sbi)->dcc_info->entry_list;
 	int i;
@@ -1250,7 +1250,7 @@ void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	unsigned long *prefree_map = dirty_i->dirty_segmap[PRE];
 	unsigned int start = 0, end = -1;
 	unsigned int secno, start_segno;
-	bool force = (cpc->reason == CP_DISCARD);
+	bool force = (cpc->reason & CP_DISCARD);
 
 	mutex_lock(&dirty_i->seglist_lock);
 
@@ -2754,7 +2754,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 			se = get_seg_entry(sbi, segno);
 
 			/* add discard candidates */
-			if (cpc->reason != CP_DISCARD) {
+			if (!(cpc->reason & CP_DISCARD)) {
 				cpc->trim_start = segno;
 				add_discard_addrs(sbi, cpc, false);
 			}
@@ -2790,7 +2790,7 @@ void flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 	f2fs_bug_on(sbi, !list_empty(head));
 	f2fs_bug_on(sbi, sit_i->dirty_sentries);
 out:
-	if (cpc->reason == CP_DISCARD) {
+	if (cpc->reason & CP_DISCARD) {
 		__u64 trim_start = cpc->trim_start;
 
 		for (; cpc->trim_start <= cpc->trim_end; cpc->trim_start++)
-- 
2.12.2.510.ge1104a5ee539

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] f2fs: introduce CP_TRIMMED_FLAG to avoid unneeded discard
  2017-04-27 12:40 [PATCH 1/2] f2fs: allow cpc->reason to indicate more than one reason Chao Yu
@ 2017-04-27 12:40 ` Chao Yu
  2017-04-27 18:16   ` Jaegeuk Kim
  0 siblings, 1 reply; 4+ messages in thread
From: Chao Yu @ 2017-04-27 12:40 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel, linux-kernel, chao, Chao Yu

Introduce CP_TRIMMED_FLAG to indicate all invalid block were trimmed
before umount, so once we do mount with image which contain the flag,
we don't record invalid blocks as undiscard one, when fstrim is being
triggered, we can avoid issuing redundant discard commands.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fs/f2fs/checkpoint.c    |  3 +++
 fs/f2fs/f2fs.h          |  1 +
 fs/f2fs/segment.c       | 28 ++++++++++++++++++++--------
 fs/f2fs/super.c         |  7 +++++++
 include/linux/f2fs_fs.h |  1 +
 5 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index 27578903eeb6..ea9c317b5916 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -1059,6 +1059,9 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
 			sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks)
 		disable_nat_bits(sbi, false);
 
+	if (cpc->reason & CP_TRIMMED)
+		__set_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
+
 	if (cpc->reason & CP_UMOUNT)
 		__set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
 	else
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 453eaa943a21..c6fce1631289 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -130,6 +130,7 @@ enum {
 #define	CP_SYNC		0x00000004
 #define	CP_RECOVERY	0x00000008
 #define	CP_DISCARD	0x00000010
+#define CP_TRIMMED	0x00000020
 
 #define DEF_BATCHED_TRIM_SECTIONS	2048
 #define BATCHED_TRIM_SEGMENTS(sbi)	\
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index a2cd10cdff60..e4dd1e4a42c9 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -2989,10 +2989,17 @@ static void build_sit_entries(struct f2fs_sb_info *sbi)
 
 			/* build discard map only one time */
 			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 (is_set_ckpt_flags(sbi, CP_TRIMMED_FLAG)) {
+					memset(se->discard_map, 0xff,
+						SIT_VBLOCK_MAP_SIZE);
+				} else {
+					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)
@@ -3016,10 +3023,15 @@ static void build_sit_entries(struct f2fs_sb_info *sbi)
 		seg_info_from_raw_sit(se, &sit);
 
 		if (f2fs_discard_en(sbi)) {
-			memcpy(se->discard_map, se->cur_valid_map,
-						SIT_VBLOCK_MAP_SIZE);
-			sbi->discard_blks += old_valid_blocks -
-						se->valid_blocks;
+			if (is_set_ckpt_flags(sbi, CP_TRIMMED_FLAG)) {
+				memset(se->discard_map, 0xff,
+							SIT_VBLOCK_MAP_SIZE);
+			} else {
+				memcpy(se->discard_map, se->cur_valid_map,
+							SIT_VBLOCK_MAP_SIZE);
+				sbi->discard_blks += old_valid_blocks -
+							se->valid_blocks;
+			}
 		}
 
 		if (sbi->segs_per_sec > 1)
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 4cd3bee6775f..9a14b2590337 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -797,6 +797,13 @@ static void f2fs_put_super(struct super_block *sb)
 	/* be sure to wait for any on-going discard commands */
 	f2fs_wait_discard_bios(sbi);
 
+	if (!sbi->discard_blks) {
+		struct cp_control cpc = {
+			.reason = CP_UMOUNT | CP_TRIMMED,
+		};
+		write_checkpoint(sbi, &cpc);
+	}
+
 	/* write_checkpoint can update stat informaion */
 	f2fs_destroy_stats(sbi);
 
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index 093549e10ee2..b6feed6547ce 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -114,6 +114,7 @@ struct f2fs_super_block {
 /*
  * For checkpoint
  */
+#define CP_TRIMMED_FLAG		0x00000100
 #define CP_NAT_BITS_FLAG	0x00000080
 #define CP_CRC_RECOVERY_FLAG	0x00000040
 #define CP_FASTBOOT_FLAG	0x00000020
-- 
2.12.2.510.ge1104a5ee539

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] f2fs: introduce CP_TRIMMED_FLAG to avoid unneeded discard
  2017-04-27 12:40 ` [PATCH 2/2] f2fs: introduce CP_TRIMMED_FLAG to avoid unneeded discard Chao Yu
@ 2017-04-27 18:16   ` Jaegeuk Kim
  2017-04-28  1:40     ` Chao Yu
  0 siblings, 1 reply; 4+ messages in thread
From: Jaegeuk Kim @ 2017-04-27 18:16 UTC (permalink / raw)
  To: Chao Yu; +Cc: linux-f2fs-devel, linux-kernel, chao

Hi Chao,

Could you add this state in print_cp_state() of f2fs-tools as well?

Thanks,

On 04/27, Chao Yu wrote:
> Introduce CP_TRIMMED_FLAG to indicate all invalid block were trimmed
> before umount, so once we do mount with image which contain the flag,
> we don't record invalid blocks as undiscard one, when fstrim is being
> triggered, we can avoid issuing redundant discard commands.
> 
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
>  fs/f2fs/checkpoint.c    |  3 +++
>  fs/f2fs/f2fs.h          |  1 +
>  fs/f2fs/segment.c       | 28 ++++++++++++++++++++--------
>  fs/f2fs/super.c         |  7 +++++++
>  include/linux/f2fs_fs.h |  1 +
>  5 files changed, 32 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
> index 27578903eeb6..ea9c317b5916 100644
> --- a/fs/f2fs/checkpoint.c
> +++ b/fs/f2fs/checkpoint.c
> @@ -1059,6 +1059,9 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
>  			sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks)
>  		disable_nat_bits(sbi, false);
>  
> +	if (cpc->reason & CP_TRIMMED)
> +		__set_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
> +
>  	if (cpc->reason & CP_UMOUNT)
>  		__set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
>  	else
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 453eaa943a21..c6fce1631289 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -130,6 +130,7 @@ enum {
>  #define	CP_SYNC		0x00000004
>  #define	CP_RECOVERY	0x00000008
>  #define	CP_DISCARD	0x00000010
> +#define CP_TRIMMED	0x00000020
>  
>  #define DEF_BATCHED_TRIM_SECTIONS	2048
>  #define BATCHED_TRIM_SEGMENTS(sbi)	\
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index a2cd10cdff60..e4dd1e4a42c9 100644
> --- a/fs/f2fs/segment.c
> +++ b/fs/f2fs/segment.c
> @@ -2989,10 +2989,17 @@ static void build_sit_entries(struct f2fs_sb_info *sbi)
>  
>  			/* build discard map only one time */
>  			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 (is_set_ckpt_flags(sbi, CP_TRIMMED_FLAG)) {
> +					memset(se->discard_map, 0xff,
> +						SIT_VBLOCK_MAP_SIZE);
> +				} else {
> +					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)
> @@ -3016,10 +3023,15 @@ static void build_sit_entries(struct f2fs_sb_info *sbi)
>  		seg_info_from_raw_sit(se, &sit);
>  
>  		if (f2fs_discard_en(sbi)) {
> -			memcpy(se->discard_map, se->cur_valid_map,
> -						SIT_VBLOCK_MAP_SIZE);
> -			sbi->discard_blks += old_valid_blocks -
> -						se->valid_blocks;
> +			if (is_set_ckpt_flags(sbi, CP_TRIMMED_FLAG)) {
> +				memset(se->discard_map, 0xff,
> +							SIT_VBLOCK_MAP_SIZE);
> +			} else {
> +				memcpy(se->discard_map, se->cur_valid_map,
> +							SIT_VBLOCK_MAP_SIZE);
> +				sbi->discard_blks += old_valid_blocks -
> +							se->valid_blocks;
> +			}
>  		}
>  
>  		if (sbi->segs_per_sec > 1)
> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
> index 4cd3bee6775f..9a14b2590337 100644
> --- a/fs/f2fs/super.c
> +++ b/fs/f2fs/super.c
> @@ -797,6 +797,13 @@ static void f2fs_put_super(struct super_block *sb)
>  	/* be sure to wait for any on-going discard commands */
>  	f2fs_wait_discard_bios(sbi);
>  
> +	if (!sbi->discard_blks) {
> +		struct cp_control cpc = {
> +			.reason = CP_UMOUNT | CP_TRIMMED,
> +		};
> +		write_checkpoint(sbi, &cpc);
> +	}
> +
>  	/* write_checkpoint can update stat informaion */
>  	f2fs_destroy_stats(sbi);
>  
> diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
> index 093549e10ee2..b6feed6547ce 100644
> --- a/include/linux/f2fs_fs.h
> +++ b/include/linux/f2fs_fs.h
> @@ -114,6 +114,7 @@ struct f2fs_super_block {
>  /*
>   * For checkpoint
>   */
> +#define CP_TRIMMED_FLAG		0x00000100
>  #define CP_NAT_BITS_FLAG	0x00000080
>  #define CP_CRC_RECOVERY_FLAG	0x00000040
>  #define CP_FASTBOOT_FLAG	0x00000020
> -- 
> 2.12.2.510.ge1104a5ee539

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] f2fs: introduce CP_TRIMMED_FLAG to avoid unneeded discard
  2017-04-27 18:16   ` Jaegeuk Kim
@ 2017-04-28  1:40     ` Chao Yu
  0 siblings, 0 replies; 4+ messages in thread
From: Chao Yu @ 2017-04-28  1:40 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: linux-f2fs-devel, linux-kernel, chao

Hi Jaegeuk,

On 2017/4/28 2:16, Jaegeuk Kim wrote:
> Hi Chao,
> 
> Could you add this state in print_cp_state() of f2fs-tools as well?

Oh, right, and we can set the flag after trimming in mkfs, also we need to
adjust this state into trace info.

Let me fix this. :)

Thanks,

> 
> Thanks,
> 
> On 04/27, Chao Yu wrote:
>> Introduce CP_TRIMMED_FLAG to indicate all invalid block were trimmed
>> before umount, so once we do mount with image which contain the flag,
>> we don't record invalid blocks as undiscard one, when fstrim is being
>> triggered, we can avoid issuing redundant discard commands.
>>
>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>> ---
>>  fs/f2fs/checkpoint.c    |  3 +++
>>  fs/f2fs/f2fs.h          |  1 +
>>  fs/f2fs/segment.c       | 28 ++++++++++++++++++++--------
>>  fs/f2fs/super.c         |  7 +++++++
>>  include/linux/f2fs_fs.h |  1 +
>>  5 files changed, 32 insertions(+), 8 deletions(-)
>>
>> diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
>> index 27578903eeb6..ea9c317b5916 100644
>> --- a/fs/f2fs/checkpoint.c
>> +++ b/fs/f2fs/checkpoint.c
>> @@ -1059,6 +1059,9 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
>>  			sbi->blocks_per_seg - NM_I(sbi)->nat_bits_blocks)
>>  		disable_nat_bits(sbi, false);
>>  
>> +	if (cpc->reason & CP_TRIMMED)
>> +		__set_ckpt_flags(ckpt, CP_TRIMMED_FLAG);
>> +
>>  	if (cpc->reason & CP_UMOUNT)
>>  		__set_ckpt_flags(ckpt, CP_UMOUNT_FLAG);
>>  	else
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index 453eaa943a21..c6fce1631289 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -130,6 +130,7 @@ enum {
>>  #define	CP_SYNC		0x00000004
>>  #define	CP_RECOVERY	0x00000008
>>  #define	CP_DISCARD	0x00000010
>> +#define CP_TRIMMED	0x00000020
>>  
>>  #define DEF_BATCHED_TRIM_SECTIONS	2048
>>  #define BATCHED_TRIM_SEGMENTS(sbi)	\
>> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
>> index a2cd10cdff60..e4dd1e4a42c9 100644
>> --- a/fs/f2fs/segment.c
>> +++ b/fs/f2fs/segment.c
>> @@ -2989,10 +2989,17 @@ static void build_sit_entries(struct f2fs_sb_info *sbi)
>>  
>>  			/* build discard map only one time */
>>  			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 (is_set_ckpt_flags(sbi, CP_TRIMMED_FLAG)) {
>> +					memset(se->discard_map, 0xff,
>> +						SIT_VBLOCK_MAP_SIZE);
>> +				} else {
>> +					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)
>> @@ -3016,10 +3023,15 @@ static void build_sit_entries(struct f2fs_sb_info *sbi)
>>  		seg_info_from_raw_sit(se, &sit);
>>  
>>  		if (f2fs_discard_en(sbi)) {
>> -			memcpy(se->discard_map, se->cur_valid_map,
>> -						SIT_VBLOCK_MAP_SIZE);
>> -			sbi->discard_blks += old_valid_blocks -
>> -						se->valid_blocks;
>> +			if (is_set_ckpt_flags(sbi, CP_TRIMMED_FLAG)) {
>> +				memset(se->discard_map, 0xff,
>> +							SIT_VBLOCK_MAP_SIZE);
>> +			} else {
>> +				memcpy(se->discard_map, se->cur_valid_map,
>> +							SIT_VBLOCK_MAP_SIZE);
>> +				sbi->discard_blks += old_valid_blocks -
>> +							se->valid_blocks;
>> +			}
>>  		}
>>  
>>  		if (sbi->segs_per_sec > 1)
>> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
>> index 4cd3bee6775f..9a14b2590337 100644
>> --- a/fs/f2fs/super.c
>> +++ b/fs/f2fs/super.c
>> @@ -797,6 +797,13 @@ static void f2fs_put_super(struct super_block *sb)
>>  	/* be sure to wait for any on-going discard commands */
>>  	f2fs_wait_discard_bios(sbi);
>>  
>> +	if (!sbi->discard_blks) {
>> +		struct cp_control cpc = {
>> +			.reason = CP_UMOUNT | CP_TRIMMED,
>> +		};
>> +		write_checkpoint(sbi, &cpc);
>> +	}
>> +
>>  	/* write_checkpoint can update stat informaion */
>>  	f2fs_destroy_stats(sbi);
>>  
>> diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
>> index 093549e10ee2..b6feed6547ce 100644
>> --- a/include/linux/f2fs_fs.h
>> +++ b/include/linux/f2fs_fs.h
>> @@ -114,6 +114,7 @@ struct f2fs_super_block {
>>  /*
>>   * For checkpoint
>>   */
>> +#define CP_TRIMMED_FLAG		0x00000100
>>  #define CP_NAT_BITS_FLAG	0x00000080
>>  #define CP_CRC_RECOVERY_FLAG	0x00000040
>>  #define CP_FASTBOOT_FLAG	0x00000020
>> -- 
>> 2.12.2.510.ge1104a5ee539
> 
> .
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-04-28  1:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-27 12:40 [PATCH 1/2] f2fs: allow cpc->reason to indicate more than one reason Chao Yu
2017-04-27 12:40 ` [PATCH 2/2] f2fs: introduce CP_TRIMMED_FLAG to avoid unneeded discard Chao Yu
2017-04-27 18:16   ` Jaegeuk Kim
2017-04-28  1:40     ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).