From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.112 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796032966; b=KK7FHqUd+5JtU/NLgO+biCu+agNG4JfSqzziyAglqL0kTUpbmhourtpJ1Gu+3e5eO9kD koQruqrZ8EOhYEBuZ7cRW0QXFBQ090ZppFyh24uwuxuN8Zg+yen2qPpLniZ/HR9fBu8qK jxJwYcQviF71OwqqJG/Lx7KrNJWzXawBR/hbRdOMF9EO+qEmrs3mle+uyE12iMYUsH6iJ CIIO9s6/ptMBbgHH6esDgLv1hlQ9U3hzc5amBtyDSGgis1+nabmPbpaZ1q2BjLyKlDYld G+4jfqx8Jp0LGf3cxvbDy0TGFM9PJKyGtMGEt3v5GF/JugHBJQzcRF6DShj6WgLJNfg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796032966; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:From:To:Cc: Subject:Date:Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=V/bYJE+xludLknIozzRAFtg8oAaSzFeuW/vGd7lp9oU=; b=x2YxYlg/X6jNAjfrEkqV2VFtaDlpZtVXsIaC1o4WOjU7+KaQI4MkZiMS2vQPbquSkk/E 7YrqG1Px8Z5+PzpEJfScYcoPml0ei1KcYK8wF47ZQhTQfQsDbnaMf1zwvr28l6PQ44rF9 h84W7hwPJZxzTtGE12D+Zz0bX0iEcpk2Uj6WCa+h50hHuUtUQG3D18J2xg99UmJaQrOy6 tGz5L8nDG7rbGKBd/kuA/yblrWnOhqplLXkcUw08Q+GHAP0pcF2xi1AV+WbgiFTjXtjOY oJEl0K5krA88Myp+StHGjzA1jg1OwwAM8z43AazmSwqxV8QO2m5iQE/LxP8jTBfVHtA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=aBmILbE8; arc=none smtp.remote-ip=115.124.30.112 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB5D3606A33B for ; Mon, 30 Nov 2026 10:02:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DB5D3606A33B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=aBmILbE8 DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796032958; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=V/bYJE+xludLknIozzRAFtg8oAaSzFeuW/vGd7lp9oU=; b=aBmILbE8vtwm9mnWKpH2S5ArZL1ePp4SbfRf7DkqdJ79BCTc2IN6V2urlqHWwfzoH/x4Ur1Bl8596R96lJZcEDpsdXF8WXOeNtKZyQr9bsSSpa6MSAmAVA4bWIxCPfCfmPfj8CAB2pLcBz9T04ZWcYpBruH8jbcjy+fA4RZxM2Y= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam011083073210;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0XFj7HlS_1796032957; Received: from localhost(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0XFj7HlS_1796032957 cluster:ay36) by smtp.aliyun-inc.com; Mon, 30 Nov 2026 18:02:37 +0800 From: Joseph Qi To: Heming Zhao , hch@lst.de Cc: Andrew Morton , Mark Fasheh , Joel Becker , ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, Joseph Qi Subject: [RFC PATCH v13 04/10] ocfs2: refactor ocfs2_lock_allocators() and add a dio variant Date: Mon, 30 Nov 2026 18:01:57 +0800 Message-Id: <20261130100203.383093-5-joseph.qi@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20261130100203.383093-1-joseph.qi@linux.alibaba.com> References: <20261130100203.383093-1-joseph.qi@linux.alibaba.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Heming Zhao 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 Signed-off-by: Joseph Qi Signed-off-by: Heming Zhao --- 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