linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext4: fix marking group trimmed if all blocks not trimmed
@ 2020-08-03 16:17 Lazar Beloica
  2020-08-07 22:01 ` tytso
  0 siblings, 1 reply; 2+ messages in thread
From: Lazar Beloica @ 2020-08-03 16:17 UTC (permalink / raw)
  To: linux-ext4
  Cc: stable, lazarbeloica, lazar.beloica, boyu.mt, adilger.kernel,
	linux-kernel

When FTRIM is issued on a group, ext4 marks it as trimmed so another FTRIM
on the same group has no effect. Ext4 marks group as trimmed if at least
one block is trimmed, therefore it is possible that a group is marked as
trimmed even if there are blocks in that group left untrimmed.

This patch marks group as trimmed only if there are no more blocks
in that group to be trimmed.

Fixes: 3d56b8d2c74cc3f375ce332b3ac3519e009d79ee
Tested-by: Lazar Beloica <lazar.beloica@nutanix.com>
Signed-off-by: Lazar Beloica <lazar.beloica@nutanix.com>
---
 fs/ext4/mballoc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index c0a331e..130936b 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -5346,6 +5346,7 @@ static int ext4_trim_extent(struct super_block *sb, int start, int count,
 {
 	void *bitmap;
 	ext4_grpblk_t next, count = 0, free_count = 0;
+	ext4_fsblk_t max_blks = ext4_blocks_count(EXT4_SB(sb)->s_es);
 	struct ext4_buddy e4b;
 	int ret = 0;
 
@@ -5401,7 +5402,9 @@ static int ext4_trim_extent(struct super_block *sb, int start, int count,
 
 	if (!ret) {
 		ret = count;
-		EXT4_MB_GRP_SET_TRIMMED(e4b.bd_info);
+		next = mb_find_next_bit(bitmap, max_blks, max + 1);
+		if (next == max_blks)
+			EXT4_MB_GRP_SET_TRIMMED(e4b.bd_info);
 	}
 out:
 	ext4_unlock_group(sb, group);
-- 
1.8.3.1


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

end of thread, other threads:[~2020-08-07 22:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-03 16:17 [PATCH] ext4: fix marking group trimmed if all blocks not trimmed Lazar Beloica
2020-08-07 22:01 ` tytso

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