Skip to contentSkip to conversation

ext4: rralloc - (former rotalloc) improved round-robin allocation policy

PATCH In review Mario Lohajner 3 participants 11 messages Feb 25 – Mar 5 1 message not in the archive ext4 file system

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 ext4: rralloc - (former rotalloc) improved round-robin allocation policy

V2 patch incorporating feedback from previous discussion:

- per-inode atomic cursors to enforce stream sequentiality
- per-CPU starting points to reduce contention
- allocator isolation maintained; regular allocator untouched
- name changed to rralloc to avoid confusion with "rotational"
- preliminary tests confirm expected performance

Files modified:
- fs/ext4/ext4.h
rralloc policy declared, per-CPU cursors & allocator vector

- fs/ext4/ialloc.c
initialize (zero) per-inode cursor

- fs/ext4/mballoc.h
expose allocator functions for vectoring in super.c

- fs/ext4/super.c
parse rralloc option, init per-CPU cursors and allocator vector

- fs/ext4/mballoc.c
add rotating allocator, vectored allocator

---
 fs/ext4/ext4.h    |  10 +++-
 fs/ext4/ialloc.c  |   3 +-
 fs/ext4/mballoc.c | 115 ++++++++++++++++++++++++++++++++++++++++++++--
 fs/ext4/mballoc.h |   3 ++
 fs/ext4/super.c   |  33 ++++++++++++-
 5 files changed, 157 insertions(+), 7 deletions(-)
fs/ext4/ext4.h +9 -1
index 293f698b7042..210332affd47 100644
@@ -229,6 +229,9 @@ struct ext4_allocation_request {
 	unsigned int flags;
 };
 
+/* rralloc show pointer type to compiler */
+struct ext4_allocation_context;
+
 /*
  * Logical to physical block mapping, used by ext4_map_blocks()
  *
@@ -1032,7 +1035,8 @@ struct ext4_inode_info {
 	__le32	i_data[15];	/* unconverted */
 	__u32	i_dtime;
 	ext4_fsblk_t	i_file_acl;
-
+	/* rralloc per inode cursor */
+	atomic_t	cursor;
 	/*
 	 * i_block_group is the number of the block group which contains
 	 * this file's inode.  Constant across the lifetime of the inode,
@@ -1217,6 +1221,7 @@ struct ext4_inode_info {
  * Mount flags set via mount options or defaults
  */
 #define EXT4_MOUNT_NO_MBCACHE		0x00001 /* Do not use mbcache */
+#define EXT4_MOUNT_RRALLOC			0x00002 /* Use round-robin policy/allocator */
 #define EXT4_MOUNT_GRPID		0x00004	/* Create files with directory's group */
 #define EXT4_MOUNT_DEBUG		0x00008	/* Some debugging messages */
 #define EXT4_MOUNT_ERRORS_CONT		0x00010	/* Continue on errors */
@@ -1546,6 +1551,9 @@ struct ext4_sb_info {
 	unsigned long s_mount_flags;
 	unsigned int s_def_mount_opt;
 	unsigned int s_def_mount_opt2;
+	/* rralloc per-cpu cursors and allocator vector */
+	ext4_group_t __percpu *s_rralloc_cursor;
+	int (*s_vectored_allocator)(struct ext4_allocation_context *ac);
 	ext4_fsblk_t s_sb_block;
 	atomic64_t s_resv_clusters;
 	kuid_t s_resuid;
fs/ext4/ialloc.c +2 -1
index b20a1bf866ab..c72cee642eca 100644
@@ -962,7 +962,8 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap,
 	if (!inode)
 		return ERR_PTR(-ENOMEM);
 	ei = EXT4_I(inode);
-
+	/* Zero the rralloc per-inode cursor */
+	atomic_set(&ei->cursor, 0);
 	/*
 	 * Initialize owners and quota early so that we don't have to account
 	 * for quota initialization worst case in standard inode creating
fs/ext4/mballoc.c +111 -4

140 lines not on this page · raw message

fs/ext4/mballoc.h +3 -0
index 15a049f05d04..27d7a7dd7044 100644
@@ -270,4 +270,7 @@ ext4_mballoc_query_range(
 	ext4_mballoc_query_range_fn	formatter,
 	void				*priv);
 
+/* Expose rotating & regular allocator for vectoring */
+int ext4_mb_rotating_allocator(struct ext4_allocation_context *ac);
+int ext4_mb_regular_allocator(struct ext4_allocation_context *ac);
 #endif
fs/ext4/super.c +32 -1
index 43f680c750ae..1e4cf6a40c88 100644
@@ -1284,6 +1284,10 @@ static void ext4_put_super(struct super_block *sb)
 	int aborted = 0;
 	int err;
 
+	/* free per cpu cursors */
+	if (sbi->s_rralloc_cursor)
+		free_percpu(sbi->s_rralloc_cursor);
+
 	/*
 	 * Unregister sysfs before destroying jbd2 journal.
 	 * Since we could still access attr_journal_task attribute via sysfs
@@ -1683,7 +1687,7 @@ enum {
 	Opt_dioread_nolock, Opt_dioread_lock,
 	Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
 	Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache,
-	Opt_no_prefetch_block_bitmaps, Opt_mb_optimize_scan,
+	Opt_no_prefetch_block_bitmaps, Opt_mb_optimize_scan, Opt_rralloc,
 	Opt_errors, Opt_data, Opt_data_err, Opt_jqfmt, Opt_dax_type,
 #ifdef CONFIG_EXT4_DEBUG
 	Opt_fc_debug_max_replay, Opt_fc_debug_force
@@ -1805,6 +1809,7 @@ static const struct fs_parameter_spec ext4_param_specs[] = {
 	fsparam_u32	("init_itable",		Opt_init_itable),
 	fsparam_flag	("init_itable",		Opt_init_itable),
 	fsparam_flag	("noinit_itable",	Opt_noinit_itable),
+	fsparam_flag	("rralloc",	Opt_rralloc),
 #ifdef CONFIG_EXT4_DEBUG
 	fsparam_flag	("fc_debug_force",	Opt_fc_debug_force),
 	fsparam_u32	("fc_debug_max_replay",	Opt_fc_debug_max_replay),
@@ -1886,6 +1891,7 @@ static const struct mount_opts {
 	{Opt_noauto_da_alloc, EXT4_MOUNT_NO_AUTO_DA_ALLOC, MOPT_SET},
 	{Opt_auto_da_alloc, EXT4_MOUNT_NO_AUTO_DA_ALLOC, MOPT_CLEAR},
 	{Opt_noinit_itable, EXT4_MOUNT_INIT_INODE_TABLE, MOPT_CLEAR},
+	{Opt_rralloc, EXT4_MOUNT_RRALLOC, MOPT_SET},
 	{Opt_dax_type, 0, MOPT_EXT4_ONLY},
 	{Opt_journal_dev, 0, MOPT_NO_EXT2},
 	{Opt_journal_path, 0, MOPT_NO_EXT2},
@@ -2272,6 +2278,9 @@ static int ext4_parse_param(struct fs_context *fc, struct fs_parameter *param)
 			ctx->s_li_wait_mult = result.uint_32;
 		ctx->spec |= EXT4_SPEC_s_li_wait_mult;
 		return 0;
+	case Opt_rralloc:
+		ctx_set_mount_opt(ctx, EXT4_MOUNT_RRALLOC);
+		return 0;
 	case Opt_max_dir_size_kb:
 		ctx->s_max_dir_size_kb = result.uint_32;
 		ctx->spec |= EXT4_SPEC_s_max_dir_size_kb;
@@ -5311,6 +5320,9 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 	struct ext4_fs_context *ctx = fc->fs_private;
 	int silent = fc->sb_flags & SB_SILENT;
 
+	/* Unconditional default regular allocator (rralloc separation) */
+	sbi->s_vectored_allocator = ext4_mb_regular_allocator;
+
 	/* Set defaults for the variables that will be set during parsing */
 	if (!(ctx->spec & EXT4_SPEC_JOURNAL_IOPRIO))
 		ctx->journal_ioprio = EXT4_DEF_JOURNAL_IOPRIO;
@@ -5522,6 +5534,25 @@ static int __ext4_fill_super(struct fs_context *fc, struct super_block *sb)
 		}
 	}
 
+	/* rralloc: initialize per-cpu cursors and rotational allocator */
+	if (test_opt(sb, RRALLOC)) {
+		sbi->s_rralloc_cursor = alloc_percpu(ext4_group_t);
+		if (!sbi->s_rralloc_cursor)
+			return -ENOMEM;
+
+		int ncpus = num_possible_cpus();
+		ext4_group_t total_groups = ext4_get_groups_count(sb);
+		ext4_group_t groups_per_cpu = total_groups / ncpus;
+		int cpu;
+
+		for_each_possible_cpu(cpu) {
+			*per_cpu_ptr(sbi->s_rralloc_cursor, cpu) = cpu * groups_per_cpu;
+		}
+
+		/* Vectored allocator to round-robin allocator */
+		sbi->s_vectored_allocator = ext4_mb_rotating_allocator;
+	}
+
 	/*
 	 * Get the # of file system overhead blocks from the
 	 * superblock if present.
Signature · 1 line
2.53.0
#2 lore raw
Quoted 8 lines · Mario Lohajner

V2 patch incorporating feedback from previous discussion:

- per-inode atomic cursors to enforce stream sequentiality
- per-CPU starting points to reduce contention
- allocator isolation maintained; regular allocator untouched
- name changed to rralloc to avoid confusion with "rotational"
- preliminary tests confirm expected performance

Mario, can you please include a summary of the performance test results into the commit message so that the effectiveness of the patch can be evaluated. This should include test(s) run and their arguments, along with table of before/after numbers.

Cheers, Andreas

Quoted 17 lines

Files modified:
- fs/ext4/ext4.h
rralloc policy declared, per-CPU cursors & allocator vector

- fs/ext4/ialloc.c
initialize (zero) per-inode cursor

- fs/ext4/mballoc.h
expose allocator functions for vectoring in super.c

- fs/ext4/super.c
parse rralloc option, init per-CPU cursors and allocator vector

- fs/ext4/mballoc.c
add rotating allocator, vectored allocator

maintainer
#3 lore raw
Quoted 5 lines · Andreas Dilger

Mario, can you please include a summary of the performance test results into the commit message so that the effectiveness of the patch can be evaluated. This should include test(s) run and their arguments, along with table of before/after numbers.

The tests should also include an explanation of the hardware that you ran the test on. Some example of cover letters that include perforance improvement results:

https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/

Cheers,

- Ted

#4 lore raw
Quoted 11 lines · Theodore Tso
Quoted 5 lines · Andreas Dilger

Mario, can you please include a summary of the performance test results into the commit message so that the effectiveness of the patch can be evaluated. This should include test(s) run and their arguments, along with table of before/after numbers.

The tests should also include an explanation of the hardware that you ran the test on. Some example of cover letters that include perforance improvement results:

Quoted 6 lines

https://lore.kernel.org/all/[email protected]/
https://lore.kernel.org/all/[email protected]/

Cheers,

- Ted

Hello Andreas, hello Theodore!

These are the results of synthetic tests designed to evaluate whether the round-robin allocator (rralloc) maintains its allocation behavior without degrading performance, and to examine its behavior under high concurrency and stress conditions.

The primary purpose of rralloc is to improve allocation distribution and avoid hotspotting. Performance improvements are not the goal here, throughput similar to regular allocator is considered favorable.

# Workloads
*** Large Sequential Files
(Evaluates sequential write throughput with multi-job concurrency)

fio --name=seqwrite --directory=. --rw=write --bs=1M --numjobs=6 \
--size=4G --runtime=300 --time_based --group_reporting

*** Small Files
(Validates allocator behavior and latency under small, random writes)

fio --name=smallfiles --directory=. --rw=write --bs=4k --numjobs=6 \
--size=1G --ioengine=psync --time_based --runtime=180 --group_reporting

*** Multi-core / Multi-task Stress
(Tests high concurrency and stress conditions)

fio --name=allocstress --directory=. --rw=write --bs=4k --numjobs=48 \
--size=2G --ioengine=psync --time_based --runtime=180 --group_reporting

# Results summary:

| Test        | Allocator | BW (MiB/s) | IOPS  | Avg lat |
| ----------- | --------- | ---------- | ----- | ------- |
| seqwrite    | Regular   | 497        | 496   | 9.19 ms |
|             | rralloc   | 538        | 537   | 9.37 ms |
| smallfiles  | Regular   | 707        | 181k  | 2.03 µs |
|             | rralloc   | 586        | 150k  | 2.18 µs |
| allocstress | Regular   | 166        | 42.4k | 1.13 ms |
|             | rralloc   | 283        | 72.5k | 0.66 ms |

The results indicate that a round-robin allocation strategy can be introduced without compromising baseline I/O characteristics.

Across tested workloads, rralloc preserves expected I/O behavior and does not introduce performance regressions of practical significance.

| Test     | Hardware                                   |
| -------- | ------------------------------------------ |
| OS       | Fedora Linux 42 Workstation x86_64         |
| Host     | 90HU007QGE ideacentre 510-15ICB            |
| Kernel   | 6.18.9-dirty                               |
| CPU      | Intel i5-8400 (6 cores) @ 2.801GHz         |
| GPU1     | AMD Radeon RX 560                          |
| GPU2     | Intel CoffeeLake-S GT2 / UHD Graphics 630  |
| Memory   | 1379 MiB / 31,958 MiB                      |
| NVMe     | INTEL SSDPEKNW512G8H (HPS1)                |
| SATA SSD | Samsung SSD 860 PRO 256GB (RVM02B6Q)       |

Note:
These results reflect synthetic tests on the described hardware. Independent reproduction and verification of these findings are welcome. Variations in hardware, kernel version, or workload configuration may affect absolute numbers, but the qualitative observation—that rralloc preserves baseline I/O behavior—remains valid.

For more details (raw outputs) please refer to:
https://github.com/mlohajner/RRALLOC

Regards,
Mario Lohajner (manjo)

maintainer
#5 lore raw
Quoted 2 lines · Mario Lohajner

The primary purpose of rralloc is to improve allocation distribution
and avoid hotspotting. Performance improvements are not the goal here...

You haven't explained *why* allocation distribution and avoiding hotspotting is something we should care about.

If it's not performance, then why? How does reducing hotspotting improve things for the user? Why should we care about this goal that apparently is so important to you?

- Ted

#6 lore raw
Quoted 4 lines · Theodore Tso
Quoted 2 lines · Mario Lohajner

The primary purpose of rralloc is to improve allocation distribution
and avoid hotspotting. Performance improvements are not the goal here...

Quoted 8 lines

You haven't explained *why* allocation distribution and avoiding hotspotting is something we should care about.

If it's not performance, then why? How does reducing hotspotting improve things for the user? Why should we care about this goal that apparently is so important to you?

- Ted

Hello Ted,

The motivation behind rralloc is to promote even allocation across the available LBA under overwrite-heavy workloads.

With the regular allocator, repeated allocations can concentrate the pressure in specific regions (e.g., in-place overwrites or LBA start).

rralloc spreads allocations across the LBA, reducing localized contention while:
* promoting existing stream allocation behavior
* distributing LBA space per CPU
* preserving intra-file locality and heuristics
* using the entire LBA in a round-robin manner
* minimizing contention and races
* keeping the regular allocator isolated and intact

Block group usage analysis confirms that rralloc distributes allocations evenly without degrading baseline throughput:
* small/medium/large file fragmentation experiments
* synthetic tests
* real-world tests (kernel source tree copies)

https://github.com/mlohajner/RRALLOC

Why it matters:
Concentrated allocation can create contention, write amplification, and uneven LBA utilization even on modern NVMe/SSD devices. rralloc promotes round-robin allocation across the entire LBA, with per-CPU zones, ensuring more even allocation distribution while leaving throughput and existing heuristics unchanged.

Workloads include (but not limited to):
* media files processing and rendering
* builds/compilations
* database workloads

End user impact:
Users can enable rralloc at mount to take advantage of this alternative allocation policy.
Regular allocator behavior remains unchanged for those who prefer linear or traditional allocation.

This approach is backward-compatible, non-intrusive, and preserves on-disk format and existing heuristics.

Preliminary observations under heavy multi-threaded workloads suggest reduced contention effects, but this has not yet been fully characterized.

Regards,
Mario Lohajner (manjo)

maintainer
#7 lore raw
Quoted 3 lines · Mario Lohajner

Concentrated allocation can create contention, write amplification, and uneven LBA utilization even on modern NVMe/SSD devices.

Uneven LBA utilization is the thing where I'm asking, "why should we care".

In terms of how this would cause contention and write amplification, <<citation needed>>. What is your benchmarks where you can demonstrate this, and how common is this across NVMe/SSD devices? That is, if it's just one trashy product, maybe it should just be avoided --- especially if it has other problems.

- Ted

#8 lore raw
Quoted 7 lines · Theodore Tso
Quoted 3 lines · Mario Lohajner

Concentrated allocation can create contention, write amplification, and uneven LBA utilization even on modern NVMe/SSD devices.

Uneven LBA utilization is the thing where I'm asking, "why should we care".

Quoted 7 lines

In terms of how this would cause contention and write amplification, <<citation needed>>. What is your benchmarks where you can demonstrate this, and how common is this across NVMe/SSD devices? That is, if it's just one trashy product, maybe it should just be avoided --- especially if it has other problems.

- Ted

RRALLOC spreads allocation starting points across block groups to avoid repeated concentration under parallel load.

This reduces short-term allocation concentration in the same regions when multiple CPUs allocate concurrently.

In high-concurrency testing, performance is consistently comparable to or occasionally better than the regular allocator. No regressions have been observed across tested configurations.

Under sustained parallel allocation pressure, testing shows improved tail-latency stability compared to the current allocator.

Additional high-concurrency test results are available at:
https://github.com/mlohajner/RRALLOC

Regards,
Mario Lohajner

maintainer
#9 lore raw
Quoted 2 lines · Mario Lohajner

RRALLOC spreads allocation starting points across block groups to avoid repeated concentration under parallel load.

There are already other ways in which we spread allocations across block groups. You need to tell explain a specific workload where this actually makes a difference.

Also note that in most use cases, files are written once, and read multiple times. So spreading blocks across different block groups is can often be actively harmful.

Quoted 3 lines

In high-concurrency testing, performance is consistently comparable to or occasionally better than the regular allocator. No regressions have been observed across tested configurations.

No regressions, and only "occasionally better" not enough of a justifiation.

What is your real life workload which is motivating your efforts?

- Ted

#10 lore raw
Quoted 16 lines · Theodore Tso
Quoted 2 lines · Mario Lohajner

RRALLOC spreads allocation starting points across block groups to avoid repeated concentration under parallel load.

There are already other ways in which we spread allocations across block groups. You need to tell explain a specific workload where this actually makes a difference.

Also note that in most use cases, files are written once, and read multiple times. So spreading blocks across different block groups is can often be actively harmful.

Quoted 3 lines

In high-concurrency testing, performance is consistently comparable to or occasionally better than the regular allocator. No regressions have been observed across tested configurations.

Quoted 5 lines

No regressions, and only "occasionally better" not enough of a justifiation.

What is your real life workload which is motivating your efforts?

- Ted

RRALLOC targets sustained parallel overwrite-heavy workloads such as scratch disks, rendering outputs, database storage and VM image storage.

It introduces a round-robin allocation policy across block groups to reduce short-term allocation concentration under high concurrency.

It is not intended to improve write-once/read-many workloads and remains disabled by default.

I do understand that without clearly measurable workload-specific improvement, this is likely not sufficient justification for upstream inclusion.

I will continue evaluating and refining the allocator out-of-tree. If I am able to demonstrate concrete and reproducible benefits beyond allocation geometry and occasional contention-related effects, I will revisit the discussion with additional data.

Thank you for the review and valuable feedback.

Regards,
Mario Lohajner

maintainer
#11 lore raw
Quoted 5 lines · Mario Lohajner

RRALLOC targets sustained parallel overwrite-heavy workloads such as scratch disks, rendering outputs, database storage and VM image storage.
....
It is not intended to improve write-once/read-many workloads and remains disabled by default.

First of all, databases and VM images are use cases which are almost the definition of write-once / read-many workloads.

As far as your first two examples, I've been part of teams that have built storage systems for scratch disks and rendering outputs at an extremely large scale, at *extremely* large scale. (A public estimate from 2013[1], for which I make no comments about how accurate it was back then, but it's fair to say that there have been at least a few more data centers built since then; also, disks and SSD have gotten somewhat more efficient from storage density since them. :-)

[1] https://what-if.xkcd.com/63/

Having built and supported systems for these first two use cases, I can quite confidentially tell you that the problem that you are trying to solve for weren't even *close* to real world issues that we had to overcome.

Now, it may be that you are doing some very different (or perhaps very dumb; I can't say given how few details you've given). But what you've described is so vague and scatter-shot that it could have come from the output of a very Large Language Model given a very sloppily written prompt. (In other words, what is commonlly called "AI Slop".)

If you want to be convincing, you'll need to give a lot more specific detail about the nature of the workloads. How many Petabytes (or whatever the appropriate unit in your case) per hour of data is being written? What kind of storage devices are you using? How many are you using? Attached to how many servers? How many files are being written in parallel? At what throughput rate?

When you use stock ext4 for this workload, what are you seeing? What sort of benchmarking did you use to convince yourself that the bottleneck is indeed block allocation algorithm. What kind of percentage increase did your replacement algorithm have for this specific workload.

If you want to see examples of well-written papers of various performance improvements, I will refer you to papers from Usenix's File System and Storage Technologies conference[2] for examples of how to write a convincing paper when you're not free to share *all* of the details of the workload, or the specific storage devices that you are using. The problem is right now, you've shared nothing about your specific workload.

[2] https://www.usenix.org/conferences/byname/146

Cheers,

- Ted