From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: hch@lst.de, Heming Zhao <heming.zhao@suse.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Mark Fasheh <mark@fasheh.com>, Joel Becker <jlbec@evilplan.org>,
ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
Joseph Qi <joseph.qi@linux.alibaba.com>
Subject: [RFC PATCH v14 04/10] ocfs2: refactor ocfs2_lock_allocators() and add a dio variant
Date: Tue, 1 Dec 2026 18:07:18 +0800 [thread overview]
Message-ID: <20261201100724.2909559-5-joseph.qi@linux.alibaba.com> (raw)
In-Reply-To: <20261201100724.2909559-1-joseph.qi@linux.alibaba.com>
From: Heming Zhao <heming.zhao@suse.com>
ocfs2_lock_allocators() derives the worst case number of extent records
from clusters_to_add + 2 * extents_to_split, which assumes the caller
inserts one record per cluster. A direct write does not: it allocates its
whole contiguous range with a single ocfs2_add_inode_data() call, and
ocfs2_add_clusters_in_btree() makes exactly one ocfs2_insert_extent()
call, so at most one record is added. It does not split an extent either,
because unwritten extents are converted when the io is done.
Factor the reservation into __ocfs2_lock_allocators() taking
max_recs_needed directly. ocfs2_lock_allocators() keeps its current
computation, and ocfs2_lock_allocators_dio() passes one record when there
is anything to allocate.
Reserving metadata is still driven by ocfs2_num_free_extents(), which
counts the free records in the rightmost leaf - the same block
ocfs2_figure_insert_type() tests - so a tree that needs to grow still gets
a metadata reservation.
No functional change for existing callers.
Co-developed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Signed-off-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Signed-off-by: Heming Zhao <heming.zhao@suse.com>
---
fs/ocfs2/suballoc.c | 50 +++++++++++++++++++++++++++++++++++++++------
fs/ocfs2/suballoc.h | 5 +++++
2 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index 23c9fbb31cbd1..8c7e7b50efbc9 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -3242,15 +3242,20 @@ int ocfs2_release_clusters(handle_t *handle,
*
* File systems which don't support holes call this from
* ocfs2_extend_allocation().
+ *
+ * @clusters_to_add is the number of data clusters to reserve.
+ * @max_recs_needed is the worst case number of extent records this
+ * allocation can add. It is not always @clusters_to_add: a direct write
+ * inserts its whole contiguous range with one ocfs2_add_inode_data() call.
*/
-int ocfs2_lock_allocators(struct inode *inode,
- struct ocfs2_extent_tree *et,
- u32 clusters_to_add, u32 extents_to_split,
- struct ocfs2_alloc_context **data_ac,
- struct ocfs2_alloc_context **meta_ac)
+static int __ocfs2_lock_allocators(struct inode *inode,
+ struct ocfs2_extent_tree *et,
+ u32 clusters_to_add,
+ u32 max_recs_needed,
+ struct ocfs2_alloc_context **data_ac,
+ struct ocfs2_alloc_context **meta_ac)
{
int ret = 0, num_free_extents;
- unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split;
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
*meta_ac = NULL;
@@ -3314,6 +3319,39 @@ int ocfs2_lock_allocators(struct inode *inode,
return ret;
}
+/*
+ * Reserve for an allocation which may add one extent record per cluster. A
+ * buffered write inserts each cluster separately, and splitting an unwritten
+ * extent can add two more records.
+ */
+int ocfs2_lock_allocators(struct inode *inode,
+ struct ocfs2_extent_tree *et,
+ u32 clusters_to_add, u32 extents_to_split,
+ struct ocfs2_alloc_context **data_ac,
+ struct ocfs2_alloc_context **meta_ac)
+{
+ return __ocfs2_lock_allocators(inode, et, clusters_to_add,
+ clusters_to_add + 2 * extents_to_split,
+ data_ac, meta_ac);
+}
+
+/*
+ * A direct write allocates its whole contiguous range with a single
+ * ocfs2_add_inode_data() call, which inserts at most one extent record, and
+ * it does not split an extent here (unwritten extents are converted when the
+ * io is done).
+ */
+int ocfs2_lock_allocators_dio(struct inode *inode,
+ struct ocfs2_extent_tree *et,
+ u32 clusters_to_add,
+ struct ocfs2_alloc_context **data_ac,
+ struct ocfs2_alloc_context **meta_ac)
+{
+ return __ocfs2_lock_allocators(inode, et, clusters_to_add,
+ clusters_to_add ? 1 : 0,
+ data_ac, meta_ac);
+}
+
/*
* Read the inode specified by blkno to get suballoc_slot and
* suballoc_bit.
diff --git a/fs/ocfs2/suballoc.h b/fs/ocfs2/suballoc.h
index 6042abc032f96..b1b725857fc6e 100644
--- a/fs/ocfs2/suballoc.h
+++ b/fs/ocfs2/suballoc.h
@@ -203,6 +203,11 @@ int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et,
u32 clusters_to_add, u32 extents_to_split,
struct ocfs2_alloc_context **data_ac,
struct ocfs2_alloc_context **meta_ac);
+int ocfs2_lock_allocators_dio(struct inode *inode,
+ struct ocfs2_extent_tree *et,
+ u32 clusters_to_add,
+ struct ocfs2_alloc_context **data_ac,
+ struct ocfs2_alloc_context **meta_ac);
int ocfs2_test_inode_bit(struct ocfs2_super *osb, u64 blkno, int *res);
--
2.39.3
next prev parent reply other threads:[~2026-12-01 10:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 10:07 [RFC PATCH v14 00/10] migrate ocfs2 DIO from buffer_head to iomap Joseph Qi
2026-12-01 10:07 ` [RFC PATCH v14 01/10] ocfs2: Add new ocfs2_map_blocks() to introduce iomap feature Joseph Qi
2026-12-01 10:07 ` [RFC PATCH v14 02/10] ocfs2: switch DIO read path from buffer_head to iomap Joseph Qi
2026-12-01 10:07 ` [RFC PATCH v14 03/10] ocfs2: add ocfs2_get_clusters_uncached() Joseph Qi
2026-12-01 10:07 ` Joseph Qi [this message]
2026-12-01 10:07 ` [RFC PATCH v14 05/10] ocfs2: record the fsync transaction when CoW makes clusters writable Joseph Qi
2026-12-01 10:07 ` [RFC PATCH v14 06/10] ocfs2: rework the direct write context for multi-cluster mappings Joseph Qi
2026-12-01 10:07 ` [RFC PATCH v14 07/10] ocfs2: switch dio write path from buffer_head to iomap Joseph Qi
2026-12-01 10:07 ` [RFC PATCH v14 08/10] ocfs2: keep sub-page overwrites of written blocks on direct I/O Joseph Qi
2026-12-01 10:07 ` [RFC PATCH v14 09/10] ocfs2: write the dio zeroed head/tail buffers out before completion Joseph Qi
2026-12-01 10:07 ` [RFC PATCH v14 10/10] ocfs2: make buffered writes wait for in-flight direct writes Joseph Qi
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=20261201100724.2909559-5-joseph.qi@linux.alibaba.com \
--to=joseph.qi@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=hch@lst.de \
--cc=heming.zhao@suse.com \
--cc=jlbec@evilplan.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark@fasheh.com \
--cc=ocfs2-devel@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.