From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 F27144C3AF; Sat, 3 Feb 2024 04:16:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706933780; cv=none; b=IWtMx0eyAatMcu6OoIc9Zytuxl5OllFw8pH3R7q5rhh5mye9qs11U57ZKr08nPUduNyu2OCjqGd1hOxMnU2zwRklqtkt1BWjOnjn33TfNJtMyFfao/PTnzryfVwtRcukzDcfA4dkyqeyMwRCMF8GAH2C6BP/CO1KUGjj2duRj9Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706933780; c=relaxed/simple; bh=mgmVB2ub7Q4L0qc1oGRtxYe2zRtVycHCnFVNSGj8Lvk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uKsTTLn4oVbtfhrdDcVJVC33EDjFhN0/r6CJKBtRU/L0UaFpz8NDCTI1JNpuAuugbD8ronkWnCUUbtsulOlPNo5Ydz+DgHKcnOB9xTNEHHcmw9R5jD6MDzW3hQXM37XSiP31sSn6QJTHmQa0rhKTLX6f8MNaEckBsuTh9jKqocw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ia/XWiqW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ia/XWiqW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC916C433F1; Sat, 3 Feb 2024 04:16:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1706933779; bh=mgmVB2ub7Q4L0qc1oGRtxYe2zRtVycHCnFVNSGj8Lvk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ia/XWiqWtseocnTGq2IJbmRTnaNBO9HjzpwKPcZOQs0qqzBfDUvsNt1vno3Y4BlPl 2bu+TQN/Q6jlxKaS/tOVV/Z0fpTSAHZvlhNnF5x37FUIBXQQcfZnnvO69CSdBaGOzx C/FK6hG0VwFMFANYle9giyeJe3bI7TywqbxWn100= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Ye Bin , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 6.7 059/353] ext4: fix inconsistent between segment fstrim and full fstrim Date: Fri, 2 Feb 2024 20:02:57 -0800 Message-ID: <20240203035405.670795689@linuxfoundation.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240203035403.657508530@linuxfoundation.org> References: <20240203035403.657508530@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.7-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ye Bin [ Upstream commit 68da4c44b994aea797eb9821acb3a4a36015293e ] Suppose we issue two FITRIM ioctls for ranges [0,15] and [16,31] with mininum length of trimmed range set to 8 blocks. If we have say a range of blocks 10-22 free, this range will not be trimmed because it straddles the boundary of the two FITRIM ranges and neither part is big enough. This is a bit surprising to some users that call FITRIM on smaller ranges of blocks to limit impact on the system. Also XFS trims all free space extents that overlap with the specified range so we are inconsistent among filesystems. Let's change ext4_try_to_trim_range() to consider for trimming the whole free space extent that straddles the end of specified range, not just the part of it within the range. Signed-off-by: Ye Bin Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20231216010919.1995851-1-yebin10@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/mballoc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index ab023d709f72..8408318e1d32 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -6758,13 +6758,15 @@ static int ext4_try_to_trim_range(struct super_block *sb, __acquires(ext4_group_lock_ptr(sb, e4b->bd_group)) __releases(ext4_group_lock_ptr(sb, e4b->bd_group)) { - ext4_grpblk_t next, count, free_count; + ext4_grpblk_t next, count, free_count, last, origin_start; bool set_trimmed = false; void *bitmap; + last = ext4_last_grp_cluster(sb, e4b->bd_group); bitmap = e4b->bd_bitmap; - if (start == 0 && max >= ext4_last_grp_cluster(sb, e4b->bd_group)) + if (start == 0 && max >= last) set_trimmed = true; + origin_start = start; start = max(e4b->bd_info->bb_first_free, start); count = 0; free_count = 0; @@ -6773,7 +6775,10 @@ __releases(ext4_group_lock_ptr(sb, e4b->bd_group)) start = mb_find_next_zero_bit(bitmap, max + 1, start); if (start > max) break; - next = mb_find_next_bit(bitmap, max + 1, start); + + next = mb_find_next_bit(bitmap, last + 1, start); + if (origin_start == 0 && next >= last) + set_trimmed = true; if ((next - start) >= minblocks) { int ret = ext4_trim_extent(sb, start, next - start, e4b); -- 2.43.0