linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Whitney <enwlinux@gmail.com>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, Eric Whitney <enwlinux@gmail.com>
Subject: [PATCH 3/6] ext4: rework partial cluster handling to use lblk more consistently
Date: Tue, 12 Sep 2023 22:11:45 -0400	[thread overview]
Message-ID: <20230913021148.1181646-4-enwlinux@gmail.com> (raw)
In-Reply-To: <20230913021148.1181646-1-enwlinux@gmail.com>

Working in the logical block space where possible when manipulating
partial clusters makes the code easier to understand.  It also offers
the opportunity for efficiency improvements, both in this patch and
those that follow.

Signed-off-by: Eric Whitney <enwlinux@gmail.com>
---
 fs/ext4/extents.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index 0c52218fb171..793a9437be9f 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -2505,7 +2505,7 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
 	 */
 	last_pblk = ext4_ext_pblock(ex) + ee_len - 1;
 	if (partial->state != none &&
-	    partial->pclu != EXT4_B2C(sbi, last_pblk)) {
+		EXT4_B2C(sbi, partial->lblk) != EXT4_B2C(sbi, to)) {
 		if (partial->state == free)
 			free_partial_cluster(handle, inode, partial);
 		partial->state = none;
@@ -2547,7 +2547,8 @@ static int ext4_remove_blocks(handle_t *handle, struct inode *inode,
 	ext4_free_blocks(handle, inode, NULL, pblk, num, flags);
 
 	/* reset the partial cluster if we've freed past it */
-	if (partial->state != none && partial->pclu != EXT4_B2C(sbi, pblk))
+	if (partial->state != none &&
+	    EXT4_B2C(sbi, partial->lblk) != EXT4_B2C(sbi, from))
 		partial->state = none;
 
 	/*
@@ -2597,11 +2598,10 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
 	struct ext4_extent_header *eh;
 	ext4_lblk_t a, b;
 	unsigned num;
-	ext4_lblk_t ex_ee_block;
+	ext4_lblk_t ex_ee_block, lblk;
 	unsigned short ex_ee_len;
 	unsigned unwritten = 0;
 	struct ext4_extent *ex;
-	ext4_fsblk_t pblk;
 
 	/* the header must be checked already in ext4_ext_remove_space() */
 	ext_debug(inode, "truncate since %u in leaf to %u\n", start, end);
@@ -2649,8 +2649,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
 			 * be just to the left.
 			 */
 			if (sbi->s_cluster_ratio > 1) {
-				pblk = ext4_ext_pblock(ex);
-				partial->pclu = EXT4_B2C(sbi, pblk);
+				partial->lblk = ex_ee_block;
 				partial->state = keep;
 			}
 			ex--;
@@ -2767,8 +2766,8 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode,
 	 * to be removed but might be shared with the partial cluster.
 	 */
 	if (partial->state == free && ex >= EXT_FIRST_EXTENT(eh)) {
-		pblk = ext4_ext_pblock(ex) + ex_ee_len - 1;
-		if (partial->pclu != EXT4_B2C(sbi, pblk))
+		lblk = ex_ee_block + ex_ee_len - 1;
+		if (EXT4_B2C(sbi, partial->lblk) != EXT4_B2C(sbi, lblk))
 			free_partial_cluster(handle, inode, partial);
 		partial->state = none;
 	}
@@ -2878,8 +2877,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
 			 * in use to avoid freeing it when removing blocks.
 			 */
 			if (sbi->s_cluster_ratio > 1) {
-				pblk = ext4_ext_pblock(ex) + end - ee_block + 1;
-				partial.pclu = EXT4_B2C(sbi, pblk);
+				partial.lblk = end + 1;
 				partial.state = keep;
 			}
 
@@ -2912,7 +2910,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start,
 			if (err < 0)
 				goto out;
 			if (pblk) {
-				partial.pclu = EXT4_B2C(sbi, pblk);
+				partial.lblk = lblk;
 				partial.state = keep;
 			}
 		}
-- 
2.30.2


  parent reply	other threads:[~2023-09-13  2:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13  2:11 [PATCH 0/6] improve cluster and block removal code Eric Whitney
2023-09-13  2:11 ` [PATCH 1/6] ext4: consolidate code used to free clusters Eric Whitney
2023-09-13  2:11 ` [PATCH 2/6] ext4: rework partial cluster definition and related tracepoints Eric Whitney
2023-09-13  2:11 ` Eric Whitney [this message]
2023-09-13  2:11 ` [PATCH 4/6] ext4: consolidate partial cluster initialization Eric Whitney
2023-09-13  2:11 ` [PATCH 5/6] ext4: simplify and improve efficiency of cluster removal code Eric Whitney
2023-09-13  2:11 ` [PATCH 6/6] ext4: remove mballoc's NOFREE flags Eric Whitney

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=20230913021148.1181646-4-enwlinux@gmail.com \
    --to=enwlinux@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).