Skip to contentSkip to conversation

add block size > page size support to ramfs

PATCH In review Pankaj Raghav (Samsung) 2 participants 5 messages Sep 24, 2024 VFS

lore
Share & tools
lore
#0 lore raw

cover add block size > page size support to ramfs

From: Pankaj Raghav <[email protected]>

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

Signature · 1 line
2.44.1
#1 lore raw

PATCH 1/2 ramfs: add blocksize mount option

From: Pankaj Raghav <[email protected]>

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.

---
 fs/ramfs/inode.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
fs/ramfs/inode.c +19 -2
index 8006faaaf0ec7..d846345a0f4b1 100644
@@ -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;
Signature · 1 line
2.44.1
#2 lore raw

PATCH 2/2 ramfs: enable block size > page size

In reply to Pankaj Raghav (Samsung)

From: Pankaj Raghav <[email protected]>

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

---
 fs/ramfs/inode.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
fs/ramfs/inode.c +8 -2
index d846345a0f4b1..5ac41115d9c62 100644
@@ -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;
Signature · 1 line
2.44.1
#3 lore raw
In reply to Pankaj Raghav (Samsung)
Quoted 4 lines · Pankaj Raghav (Samsung)

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.

Quoted 6 lines

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(-)
#4 lore raw
Quoted 9 lines · Matthew Wilcox
Quoted 4 lines · Pankaj Raghav (Samsung)

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