From: Ojaswin Mujoo <ojaswin@linux.ibm.com>
To: linux-ext4@vger.kernel.org, "Theodore Ts'o" <tytso@mit.edu>
Cc: John Garry <john.g.garry@oracle.com>,
dchinner@redhat.com, "Darrick J . Wong" <djwong@kernel.org>,
Ritesh Harjani <ritesh.list@gmail.com>,
linux-kernel@vger.kernel.org
Subject: [RFC v3 08/11] ext4: add forcealign support of mballoc
Date: Mon, 24 Mar 2025 13:07:06 +0530 [thread overview]
Message-ID: <18c0e6352a9d20bea37447e6500ecec4cae73614.1742800203.git.ojaswin@linux.ibm.com> (raw)
In-Reply-To: <cover.1742800203.git.ojaswin@linux.ibm.com>
Introduce an EXT4_MB_FORCE_ALIGN flag that essentially enforces the same
behavior as EXT4_MB_HINT_ALIGNED however the alignment requirements are no
longer a hint but must be respected. If the allocator can't return aligned
blocks, then ENOSPC will be thrown.
This will be eventually used to guarantee aligned blocks to perform H/W
accelerated atomic writes.
Signed-off-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>
---
fs/ext4/ext4.h | 2 ++
fs/ext4/mballoc.c | 31 +++++++++++++++++++++++--------
include/trace/events/ext4.h | 1 +
3 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index ab4f10f9031a..9b9d7a354736 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -224,6 +224,8 @@ enum criteria {
#define EXT4_MB_CR_BEST_AVAIL_LEN_OPTIMIZED 0x00020000
/* mballoc will try to align physical start to length (aka natural alignment) */
#define EXT4_MB_HINT_ALIGNED 0x40000
+/* Same as HINT_ALIGNED but fail allocation if alginment can't be guaranteed */
+#define EXT4_MB_FORCE_ALIGN 0x80000
struct ext4_allocation_request {
/* target inode for block we're allocating */
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index db7c593873a9..412aa80bc6e7 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -2872,12 +2872,21 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
ac->ac_criteria = cr;
if (ac->ac_criteria > CR_POWER2_ALIGNED &&
- ac->ac_flags & EXT4_MB_HINT_ALIGNED &&
ac->ac_g_ex.fe_len > 1) {
- ext4_warning_inode(
- ac->ac_inode,
- "Aligned allocation not possible, using unaligned allocation");
- ac->ac_flags &= ~EXT4_MB_HINT_ALIGNED;
+ if (ac->ac_flags & EXT4_MB_FORCE_ALIGN) {
+ ext4_warning_inode(
+ ac->ac_inode,
+ "Aligned allocation not possible, failing allocation");
+ ac->ac_status = AC_STATUS_BREAK;
+ goto exit;
+ }
+
+ if (ac->ac_flags & EXT4_MB_HINT_ALIGNED) {
+ ext4_warning_inode(
+ ac->ac_inode,
+ "Aligned allocation not possible, using unaligned allocation");
+ ac->ac_flags &= ~EXT4_MB_HINT_ALIGNED;
+ }
}
/*
@@ -3023,9 +3032,15 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
goto exit;
}
- WARN_ON_ONCE(!is_power_of_2(len));
- WARN_ON_ONCE(start % len);
- WARN_ON_ONCE(ac->ac_b_ex.fe_len < ac->ac_o_ex.fe_len);
+ if (WARN_ON_ONCE(!is_power_of_2(len)) ||
+ WARN_ON_ONCE(start % len) ||
+ WARN_ON_ONCE(ac->ac_b_ex.fe_len < ac->ac_o_ex.fe_len)) {
+ /* FORCE_ALIGN should error out if aligned blocks can't be found */
+ if (ac->ac_flags & EXT4_MB_FORCE_ALIGN) {
+ ac->ac_status = AC_STATUS_BREAK;
+ goto exit;
+ }
+ }
}
exit:
diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
index d9464ee764af..ebc1fb5ad57b 100644
--- a/include/trace/events/ext4.h
+++ b/include/trace/events/ext4.h
@@ -37,6 +37,7 @@ struct partial_cluster;
{ EXT4_MB_USE_ROOT_BLOCKS, "USE_ROOT_BLKS" }, \
{ EXT4_MB_USE_RESERVED, "USE_RESV" }, \
{ EXT4_MB_HINT_ALIGNED, "HINT_ALIGNED" }, \
+ { EXT4_MB_FORCE_ALIGN, "FORCE_ALIGN" }, \
{ EXT4_MB_STRICT_CHECK, "STRICT_CHECK" })
#define show_map_flags(flags) __print_flags(flags, "|", \
--
2.48.1
next prev parent reply other threads:[~2025-03-24 7:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-24 7:36 [RFC v3 00/11] ext4: Add extsize and forcealign support (groundwork for multi block atomic writes) Ojaswin Mujoo
2025-03-24 7:36 ` [RFC v3 01/11] ext4: add aligned allocation hint in mballoc Ojaswin Mujoo
2025-03-24 7:37 ` [RFC v3 02/11] ext4: allow inode preallocation for aligned alloc Ojaswin Mujoo
2025-03-24 7:37 ` [RFC v3 03/11] ext4: support for extsize hint using FS_IOC_FS(GET/SET)XATTR Ojaswin Mujoo
2025-03-24 7:37 ` [RFC v3 04/11] ext4: pass lblk and len explicitly to ext4_split_extent*() Ojaswin Mujoo
2025-03-24 7:37 ` [RFC v3 05/11] ext4: add extsize hint support Ojaswin Mujoo
2025-03-24 7:37 ` [RFC v3 06/11] ext4: make extsize work with EOF allocations Ojaswin Mujoo
2025-03-24 7:37 ` [RFC v3 07/11] ext4: add ext4_map_blocks_extsize() wrapper to handle overwrites Ojaswin Mujoo
2025-03-24 7:37 ` Ojaswin Mujoo [this message]
2025-03-24 7:37 ` [RFC v3 09/11] ext4: add forcealign support to ext4_map_blocks Ojaswin Mujoo
2025-03-24 7:37 ` [RFC v3 10/11] ext4: add support for adding focealign via SETXATTR ioctl Ojaswin Mujoo
2025-03-24 7:37 ` [RFC v3 11/11] ext4: disallow unaligned deallocations on forcealign inodes Ojaswin Mujoo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=18c0e6352a9d20bea37447e6500ecec4cae73614.1742800203.git.ojaswin@linux.ibm.com \
--to=ojaswin@linux.ibm.com \
--cc=dchinner@redhat.com \
--cc=djwong@kernel.org \
--cc=john.g.garry@oracle.com \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ritesh.list@gmail.com \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®