mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] add block size > page size support to ramfs
@ 2024-09-24 19:23 Pankaj Raghav (Samsung)
  2024-09-24 19:23 ` [PATCH 1/2] ramfs: add blocksize mount option Pankaj Raghav (Samsung)
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Pankaj Raghav (Samsung) @ 2024-09-24 19:23 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel
  Cc: willy, mcgrof, gost.dev, akpm, kernel, Christian Brauner, Pankaj Raghav

From: Pankaj Raghav <p.raghav@samsung.com>

Add block size > page size to ramfs as we support minimum folio order
allocation in the page cache. The changes are very minimal, and this is
also a nice way to stress test just the page cache changes for minimum
folio order.

I tested the changes from blocksize 4k to 2M with ltp's fsx on an x86
machine.

I ran a basic perf test with dd as follows:
$ mount ramfs -t ramfs -o blocksize=$bs /media/test/
$ dd if=/mnt/rand of="/media/test/rand" bs=2M count=2048

+------+----------+
|  bs  | BW(GB/s) |
+------+----------+
| 4k   |      1.7 |
| 8k   |      2.4 |
| 16k  |      3.2 |
| 32k  |      4.0 |
| 64k  |      4.5 |
| 128k |      4.8 |
| 256k |      5.3 |
| 512k |      5.5 |
| 1M   |      5.6 |
| 2M   |      5.6 |
+------+----------+

We get better performance for larger bs as we allocate larger folios
instead of multiple smaller folios when there is no memory fragmentation
and pressure.

Pankaj Raghav (2):
  ramfs: add blocksize mount option
  ramfs: enable block size > page size

 fs/ramfs/inode.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)


base-commit: 4d0326b60bb753627437fff0f76bf1525bcda422
-- 
2.44.1


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

* [PATCH 1/2] ramfs: add blocksize mount option
  2024-09-24 19:23 [PATCH 0/2] add block size > page size support to ramfs Pankaj Raghav (Samsung)
@ 2024-09-24 19:23 ` Pankaj Raghav (Samsung)
  2024-09-24 19:23 ` [PATCH 2/2] ramfs: enable block size > page size Pankaj Raghav (Samsung)
  2024-09-24 20:00 ` [PATCH 0/2] add block size > page size support to ramfs Matthew Wilcox
  2 siblings, 0 replies; 5+ messages in thread
From: Pankaj Raghav (Samsung) @ 2024-09-24 19:23 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel
  Cc: willy, mcgrof, gost.dev, akpm, kernel, Christian Brauner, Pankaj Raghav

From: Pankaj Raghav <p.raghav@samsung.com>

ramfs has only supported blocksize == PAGE_SIZE as page cache's minimum
allocation unit was a PAGE_SIZE.

As the page cache now has minimum folio order support, ramfs can support
different blocksizes.

This is a preparation patch which adds blocksize mount option but still
supporting only blocksize == PAGE_SIZE.

Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
 fs/ramfs/inode.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index 8006faaaf0ec7..d846345a0f4b1 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -43,6 +43,7 @@
 
 struct ramfs_mount_opts {
 	umode_t mode;
+	u32 blocksize;
 };
 
 struct ramfs_fs_info {
@@ -221,10 +222,12 @@ static const struct super_operations ramfs_ops = {
 
 enum ramfs_param {
 	Opt_mode,
+	Opt_blocksize,
 };
 
 const struct fs_parameter_spec ramfs_fs_parameters[] = {
 	fsparam_u32oct("mode",	Opt_mode),
+	fsparam_u32("blocksize", Opt_blocksize),
 	{}
 };
 
@@ -254,6 +257,19 @@ static int ramfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
 	case Opt_mode:
 		fsi->mount_opts.mode = result.uint_32 & S_IALLUGO;
 		break;
+	case Opt_blocksize:
+		if (!fsi->mount_opts.blocksize)
+			return -EINVAL;
+
+		fsi->mount_opts.blocksize = rounddown_pow_of_two(result.uint_32);
+
+		if (fsi->mount_opts.blocksize > PAGE_SIZE)
+			fsi->mount_opts.blocksize = PAGE_SIZE;
+
+		if (fsi->mount_opts.blocksize < PAGE_SIZE)
+			fsi->mount_opts.blocksize = PAGE_SIZE;
+
+		break;
 	}
 
 	return 0;
@@ -265,8 +281,8 @@ static int ramfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	struct inode *inode;
 
 	sb->s_maxbytes		= MAX_LFS_FILESIZE;
-	sb->s_blocksize		= PAGE_SIZE;
-	sb->s_blocksize_bits	= PAGE_SHIFT;
+	sb->s_blocksize		= fsi->mount_opts.blocksize;
+	sb->s_blocksize_bits	= ilog2(fsi->mount_opts.blocksize);
 	sb->s_magic		= RAMFS_MAGIC;
 	sb->s_op		= &ramfs_ops;
 	sb->s_time_gran		= 1;
@@ -304,6 +320,7 @@ int ramfs_init_fs_context(struct fs_context *fc)
 		return -ENOMEM;
 
 	fsi->mount_opts.mode = RAMFS_DEFAULT_MODE;
+	fsi->mount_opts.blocksize = PAGE_SIZE;
 	fc->s_fs_info = fsi;
 	fc->ops = &ramfs_context_ops;
 	return 0;
-- 
2.44.1


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

* [PATCH 2/2] ramfs: enable block size > page size
  2024-09-24 19:23 [PATCH 0/2] add block size > page size support to ramfs Pankaj Raghav (Samsung)
  2024-09-24 19:23 ` [PATCH 1/2] ramfs: add blocksize mount option Pankaj Raghav (Samsung)
@ 2024-09-24 19:23 ` Pankaj Raghav (Samsung)
  2024-09-24 20:00 ` [PATCH 0/2] add block size > page size support to ramfs Matthew Wilcox
  2 siblings, 0 replies; 5+ messages in thread
From: Pankaj Raghav (Samsung) @ 2024-09-24 19:23 UTC (permalink / raw)
  To: linux-fsdevel, linux-kernel
  Cc: willy, mcgrof, gost.dev, akpm, kernel, Christian Brauner, Pankaj Raghav

From: Pankaj Raghav <p.raghav@samsung.com>

Use page cache's minimum folio order infrastructure to support block
size > page size.

Signed-off-by: Pankaj Raghav <p.raghav@samsung.com>
---
 fs/ramfs/inode.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/ramfs/inode.c b/fs/ramfs/inode.c
index d846345a0f4b1..5ac41115d9c62 100644
--- a/fs/ramfs/inode.c
+++ b/fs/ramfs/inode.c
@@ -74,6 +74,9 @@ struct inode *ramfs_get_inode(struct super_block *sb,
 		case S_IFREG:
 			inode->i_op = &ramfs_file_inode_operations;
 			inode->i_fop = &ramfs_file_operations;
+			mapping_set_folio_min_order(inode->i_mapping,
+						    sb->s_blocksize_bits -
+							    PAGE_SHIFT);
 			break;
 		case S_IFDIR:
 			inode->i_op = &ramfs_dir_inode_operations;
@@ -211,6 +214,8 @@ static int ramfs_show_options(struct seq_file *m, struct dentry *root)
 
 	if (fsi->mount_opts.mode != RAMFS_DEFAULT_MODE)
 		seq_printf(m, ",mode=%o", fsi->mount_opts.mode);
+	if (fsi->mount_opts.blocksize != PAGE_SIZE)
+		seq_printf(m, ",blocksize=%u", fsi->mount_opts.blocksize);
 	return 0;
 }
 
@@ -235,6 +240,7 @@ static int ramfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
 {
 	struct fs_parse_result result;
 	struct ramfs_fs_info *fsi = fc->s_fs_info;
+	size_t max_blocksize = mapping_max_folio_size_supported();
 	int opt;
 
 	opt = fs_parse(fc, ramfs_fs_parameters, param, &result);
@@ -263,8 +269,8 @@ static int ramfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
 
 		fsi->mount_opts.blocksize = rounddown_pow_of_two(result.uint_32);
 
-		if (fsi->mount_opts.blocksize > PAGE_SIZE)
-			fsi->mount_opts.blocksize = PAGE_SIZE;
+		if (fsi->mount_opts.blocksize > max_blocksize)
+			fsi->mount_opts.blocksize = max_blocksize;
 
 		if (fsi->mount_opts.blocksize < PAGE_SIZE)
 			fsi->mount_opts.blocksize = PAGE_SIZE;
-- 
2.44.1


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

* Re: [PATCH 0/2] add block size > page size support to ramfs
  2024-09-24 19:23 [PATCH 0/2] add block size > page size support to ramfs Pankaj Raghav (Samsung)
  2024-09-24 19:23 ` [PATCH 1/2] ramfs: add blocksize mount option Pankaj Raghav (Samsung)
  2024-09-24 19:23 ` [PATCH 2/2] ramfs: enable block size > page size Pankaj Raghav (Samsung)
@ 2024-09-24 20:00 ` Matthew Wilcox
  2024-09-24 20:24   ` Pankaj Raghav
  2 siblings, 1 reply; 5+ messages in thread
From: Matthew Wilcox @ 2024-09-24 20:00 UTC (permalink / raw)
  To: Pankaj Raghav (Samsung)
  Cc: linux-fsdevel, linux-kernel, mcgrof, gost.dev, akpm,
	Christian Brauner, Pankaj Raghav

On Tue, Sep 24, 2024 at 09:23:49PM +0200, Pankaj Raghav (Samsung) wrote:
> Add block size > page size to ramfs as we support minimum folio order
> allocation in the page cache. The changes are very minimal, and this is
> also a nice way to stress test just the page cache changes for minimum
> folio order.

I don't really see the point of upstreaming this.  I'm sure it was
useful for your testing.  And splitting the patch in two makes no sense
to me; the combined patch is not large.

> Pankaj Raghav (2):
>   ramfs: add blocksize mount option
>   ramfs: enable block size > page size
> 
>  fs/ramfs/inode.c | 27 +++++++++++++++++++++++++--
>  1 file changed, 25 insertions(+), 2 deletions(-)

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

* Re: [PATCH 0/2] add block size > page size support to ramfs
  2024-09-24 20:00 ` [PATCH 0/2] add block size > page size support to ramfs Matthew Wilcox
@ 2024-09-24 20:24   ` Pankaj Raghav
  0 siblings, 0 replies; 5+ messages in thread
From: Pankaj Raghav @ 2024-09-24 20:24 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: linux-fsdevel, linux-kernel, mcgrof, gost.dev, akpm,
	Christian Brauner, Pankaj Raghav


On Tue, Sep 24, 2024 at 09:00:26PM +0100, Matthew Wilcox wrote:
> On Tue, Sep 24, 2024 at 09:23:49PM +0200, Pankaj Raghav (Samsung) wrote:
> > Add block size > page size to ramfs as we support minimum folio order
> > allocation in the page cache. The changes are very minimal, and this is
> > also a nice way to stress test just the page cache changes for minimum
> > folio order.
>
> I don't really see the point of upstreaming this.  I'm sure it was
> useful for your testing.  And splitting the patch in two makes no sense
> to me; the combined patch is not large.

I just wanted to put it out in the wild to see if somebody found it
useful as it was pretty trivial to add the support. Also, the first
series that tried adding support for LBS in the kernel 17 years ago used
ramfs as an example :).

The only use case I could come up with was testing the folio order changes
in the page cache without having to use a more complicated FS like XFS.
In that sense it is still useful to add this feature I guess considering
the minimal changes?

--
Pankaj


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

end of thread, other threads:[~2024-09-24 20:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-24 19:23 [PATCH 0/2] add block size > page size support to ramfs Pankaj Raghav (Samsung)
2024-09-24 19:23 ` [PATCH 1/2] ramfs: add blocksize mount option Pankaj Raghav (Samsung)
2024-09-24 19:23 ` [PATCH 2/2] ramfs: enable block size > page size Pankaj Raghav (Samsung)
2024-09-24 20:00 ` [PATCH 0/2] add block size > page size support to ramfs Matthew Wilcox
2024-09-24 20:24   ` Pankaj Raghav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®