From nobody Thu Apr 9 17:58:08 2026 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F38D33A6E0; Fri, 6 Mar 2026 09:03:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772787807; cv=pass; b=g2Io6n/SYESaXr3/rMrJufK1Jr6T2H3kiFKQW7F4d6klMnUqNz7HjFprGKAwLpf3o6iXk4YBgDe4GVcyD8fD7T947pFdrulk31QXddppelLT/0lIjLq4jTlT+S6WSjKQIzf5GEkUoeCPZRaf3UlDX2Xby406bt3KLr/imzPdFok= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772787807; c=relaxed/simple; bh=Hj6lHdXG+HkGViJUite+vsxSD3ZPWd2kPpVXuuduSqw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aVctIjnPjKJ/vcMtUEFNnEcTDMNjYtR5hpF3ivBsrk5UMPjvh626iYO5odn+QwMzbYIaXIduKjQ45tTgTiUGYuJqr/dsMi86G9MUmPH02ZD6X9f1DKk+2vbHPSL3QoB98FUJvc5TLVfmNq7M1Vtb6mP3K8HCDr5ZgttCdEadfKE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.beauty; spf=pass smtp.mailfrom=linux.beauty; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b=iShS0JlH; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.beauty Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.beauty Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b="iShS0JlH" ARC-Seal: i=1; a=rsa-sha256; t=1772787795; cv=none; d=zohomail.com; s=zohoarc; b=A9gsgUZtUaX8N/BexV5xf9oUtj7H72DVWtfzCcWH4DAXpMHNV9pgMqcZYnKs5FGkIS/a7TCW5oaROg0eRhS4r7gLAeoPvc/wrqYhJrxsarEkRiwR0JQq/sKP659BZfORM5Ct1pO1BQ/rX9Gty9ZhI7oVKxZGa5+g8ADcFAOGUak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772787795; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=SRSTXD9L61Hkaqs6DadL86nW5rdda4EPzuZg39TK760=; b=GAr7r9C2zye2Fb99BtwE4S4QK79bXh76Uk2161SwzZVbz9rUqZ2NC8/lMj9k1Xjnl5lwmoh1rgJOZ8gbqGhALAQHteOVRe2jSylvuqUELDS5hDMV0B3Rc2VO5aEfezZHxMqbbSgucxpaOh9+dUoRDEMt7iA6V9aprhE6/vkxEbk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1772787795; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=SRSTXD9L61Hkaqs6DadL86nW5rdda4EPzuZg39TK760=; b=iShS0JlHcMx0A6KDYasyJTkmmpOFS5N8MJv9h0C3b4ud/4U+tXEnSYTm2/TB/9N6 wZATlGa6fHAbvTH5lBnCX8ykIyutcr/6y/Ot550rQUUnWb5iWILB4z7ccfO9pF3O8En 63apRo6fHiz40xX/yrtjCUIN8/Aop6E+RPqVrSHw= Received: by mx.zohomail.com with SMTPS id 1772787792428246.8300268629713; Fri, 6 Mar 2026 01:03:12 -0800 (PST) From: Li Chen To: Theodore Ts'o , Jan Kara , Mark Fasheh , linux-ext4@vger.kernel.org, ocfs2-devel@lists.linux.dev, Jan Kara , linux-kernel@vger.kernel.org Cc: Andreas Dilger , Li Chen Subject: [PATCH v4 1/4] jbd2: add jinode dirty range accessors Date: Fri, 6 Mar 2026 16:56:39 +0800 Message-ID: <20260306085643.465275-2-me@linux.beauty> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260306085643.465275-1-me@linux.beauty> References: <20260306085643.465275-1-me@linux.beauty> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" Provide a helper to fetch jinode dirty ranges in bytes. This lets filesystem callbacks avoid depending on the internal representation, preparing for a later conversion to page units. Suggested-by: Andreas Dilger Reviewed-by: Jan Kara Signed-off-by: Li Chen --- Changes since v3: - Add Reviewed-by: Jan Kara. Changes since v2: - New patch: add jbd2_jinode_get_dirty_range() helper. include/linux/jbd2.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index a53a00d36228c..64392baf5f4b4 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -445,6 +445,20 @@ struct jbd2_inode { loff_t i_dirty_end; }; =20 +static inline bool jbd2_jinode_get_dirty_range(const struct jbd2_inode *ji= node, + loff_t *start, loff_t *end) +{ + loff_t start_byte =3D jinode->i_dirty_start; + loff_t end_byte =3D jinode->i_dirty_end; + + if (!end_byte) + return false; + + *start =3D start_byte; + *end =3D end_byte; + return true; +} + struct jbd2_revoke_table_s; =20 /** --=20 2.53.0 From nobody Thu Apr 9 17:58:08 2026 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8AB8342CBA; Fri, 6 Mar 2026 09:07:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772788046; cv=pass; b=hA4nVzJpm6BaTLIfdijXiJyxiIGSZ/SjBC4WY9WYbZr1BSX0F+OinJ6p2w1xACesHqupZ1EkwlwOjRn+V0EzGqSnffBiuUZYEcZtq/OXYxNxEmaW3Fii8vPZ4BcEBN/0577hW3EwRVt3ePdRNDbCEQ8rhXEz67HIMmuRkY4dj1g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772788046; c=relaxed/simple; bh=f9jxggpwBAEmah9F+c2UFiKDNg65LJVRMaIsD/Aw1Qw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Won1TSRJu/wEjXIqOfjOVIKYJ4KU2jyLAuD+quvYIdhWuBbD2h/gF6fBPy9FWYIjnBtNuIiK+MlPgmw4oBsIsp7w5iafCfCwNwlHZlkMWhjyI/zU8ZrW6ZKBR7zb177A4PbfR0SbvQ8Tk/urJIktuRl7Vap9QQtuIUIK69Q/Pq8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.beauty; spf=pass smtp.mailfrom=linux.beauty; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b=aUKXf+Xx; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.beauty Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.beauty Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b="aUKXf+Xx" ARC-Seal: i=1; a=rsa-sha256; t=1772788034; cv=none; d=zohomail.com; s=zohoarc; b=LjBNXEJaavu4lc/YXg4M3LzwIlwYXVnm7I6Qs8Ho8U6qaUfRBY1zUuIS0uaxWvfm0tXzRz6jUn0ZgbmDim7ajiXSar2dNZsbtcd6iHaTE6+qFDhiXtuqFhWPay/r7pyinwG/NhlYa7+rzoZDeq0LKa83D/ZJpWONV/FzOjD/JL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772788034; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=hDeA288ntLPiXzKkk06WV0KTqSx6XHe/qQriCyB0UmM=; b=WIzZgBYiYFJVaFYpPhqCVFtXu2TrYmxxD70GHi5LVSF5kBgKHDXnV5/2oJ+WcPbPc+XDRblvHmgc1L/trQlbzMs7UqjQ1iWjzCypTyD6eppFLY2eQZqJT0VZ6j39ywVy0Y41k3TG2l/JY/VhuWFcckyC/ir/JNlTjw4/K1qtrMM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1772788034; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=hDeA288ntLPiXzKkk06WV0KTqSx6XHe/qQriCyB0UmM=; b=aUKXf+XxseMzL3pxHOyYpi4o0TFaqzYwX2pYnq78s3EzX210Bibtl82LqDJ6Yjpj 3IWzhPERRrk8hS8rm2USZtyeXci4bAw1yJwqdyMoJjJUIAExGg5jDxyVZtb1FhUMKJT b5KsVC37v9fgxIhfsyLD27O+lzq0722eRfOQIOm8= Received: by mx.zohomail.com with SMTPS id 1772788032644582.3927587557158; Fri, 6 Mar 2026 01:07:12 -0800 (PST) From: Li Chen To: Theodore Ts'o , Jan Kara , Mark Fasheh , linux-ext4@vger.kernel.org, ocfs2-devel@lists.linux.dev, Andreas Dilger , linux-kernel@vger.kernel.org Cc: Li Chen Subject: [PATCH v4 2/4] ext4: use jbd2 jinode dirty range accessor Date: Fri, 6 Mar 2026 16:56:40 +0800 Message-ID: <20260306085643.465275-3-me@linux.beauty> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260306085643.465275-1-me@linux.beauty> References: <20260306085643.465275-1-me@linux.beauty> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" ext4 journal commit callbacks access jbd2_inode dirty range fields without holding journal->j_list_lock. Use jbd2_jinode_get_dirty_range() to get the range in bytes, and read i_transaction with READ_ONCE() in the redirty check. Suggested-by: Jan Kara Reviewed-by: Jan Kara Signed-off-by: Li Chen --- Changes since v3: - No changes. Changes since v2: - Use jbd2_jinode_get_dirty_range() instead of direct i_dirty_* reads. - Drop per-caller page->byte conversion (now handled by the accessor). Changes since v1: - Convert the jinode dirty range from PAGE_SIZE units (pgoff_t) back to byte offsets before passing it to writeback. fs/ext4/inode.c | 10 ++++++++-- fs/ext4/super.c | 16 +++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index da96db5f23450..f87d35bda9276 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3031,17 +3031,23 @@ static int ext4_writepages(struct address_space *ma= pping, =20 int ext4_normal_submit_inode_data_buffers(struct jbd2_inode *jinode) { + loff_t range_start, range_end; struct writeback_control wbc =3D { .sync_mode =3D WB_SYNC_ALL, .nr_to_write =3D LONG_MAX, - .range_start =3D jinode->i_dirty_start, - .range_end =3D jinode->i_dirty_end, }; struct mpage_da_data mpd =3D { .inode =3D jinode->i_vfs_inode, .wbc =3D &wbc, .can_map =3D 0, }; + + if (!jbd2_jinode_get_dirty_range(jinode, &range_start, &range_end)) + return 0; + + wbc.range_start =3D range_start; + wbc.range_end =3D range_end; + return ext4_do_writepages(&mpd); } =20 diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 69eb63dde9839..685951cd58394 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -521,6 +521,7 @@ static bool ext4_journalled_writepage_needs_redirty(str= uct jbd2_inode *jinode, { struct buffer_head *bh, *head; struct journal_head *jh; + transaction_t *trans =3D READ_ONCE(jinode->i_transaction); =20 bh =3D head =3D folio_buffers(folio); do { @@ -539,7 +540,7 @@ static bool ext4_journalled_writepage_needs_redirty(str= uct jbd2_inode *jinode, */ jh =3D bh2jh(bh); if (buffer_dirty(bh) || - (jh && (jh->b_transaction !=3D jinode->i_transaction || + (jh && (jh->b_transaction !=3D trans || jh->b_next_transaction))) return true; } while ((bh =3D bh->b_this_page) !=3D head); @@ -550,15 +551,20 @@ static bool ext4_journalled_writepage_needs_redirty(s= truct jbd2_inode *jinode, static int ext4_journalled_submit_inode_data_buffers(struct jbd2_inode *ji= node) { struct address_space *mapping =3D jinode->i_vfs_inode->i_mapping; + loff_t range_start, range_end; struct writeback_control wbc =3D { - .sync_mode =3D WB_SYNC_ALL, + .sync_mode =3D WB_SYNC_ALL, .nr_to_write =3D LONG_MAX, - .range_start =3D jinode->i_dirty_start, - .range_end =3D jinode->i_dirty_end, - }; + }; struct folio *folio =3D NULL; int error; =20 + if (!jbd2_jinode_get_dirty_range(jinode, &range_start, &range_end)) + return 0; + + wbc.range_start =3D range_start; + wbc.range_end =3D range_end; + /* * writeback_iter() already checks for dirty pages and calls * folio_clear_dirty_for_io(), which we want to write protect the --=20 2.53.0 From nobody Thu Apr 9 17:58:08 2026 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB7D133DEFC; Fri, 6 Mar 2026 09:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772788260; cv=pass; b=XhtxkXxRqGh/j//accifKYvMY1q4xB8fyHx18kA6LwiN3qrrH+i0QATNh/Yp5vYxXc0kpgK4QbyKD5SJGxtA2E12QUIYrZZsWPv5L7feE/7XkZmvySovYXmBT31w0NUgeZX3x63cps8c5gl9h9CIOypf+07YNPBMpLqCdtZYV1s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772788260; c=relaxed/simple; bh=Vrvj/Hz9mHwDjSo7ZWHDvw9X5Iwnz90mvGTE/luJ03A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EDNK3O+ZE7SRTBe1sUSP6eCN4kQ9VJ4m65BFPc69mq0Z/A+Z13fFHr6/6B/anMiGv8HBxuFgo6BxyDhNrGuROrgyLzvC/s9Oco0AbZdMYsJfDDuFyBhwXUNd0l8fBNupmcfUWMewFOscDw0kmKEzLhik1b86G/89oFdrxAAtC5g= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.beauty; spf=pass smtp.mailfrom=linux.beauty; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b=a5nhWPXd; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.beauty Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.beauty Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b="a5nhWPXd" ARC-Seal: i=1; a=rsa-sha256; t=1772788231; cv=none; d=zohomail.com; s=zohoarc; b=KXaHqSGEOMMiemKWltAh0DB/oiTNymrsdlQIEBFiPIHizS3rtSkOVXO6dbEGjq0l5OXQjJsRQiorug7FNMJjRoiIIj2r0P+yPe5BR5xNLJXpvZYY2kGCPL+C0N7SjEw/TbBkmy5LSTqKKR67xfQ1tP9/TFQvd7MJbXE2c0cDsvA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772788231; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=pJ0kj7owG62bsgS4T1OkFHO8CXLZzKqBToAuEVC/SoI=; b=IbUVkEuzTaWeo+rAXfi0OMWhNHMUlqaGzmKCqoZcud/vBm5Ro5mU7JOZxzs9vBzrNCMkVKxpwC9pzsoq0Kf61+ePtbGC/TJAsckvB9RnbU7UPCPzU6eElkQov1N1HsGdAXt6sVFX/ud4qqQseQnLg4y7uQg9ZOAorz3xpDBI080= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1772788231; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=pJ0kj7owG62bsgS4T1OkFHO8CXLZzKqBToAuEVC/SoI=; b=a5nhWPXdYLZoSxZqGekiEACbAYn9h7cHZyWxvwNr4jV6EM4tbetvym8IJRLDwTsp 38/svZQxRIsxVCUGBzwuVkf3Mc2O7E65WyMFoEcjTkXImUxDGMC2ZKnEuLrwb1qgO5z wUbIb0s8ECXZlExle7spWvdyJmMYNlcyEVdGy+Xo= Received: by mx.zohomail.com with SMTPS id 1772788229551199.97655860003874; Fri, 6 Mar 2026 01:10:29 -0800 (PST) From: Li Chen To: Theodore Ts'o , Jan Kara , Mark Fasheh , linux-ext4@vger.kernel.org, ocfs2-devel@lists.linux.dev, Joel Becker , Joseph Qi , linux-kernel@vger.kernel.org Cc: Li Chen Subject: [PATCH v4 3/4] ocfs2: use jbd2 jinode dirty range accessor Date: Fri, 6 Mar 2026 16:56:41 +0800 Message-ID: <20260306085643.465275-4-me@linux.beauty> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260306085643.465275-1-me@linux.beauty> References: <20260306085643.465275-1-me@linux.beauty> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" ocfs2 journal commit callback reads jbd2_inode dirty range fields without holding journal->j_list_lock. Use jbd2_jinode_get_dirty_range() to get the range in bytes. Suggested-by: Jan Kara Reviewed-by: Jan Kara Signed-off-by: Li Chen --- Changes since v3: - Add Reviewed-by: Jan Kara. Changes since v2: - Use jbd2_jinode_get_dirty_range() instead of direct i_dirty_* reads. - Drop per-caller page->byte conversion (now handled by the accessor). fs/ocfs2/journal.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c index 85239807dec78..68c2f567e6e1b 100644 --- a/fs/ocfs2/journal.c +++ b/fs/ocfs2/journal.c @@ -902,8 +902,13 @@ int ocfs2_journal_alloc(struct ocfs2_super *osb) =20 static int ocfs2_journal_submit_inode_data_buffers(struct jbd2_inode *jino= de) { - return filemap_fdatawrite_range(jinode->i_vfs_inode->i_mapping, - jinode->i_dirty_start, jinode->i_dirty_end); + struct address_space *mapping =3D jinode->i_vfs_inode->i_mapping; + loff_t range_start, range_end; + + if (!jbd2_jinode_get_dirty_range(jinode, &range_start, &range_end)) + return 0; + + return filemap_fdatawrite_range(mapping, range_start, range_end); } =20 int ocfs2_journal_init(struct ocfs2_super *osb, int *dirty) --=20 2.53.0 From nobody Thu Apr 9 17:58:08 2026 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E764533A9CB; Fri, 6 Mar 2026 09:13:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772788383; cv=pass; b=OB0DzAVlVxkJgPYqmmWowrWk7iLKah82mZ21Zycxf40TKgsGJCV1Hsm/RGJ9cERRyAu4KnU7YUmJOdtWFvgeZHC/qj/kjTJDxhDnVKPWrvd8KXYqidTzRtXwPCo7xqiC9DU91PCCMqWgw2hymJbwv7n6EioSa5Xq6O6yrwP7W9Y= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772788383; c=relaxed/simple; bh=RIt/K3dbf/jCBmOegl2T65GE6fBo2ZoBdKGc4eUCYhA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TPGgDsEappyljHobq2wJqVsaCVvgjoKopbOzEmo7xDPCKdZEsoyHza8XHqZH21uLgGLnHGdi/ZGmcy8pMOTZjvWtahxPwKnMbY5tb8mkXyIxLaKiUfnHmanfNJMaUM1fMjZ4bwtCVl5LYPv3yJJMsFl9xU02H/KhvwHgr33hpm8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.beauty; spf=pass smtp.mailfrom=linux.beauty; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b=fUecrIVh; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.beauty Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.beauty Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.beauty header.i=me@linux.beauty header.b="fUecrIVh" ARC-Seal: i=1; a=rsa-sha256; t=1772788374; cv=none; d=zohomail.com; s=zohoarc; b=DQllaLyE4kOpyrUg5MDFGu9pZfm2BvG0bvJNsctmFTA699vMmLs8EOO9hLShntAfsNycgTSMO1nMFr+J8YSWDIAy61BAcHuh3ZN+ABuOVsnPqf1d7vA3STEsVqxrMca2i0S2/1LCexdjkKzMenf+pAuUaWOdxF0djmfDKLFtKCw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772788374; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=UhaLQnxw6IYxJZMyMwnG0zOmGc8AkVob2k0lQF7GI3w=; b=kZvU/Hy/GI/Imla6+iHQwkJ1OvrxPFkeKN70//rzXyV6rwl2R0qfIrlJ9i7rlOc+7XSIMPZypmljmzOl66a0U908RErR0KVV5jvyQT3GEV0DEeg2ohJ8djBu7d7YtDX7GobY4NMLmH1zZSbDOWQDXYHH4JWKuYtu6IbYF2TL7pU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1772788374; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=UhaLQnxw6IYxJZMyMwnG0zOmGc8AkVob2k0lQF7GI3w=; b=fUecrIVhMi8FWdtsnANomBJjdkYvQlXciigGoOgtgujA8tB0pmjzp/UzLIiXoI+4 Yfpv8LWjdNRY71KVfo3JdkLvGCvhl7SrnYnwcpm7kzRNzhkqVwI7NDL57GMilil1x/G v7OrUMq14bsW3kuSj+Vl7Yc4aBAuuWLZ62GPEwqE= Received: by mx.zohomail.com with SMTPS id 1772788372569154.52324977364003; Fri, 6 Mar 2026 01:12:52 -0800 (PST) From: Li Chen To: Theodore Ts'o , Jan Kara , Mark Fasheh , linux-ext4@vger.kernel.org, ocfs2-devel@lists.linux.dev, Jan Kara , linux-kernel@vger.kernel.org Cc: Li Chen Subject: [PATCH v4 4/4] jbd2: store jinode dirty range in PAGE_SIZE units Date: Fri, 6 Mar 2026 16:56:42 +0800 Message-ID: <20260306085643.465275-5-me@linux.beauty> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260306085643.465275-1-me@linux.beauty> References: <20260306085643.465275-1-me@linux.beauty> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset="utf-8" jbd2_inode fields are updated under journal->j_list_lock, but some paths read them without holding the lock (e.g. fast commit helpers and ordered truncate helpers). READ_ONCE() alone is not sufficient for the dirty range fields when they are stored as loff_t because 32-bit platforms can observe torn loads. Store the dirty range in PAGE_SIZE units as pgoff_t instead. Represent the dirty range end as an exclusive end page. This avoids a special sentinel value and keeps MAX_LFS_FILESIZE on 32-bit representable. Publish a new dirty range by updating end_page before start_page, and treat start_page >=3D end_page as empty in the accessor for robustness. Use READ_ONCE() on the read side and WRITE_ONCE() on the write side for the dirty range and i_flags to match the existing lockless access pattern. Suggested-by: Jan Kara Reviewed-by: Jan Kara Signed-off-by: Li Chen --- Changes since v3: - Store i_dirty_end_page as an exclusive end page and drop the sentinel. - Publish end_page before start_page and treat start_page >=3D end_page as empty in the accessor. - Document the empty-range encoding and publication ordering in comments. Changes since v2: - Rename i_dirty_start/end to i_dirty_start_page/end_page. - Use jbd2_jinode_get_dirty_range() for byte conversions in commit paths. fs/jbd2/commit.c | 55 +++++++++++++++++++++++++++++++++---------- fs/jbd2/journal.c | 5 ++-- fs/jbd2/transaction.c | 21 +++++++++++------ include/linux/jbd2.h | 34 ++++++++++++++++---------- 4 files changed, 80 insertions(+), 35 deletions(-) diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 7203d2d2624d7..8cf61e7185c44 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c @@ -180,7 +180,13 @@ static int journal_wait_on_commit_record(journal_t *jo= urnal, /* Send all the data buffers related to an inode */ int jbd2_submit_inode_data(journal_t *journal, struct jbd2_inode *jinode) { - if (!jinode || !(jinode->i_flags & JI_WRITE_DATA)) + unsigned long flags; + + if (!jinode) + return 0; + + flags =3D READ_ONCE(jinode->i_flags); + if (!(flags & JI_WRITE_DATA)) return 0; =20 trace_jbd2_submit_inode_data(jinode->i_vfs_inode); @@ -191,12 +197,30 @@ EXPORT_SYMBOL(jbd2_submit_inode_data); =20 int jbd2_wait_inode_data(journal_t *journal, struct jbd2_inode *jinode) { - if (!jinode || !(jinode->i_flags & JI_WAIT_DATA) || - !jinode->i_vfs_inode || !jinode->i_vfs_inode->i_mapping) + struct address_space *mapping; + struct inode *inode; + unsigned long flags; + loff_t start_byte, end_byte; + + if (!jinode) + return 0; + + flags =3D READ_ONCE(jinode->i_flags); + if (!(flags & JI_WAIT_DATA)) + return 0; + + inode =3D jinode->i_vfs_inode; + if (!inode) + return 0; + + mapping =3D inode->i_mapping; + if (!mapping) + return 0; + + if (!jbd2_jinode_get_dirty_range(jinode, &start_byte, &end_byte)) return 0; return filemap_fdatawait_range_keep_errors( - jinode->i_vfs_inode->i_mapping, jinode->i_dirty_start, - jinode->i_dirty_end); + mapping, start_byte, end_byte); } EXPORT_SYMBOL(jbd2_wait_inode_data); =20 @@ -218,7 +242,8 @@ static int journal_submit_data_buffers(journal_t *journ= al, list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) { if (!(jinode->i_flags & JI_WRITE_DATA)) continue; - jinode->i_flags |=3D JI_COMMIT_RUNNING; + WRITE_ONCE(jinode->i_flags, + jinode->i_flags | JI_COMMIT_RUNNING); spin_unlock(&journal->j_list_lock); /* submit the inode data buffers. */ trace_jbd2_submit_inode_data(jinode->i_vfs_inode); @@ -229,7 +254,8 @@ static int journal_submit_data_buffers(journal_t *journ= al, } spin_lock(&journal->j_list_lock); J_ASSERT(jinode->i_transaction =3D=3D commit_transaction); - jinode->i_flags &=3D ~JI_COMMIT_RUNNING; + WRITE_ONCE(jinode->i_flags, + jinode->i_flags & ~JI_COMMIT_RUNNING); smp_mb(); wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING); } @@ -240,10 +266,13 @@ static int journal_submit_data_buffers(journal_t *jou= rnal, int jbd2_journal_finish_inode_data_buffers(struct jbd2_inode *jinode) { struct address_space *mapping =3D jinode->i_vfs_inode->i_mapping; + loff_t start_byte, end_byte; + + if (!jbd2_jinode_get_dirty_range(jinode, &start_byte, &end_byte)) + return 0; =20 return filemap_fdatawait_range_keep_errors(mapping, - jinode->i_dirty_start, - jinode->i_dirty_end); + start_byte, end_byte); } =20 /* @@ -262,7 +291,7 @@ static int journal_finish_inode_data_buffers(journal_t = *journal, list_for_each_entry(jinode, &commit_transaction->t_inode_list, i_list) { if (!(jinode->i_flags & JI_WAIT_DATA)) continue; - jinode->i_flags |=3D JI_COMMIT_RUNNING; + WRITE_ONCE(jinode->i_flags, jinode->i_flags | JI_COMMIT_RUNNING); spin_unlock(&journal->j_list_lock); /* wait for the inode data buffers writeout. */ if (journal->j_finish_inode_data_buffers) { @@ -272,7 +301,7 @@ static int journal_finish_inode_data_buffers(journal_t = *journal, } cond_resched(); spin_lock(&journal->j_list_lock); - jinode->i_flags &=3D ~JI_COMMIT_RUNNING; + WRITE_ONCE(jinode->i_flags, jinode->i_flags & ~JI_COMMIT_RUNNING); smp_mb(); wake_up_bit(&jinode->i_flags, __JI_COMMIT_RUNNING); } @@ -288,8 +317,8 @@ static int journal_finish_inode_data_buffers(journal_t = *journal, &jinode->i_transaction->t_inode_list); } else { jinode->i_transaction =3D NULL; - jinode->i_dirty_start =3D 0; - jinode->i_dirty_end =3D 0; + WRITE_ONCE(jinode->i_dirty_start_page, 0); + WRITE_ONCE(jinode->i_dirty_end_page, 0); } } spin_unlock(&journal->j_list_lock); diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index c973162d5b316..0bf09aa900277 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -3020,8 +3020,8 @@ void jbd2_journal_init_jbd_inode(struct jbd2_inode *j= inode, struct inode *inode) jinode->i_next_transaction =3D NULL; jinode->i_vfs_inode =3D inode; jinode->i_flags =3D 0; - jinode->i_dirty_start =3D 0; - jinode->i_dirty_end =3D 0; + jinode->i_dirty_start_page =3D 0; + jinode->i_dirty_end_page =3D 0; INIT_LIST_HEAD(&jinode->i_list); } =20 @@ -3178,4 +3178,3 @@ MODULE_DESCRIPTION("Generic filesystem journal-writin= g module"); MODULE_LICENSE("GPL"); module_init(journal_init); module_exit(journal_exit); - diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index dca4b5d8aaaa3..17709ecdd22c0 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -2646,6 +2646,7 @@ static int jbd2_journal_file_inode(handle_t *handle, = struct jbd2_inode *jinode, { transaction_t *transaction =3D handle->h_transaction; journal_t *journal; + pgoff_t start_page, end_page; =20 if (is_handle_aborted(handle)) return -EROFS; @@ -2654,15 +2655,21 @@ static int jbd2_journal_file_inode(handle_t *handle= , struct jbd2_inode *jinode, jbd2_debug(4, "Adding inode %lu, tid:%d\n", jinode->i_vfs_inode->i_ino, transaction->t_tid); =20 + start_page =3D (pgoff_t)(start_byte >> PAGE_SHIFT); + end_page =3D (pgoff_t)(end_byte >> PAGE_SHIFT) + 1; + spin_lock(&journal->j_list_lock); - jinode->i_flags |=3D flags; + WRITE_ONCE(jinode->i_flags, jinode->i_flags | flags); =20 - if (jinode->i_dirty_end) { - jinode->i_dirty_start =3D min(jinode->i_dirty_start, start_byte); - jinode->i_dirty_end =3D max(jinode->i_dirty_end, end_byte); + if (jinode->i_dirty_start_page !=3D jinode->i_dirty_end_page) { + WRITE_ONCE(jinode->i_dirty_start_page, + min(jinode->i_dirty_start_page, start_page)); + WRITE_ONCE(jinode->i_dirty_end_page, + max(jinode->i_dirty_end_page, end_page)); } else { - jinode->i_dirty_start =3D start_byte; - jinode->i_dirty_end =3D end_byte; + /* Publish a new non-empty range by making end visible first. */ + WRITE_ONCE(jinode->i_dirty_end_page, end_page); + WRITE_ONCE(jinode->i_dirty_start_page, start_page); } =20 /* Is inode already attached where we need it? */ @@ -2739,7 +2746,7 @@ int jbd2_journal_begin_ordered_truncate(journal_t *jo= urnal, int ret =3D 0; =20 /* This is a quick check to avoid locking if not necessary */ - if (!jinode->i_transaction) + if (!READ_ONCE(jinode->i_transaction)) goto out; /* Locks are here just to force reading of recent values, it is * enough that the transaction was not committing before we started diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 64392baf5f4b4..7e785aa6d35d6 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -429,33 +429,43 @@ struct jbd2_inode { unsigned long i_flags; =20 /** - * @i_dirty_start: + * @i_dirty_start_page: + * + * Dirty range start in PAGE_SIZE units. + * + * The dirty range is empty if @i_dirty_start_page is greater than or + * equal to @i_dirty_end_page. * - * Offset in bytes where the dirty range for this inode starts. * [j_list_lock] */ - loff_t i_dirty_start; + pgoff_t i_dirty_start_page; =20 /** - * @i_dirty_end: + * @i_dirty_end_page: + * + * Dirty range end in PAGE_SIZE units (exclusive). * - * Inclusive offset in bytes where the dirty range for this inode - * ends. [j_list_lock] + * [j_list_lock] */ - loff_t i_dirty_end; + pgoff_t i_dirty_end_page; }; =20 +/* + * Lockless readers treat start_page >=3D end_page as an empty range. + * Writers publish a new non-empty range by storing i_dirty_end_page before + * i_dirty_start_page. + */ static inline bool jbd2_jinode_get_dirty_range(const struct jbd2_inode *ji= node, loff_t *start, loff_t *end) { - loff_t start_byte =3D jinode->i_dirty_start; - loff_t end_byte =3D jinode->i_dirty_end; + pgoff_t start_page =3D READ_ONCE(jinode->i_dirty_start_page); + pgoff_t end_page =3D READ_ONCE(jinode->i_dirty_end_page); =20 - if (!end_byte) + if (start_page >=3D end_page) return false; =20 - *start =3D start_byte; - *end =3D end_byte; + *start =3D (loff_t)start_page << PAGE_SHIFT; + *end =3D ((loff_t)end_page << PAGE_SHIFT) - 1; return true; } =20 --=20 2.53.0