linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] resize2fs: fix over-pessimistic heuristic.
@ 2014-04-06 12:56 Dmitry Monakhov
  2014-04-11  3:39 ` Theodore Ts'o
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Monakhov @ 2014-04-06 12:56 UTC (permalink / raw)
  To: linux-ext4; +Cc: tytso, Dmitry Monakhov

In worst case we need one extent per moved block. Number of blocks to
be moved is less or equals to blks_needed.

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 resize/resize2fs.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index f5f1337..8ca53a3 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -2587,11 +2587,17 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags)
 	/*
 	 * We need to reserve a few extra blocks if extents are
 	 * enabled, in case we need to grow the extent tree.  The more
-	 * we shrink the file system, the more space we need.
+	 * we shrink the file system, the more blocks will be moved.
+	 * Worse case is one extent per moved block.
 	 */
 	if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) {
-		blk64_t safe_margin = (ext2fs_blocks_count(fs->super) -
-				       blks_needed)/500;
+		blk64_t safe_margin = ext2fs_blocks_count(fs->super)
+			- blks_needed;
+
+		if (safe_margin > blks_needed)
+			safe_margin = blks_needed;
+		safe_margin /= 500;
+
 #ifdef RESIZE2FS_DEBUG
 		if (flags & RESIZE_DEBUG_MIN_CALC)
 			printf("Extents safety margin: %llu\n", safe_margin);
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-11  8:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-06 12:56 [PATCH] resize2fs: fix over-pessimistic heuristic Dmitry Monakhov
2014-04-11  3:39 ` Theodore Ts'o
2014-04-11  8:05   ` Dmitry Monakhov

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).