Re: [f2fs-dev] [PATCH] f2fs: Add option to limit required GC for checkpoint=disable

2019-04-27 Thread Chao Yu
Hi Daniel,

On 2019/4/24 9:25, Daniel Rosenberg wrote:
> This extends the checkpoint option to allow checkpoint=disable:%u
> This allows you to specify what percent of the drive you are willing
> to lose access to while mounting with checkpoint=disable. If the amount
> lost would be higher, the mount will return -EAGAIN.
> Currently, we need to run garbage collection until the amount of holes
> is smaller than the OVP space. With the new option, f2fs can mark
> space as unusable up front instead of requiring that
> the space be freed up with garbage collection.
> 
> Signed-off-by: Daniel Rosenberg 
> ---
>  Documentation/ABI/testing/sysfs-fs-f2fs |  8 +
>  Documentation/filesystems/f2fs.txt  |  8 +++--
>  fs/f2fs/f2fs.h  |  6 +++-
>  fs/f2fs/segment.c   | 17 --
>  fs/f2fs/super.c | 44 +
>  fs/f2fs/sysfs.c | 16 +
>  6 files changed, 72 insertions(+), 27 deletions(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs 
> b/Documentation/ABI/testing/sysfs-fs-f2fs
> index 91822ce258317..d65b9ebc56190 100644
> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
> @@ -243,3 +243,11 @@ Description:
>- Del: echo '[h/c]!extension' > 
> /sys/fs/f2fs//extension_list
>- [h] means add/del hot file extension
>- [c] means add/del cold file extension
> +
> +What:/sys/fs/f2fs//unusable
> +Date April 2019
> +Contact: "Daniel Rosenberg" 
> +Description:
> + Displays the number of blocks that are unusable during 
> checkpoint=disable

Maybe it will be more clear to indicate what you implement in unusable_show():

If checkpoint=enable, it displays...
If checkpoint=disable, it displays...

> + or the number of blocks that would be unusable if 
> checkpoint=disable
> + were to be set.
> diff --git a/Documentation/filesystems/f2fs.txt 
> b/Documentation/filesystems/f2fs.txt
> index f7b5e4ff0de3e..b3b5534407da7 100644
> --- a/Documentation/filesystems/f2fs.txt
> +++ b/Documentation/filesystems/f2fs.txt
> @@ -214,11 +214,15 @@ fsync_mode=%s  Control the policy of fsync. 
> Currently supports "posix",
> non-atomic files likewise "nobarrier" mount option.
>  test_dummy_encryption  Enable dummy encryption, which provides a fake fscrypt
> context. The fake fscrypt context is used by xfstests.
> -checkpoint=%s  Set to "disable" to turn off checkpointing. Set to 
> "enable"
> +checkpoint=%s[:%u] Set to "disable" to turn off checkpointing. Set to 
> "enable"
> to reenable checkpointing. Is enabled by default. 
> While
> disabled, any unmounting or unexpected shutdowns will 
> cause
> the filesystem contents to appear as they did when the
> -   filesystem was mounted with that option.
> +   filesystem was mounted with that option. While 
> mounting
> +   with disabled, you may optionally add a percentage to
> +   limit the amount of space that checkpoint=disable 
> denies
> +   access to. If this is set, the mount may return 
> EAGAIN if
> +   additional garbage collection is required to meet the 
> limit
>  
>  
> 
>  DEBUGFS ENTRIES
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 30acde08822ef..d0477251cec56 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -136,6 +136,9 @@ struct f2fs_mount_info {
>   int alloc_mode; /* segment allocation policy */
>   int fsync_mode; /* fsync policy */
>   bool test_dummy_encryption; /* test dummy encryption */
> + block_t unusable_percent_cap;   /* Percent of space allowed to be
> +  * unusable when disabling checkpoint
> +  */
>  };
>  
>  #define F2FS_FEATURE_ENCRYPT 0x0001
> @@ -3049,7 +3052,8 @@ bool f2fs_issue_discard_timeout(struct f2fs_sb_info 
> *sbi);
>  void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,
>   struct cp_control *cpc);
>  void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi);
> -int f2fs_disable_cp_again(struct f2fs_sb_info *sbi);
> +block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi);
> +int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable);
>  void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi);
>  int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
>  void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
> diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
> index a3380d1de6000..704224f4a2866 100644
> --- 

[f2fs-dev] [PATCH] f2fs: Add option to limit required GC for checkpoint=disable

2019-04-23 Thread Daniel Rosenberg via Linux-f2fs-devel
This extends the checkpoint option to allow checkpoint=disable:%u
This allows you to specify what percent of the drive you are willing
to lose access to while mounting with checkpoint=disable. If the amount
lost would be higher, the mount will return -EAGAIN.
Currently, we need to run garbage collection until the amount of holes
is smaller than the OVP space. With the new option, f2fs can mark
space as unusable up front instead of requiring that
the space be freed up with garbage collection.

Signed-off-by: Daniel Rosenberg 
---
 Documentation/ABI/testing/sysfs-fs-f2fs |  8 +
 Documentation/filesystems/f2fs.txt  |  8 +++--
 fs/f2fs/f2fs.h  |  6 +++-
 fs/f2fs/segment.c   | 17 --
 fs/f2fs/super.c | 44 +
 fs/f2fs/sysfs.c | 16 +
 6 files changed, 72 insertions(+), 27 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs 
b/Documentation/ABI/testing/sysfs-fs-f2fs
index 91822ce258317..d65b9ebc56190 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -243,3 +243,11 @@ Description:
 - Del: echo '[h/c]!extension' > 
/sys/fs/f2fs//extension_list
 - [h] means add/del hot file extension
 - [c] means add/del cold file extension
+
+What:  /sys/fs/f2fs//unusable
+Date   April 2019
+Contact:   "Daniel Rosenberg" 
+Description:
+   Displays the number of blocks that are unusable during 
checkpoint=disable
+   or the number of blocks that would be unusable if 
checkpoint=disable
+   were to be set.
diff --git a/Documentation/filesystems/f2fs.txt 
b/Documentation/filesystems/f2fs.txt
index f7b5e4ff0de3e..b3b5534407da7 100644
--- a/Documentation/filesystems/f2fs.txt
+++ b/Documentation/filesystems/f2fs.txt
@@ -214,11 +214,15 @@ fsync_mode=%s  Control the policy of fsync. 
Currently supports "posix",
non-atomic files likewise "nobarrier" mount option.
 test_dummy_encryption  Enable dummy encryption, which provides a fake fscrypt
context. The fake fscrypt context is used by xfstests.
-checkpoint=%s  Set to "disable" to turn off checkpointing. Set to 
"enable"
+checkpoint=%s[:%u] Set to "disable" to turn off checkpointing. Set to 
"enable"
to reenable checkpointing. Is enabled by default. While
disabled, any unmounting or unexpected shutdowns will 
cause
the filesystem contents to appear as they did when the
-   filesystem was mounted with that option.
+   filesystem was mounted with that option. While mounting
+   with disabled, you may optionally add a percentage to
+   limit the amount of space that checkpoint=disable denies
+   access to. If this is set, the mount may return EAGAIN 
if
+   additional garbage collection is required to meet the 
limit
 
 

 DEBUGFS ENTRIES
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 30acde08822ef..d0477251cec56 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -136,6 +136,9 @@ struct f2fs_mount_info {
int alloc_mode; /* segment allocation policy */
int fsync_mode; /* fsync policy */
bool test_dummy_encryption; /* test dummy encryption */
+   block_t unusable_percent_cap;   /* Percent of space allowed to be
+* unusable when disabling checkpoint
+*/
 };
 
 #define F2FS_FEATURE_ENCRYPT   0x0001
@@ -3049,7 +3052,8 @@ bool f2fs_issue_discard_timeout(struct f2fs_sb_info *sbi);
 void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi,
struct cp_control *cpc);
 void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi);
-int f2fs_disable_cp_again(struct f2fs_sb_info *sbi);
+block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi);
+int f2fs_disable_cp_again(struct f2fs_sb_info *sbi, block_t unusable);
 void f2fs_release_discard_addrs(struct f2fs_sb_info *sbi);
 int f2fs_npages_for_summary_flush(struct f2fs_sb_info *sbi, bool for_ra);
 void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi);
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index a3380d1de6000..704224f4a2866 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -869,11 +869,12 @@ void f2fs_dirty_to_prefree(struct f2fs_sb_info *sbi)
mutex_unlock(_i->seglist_lock);
 }
 
-int f2fs_disable_cp_again(struct f2fs_sb_info *sbi)
+block_t f2fs_get_unusable_blocks(struct f2fs_sb_info *sbi)
 {
-   struct dirty_seglist_info *dirty_i = DIRTY_I(sbi);
block_t ovp = overprovision_segments(sbi)