linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] f2fs: add wsync_mode for sysfs entry
@ 2019-06-21 18:01 Jaegeuk Kim
  2019-06-24  1:46 ` [f2fs-dev] " Chao Yu
  0 siblings, 1 reply; 3+ messages in thread
From: Jaegeuk Kim @ 2019-06-21 18:01 UTC (permalink / raw)
  To: linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim

From: Jaegeuk Kim <jaegeuk@google.com>

This add one sysfs entry to control REQ_SYNC/REQ_BACKGROUND for write bios
for data page writes.

Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
---
 Documentation/ABI/testing/sysfs-fs-f2fs |  7 +++++++
 Documentation/filesystems/f2fs.txt      |  4 ++++
 fs/f2fs/data.c                          |  3 +--
 fs/f2fs/f2fs.h                          | 12 ++++++++++++
 fs/f2fs/sysfs.c                         |  2 ++
 5 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index dca326e0ee3e..d3eca3eb3214 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -251,3 +251,10 @@ Description:
 		If checkpoint=disable, it displays the number of blocks that are unusable.
                 If checkpoint=enable it displays the enumber of blocks that would be unusable
                 if checkpoint=disable were to be set.
+
+What:		/sys/fs/f2fs/<disk>/wsync_mode
+Date		June 2019
+Contact:	"Jaegeuk Kim" <jaegeuk.kim@kernel.org>
+Description:
+		0 gives no change. 1 assigns all the data writes with REQ_SYNC.
+                2 does REQ_BACKGROUND instead.
diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt
index bebd1be3ba49..81c529801a88 100644
--- a/Documentation/filesystems/f2fs.txt
+++ b/Documentation/filesystems/f2fs.txt
@@ -413,6 +413,10 @@ Files in /sys/fs/f2fs/<devname>
                               that would be unusable if checkpoint=disable were
                               to be set.
 
+ wsync_mode                   0 is by default. 1 gives REQ_SYNC for all the data
+                              writes. 2 gives REQ_BACKGROUND for all. This can
+                              used for the performance tuning purpose.
+
 ================================================================================
 USAGE
 ================================================================================
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index f4e1672bd96e..18c73a1fdef3 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -9,7 +9,6 @@
 #include <linux/f2fs_fs.h>
 #include <linux/buffer_head.h>
 #include <linux/mpage.h>
-#include <linux/writeback.h>
 #include <linux/backing-dev.h>
 #include <linux/pagevec.h>
 #include <linux/blkdev.h>
@@ -2021,7 +2020,7 @@ static int __write_data_page(struct page *page, bool *submitted,
 		.ino = inode->i_ino,
 		.type = DATA,
 		.op = REQ_OP_WRITE,
-		.op_flags = wbc_to_write_flags(wbc),
+		.op_flags = f2fs_wbc_to_write_flags(sbi, wbc),
 		.old_blkaddr = NULL_ADDR,
 		.page = page,
 		.encrypted_page = NULL,
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 2be2b16573c3..1cc46a6dc340 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -12,6 +12,7 @@
 #include <linux/types.h>
 #include <linux/page-flags.h>
 #include <linux/buffer_head.h>
+#include <linux/writeback.h>
 #include <linux/slab.h>
 #include <linux/crc32.h>
 #include <linux/magic.h>
@@ -1264,6 +1265,7 @@ struct f2fs_sb_info {
 
 	/* writeback control */
 	atomic_t wb_sync_req[META];	/* count # of WB_SYNC threads */
+	int wsync_mode;			/* write mode */
 
 	/* valid inode count */
 	struct percpu_counter total_valid_inode_count;
@@ -3631,6 +3633,16 @@ static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
 	}
 }
 
+static inline int f2fs_wbc_to_write_flags(struct f2fs_sb_info *sbi,
+				struct writeback_control *wbc)
+{
+	if (sbi->wsync_mode == 1)
+		return REQ_SYNC;
+	if (sbi->wsync_mode == 2)
+		return REQ_BACKGROUND;
+	return wbc_to_write_flags(wbc);
+}
+
 static inline bool f2fs_may_encrypt(struct inode *inode)
 {
 #ifdef CONFIG_FS_ENCRYPTION
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
index 3aeacd0aacfd..e3c164d921a1 100644
--- a/fs/f2fs/sysfs.c
+++ b/fs/f2fs/sysfs.c
@@ -455,6 +455,7 @@ F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
 F2FS_GENERAL_RO_ATTR(features);
 F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
 F2FS_GENERAL_RO_ATTR(unusable);
+F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, wsync_mode, wsync_mode);
 
 #ifdef CONFIG_FS_ENCRYPTION
 F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
@@ -515,6 +516,7 @@ static struct attribute *f2fs_attrs[] = {
 	ATTR_LIST(features),
 	ATTR_LIST(reserved_blocks),
 	ATTR_LIST(current_reserved_blocks),
+	ATTR_LIST(wsync_mode),
 	NULL,
 };
 ATTRIBUTE_GROUPS(f2fs);
-- 
2.19.0.605.g01d371f741-goog


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

* Re: [f2fs-dev] [PATCH] f2fs: add wsync_mode for sysfs entry
  2019-06-21 18:01 [PATCH] f2fs: add wsync_mode for sysfs entry Jaegeuk Kim
@ 2019-06-24  1:46 ` Chao Yu
  2019-06-24 13:22   ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2019-06-24  1:46 UTC (permalink / raw)
  To: Jaegeuk Kim, linux-kernel, linux-f2fs-devel; +Cc: Jaegeuk Kim

On 2019/6/22 2:01, Jaegeuk Kim wrote:
> From: Jaegeuk Kim <jaegeuk@google.com>
> 
> This add one sysfs entry to control REQ_SYNC/REQ_BACKGROUND for write bios
> for data page writes.
> 
> Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
> ---
>  Documentation/ABI/testing/sysfs-fs-f2fs |  7 +++++++
>  Documentation/filesystems/f2fs.txt      |  4 ++++
>  fs/f2fs/data.c                          |  3 +--
>  fs/f2fs/f2fs.h                          | 12 ++++++++++++
>  fs/f2fs/sysfs.c                         |  2 ++
>  5 files changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
> index dca326e0ee3e..d3eca3eb3214 100644
> --- a/Documentation/ABI/testing/sysfs-fs-f2fs
> +++ b/Documentation/ABI/testing/sysfs-fs-f2fs
> @@ -251,3 +251,10 @@ Description:
>  		If checkpoint=disable, it displays the number of blocks that are unusable.
>                  If checkpoint=enable it displays the enumber of blocks that would be unusable
>                  if checkpoint=disable were to be set.
> +
> +What:		/sys/fs/f2fs/<disk>/wsync_mode
> +Date		June 2019
> +Contact:	"Jaegeuk Kim" <jaegeuk.kim@kernel.org>

jaegeuk@kernel.org ?

> +Description:
> +		0 gives no change. 1 assigns all the data writes with REQ_SYNC.
> +                2 does REQ_BACKGROUND instead.
> diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt
> index bebd1be3ba49..81c529801a88 100644
> --- a/Documentation/filesystems/f2fs.txt
> +++ b/Documentation/filesystems/f2fs.txt
> @@ -413,6 +413,10 @@ Files in /sys/fs/f2fs/<devname>
>                                that would be unusable if checkpoint=disable were
>                                to be set.
>  
> + wsync_mode                   0 is by default. 1 gives REQ_SYNC for all the data
> +                              writes. 2 gives REQ_BACKGROUND for all. This can
> +                              used for the performance tuning purpose.

It looks so hacking. :P

Could you please explain more about this idea, I'm confused in which scenario it
can improve performance.

Thanks,

> +
>  ================================================================================
>  USAGE
>  ================================================================================
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index f4e1672bd96e..18c73a1fdef3 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -9,7 +9,6 @@
>  #include <linux/f2fs_fs.h>
>  #include <linux/buffer_head.h>
>  #include <linux/mpage.h>
> -#include <linux/writeback.h>
>  #include <linux/backing-dev.h>
>  #include <linux/pagevec.h>
>  #include <linux/blkdev.h>
> @@ -2021,7 +2020,7 @@ static int __write_data_page(struct page *page, bool *submitted,
>  		.ino = inode->i_ino,
>  		.type = DATA,
>  		.op = REQ_OP_WRITE,
> -		.op_flags = wbc_to_write_flags(wbc),
> +		.op_flags = f2fs_wbc_to_write_flags(sbi, wbc),
>  		.old_blkaddr = NULL_ADDR,
>  		.page = page,
>  		.encrypted_page = NULL,
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 2be2b16573c3..1cc46a6dc340 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -12,6 +12,7 @@
>  #include <linux/types.h>
>  #include <linux/page-flags.h>
>  #include <linux/buffer_head.h>
> +#include <linux/writeback.h>
>  #include <linux/slab.h>
>  #include <linux/crc32.h>
>  #include <linux/magic.h>
> @@ -1264,6 +1265,7 @@ struct f2fs_sb_info {
>  
>  	/* writeback control */
>  	atomic_t wb_sync_req[META];	/* count # of WB_SYNC threads */
> +	int wsync_mode;			/* write mode */
>  
>  	/* valid inode count */
>  	struct percpu_counter total_valid_inode_count;
> @@ -3631,6 +3633,16 @@ static inline void set_opt_mode(struct f2fs_sb_info *sbi, unsigned int mt)
>  	}
>  }
>  
> +static inline int f2fs_wbc_to_write_flags(struct f2fs_sb_info *sbi,
> +				struct writeback_control *wbc)
> +{
> +	if (sbi->wsync_mode == 1)
> +		return REQ_SYNC;
> +	if (sbi->wsync_mode == 2)
> +		return REQ_BACKGROUND;
> +	return wbc_to_write_flags(wbc);
> +}
> +
>  static inline bool f2fs_may_encrypt(struct inode *inode)
>  {
>  #ifdef CONFIG_FS_ENCRYPTION
> diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
> index 3aeacd0aacfd..e3c164d921a1 100644
> --- a/fs/f2fs/sysfs.c
> +++ b/fs/f2fs/sysfs.c
> @@ -455,6 +455,7 @@ F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
>  F2FS_GENERAL_RO_ATTR(features);
>  F2FS_GENERAL_RO_ATTR(current_reserved_blocks);
>  F2FS_GENERAL_RO_ATTR(unusable);
> +F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, wsync_mode, wsync_mode);
>  
>  #ifdef CONFIG_FS_ENCRYPTION
>  F2FS_FEATURE_RO_ATTR(encryption, FEAT_CRYPTO);
> @@ -515,6 +516,7 @@ static struct attribute *f2fs_attrs[] = {
>  	ATTR_LIST(features),
>  	ATTR_LIST(reserved_blocks),
>  	ATTR_LIST(current_reserved_blocks),
> +	ATTR_LIST(wsync_mode),
>  	NULL,
>  };
>  ATTRIBUTE_GROUPS(f2fs);
> 

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

* Re: [f2fs-dev] [PATCH] f2fs: add wsync_mode for sysfs entry
  2019-06-24  1:46 ` [f2fs-dev] " Chao Yu
@ 2019-06-24 13:22   ` Christoph Hellwig
  0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2019-06-24 13:22 UTC (permalink / raw)
  To: Chao Yu; +Cc: Jaegeuk Kim, linux-kernel, linux-f2fs-devel, Jaegeuk Kim

Moreover if it makes sense it should be a generic setting.  Please
Cc Jens who added REQ_BACKGROUND and linux-mm to the cc list so that
we can have a good discussion.

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

end of thread, other threads:[~2019-06-24 13:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-21 18:01 [PATCH] f2fs: add wsync_mode for sysfs entry Jaegeuk Kim
2019-06-24  1:46 ` [f2fs-dev] " Chao Yu
2019-06-24 13:22   ` Christoph Hellwig

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).