From patchwork Sat Dec 16 01:09:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ye Bin X-Patchwork-Id: 179726 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9682278dys; Fri, 15 Dec 2023 17:06:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPLt9L5jvuKG6s3EUdXaSfffjWIeIpqlgzYo/TOqsnbKiH4Y+nI1XJGRU2fP1Smj5Nz8A6 X-Received: by 2002:a05:620a:13e6:b0:77f:99be:897b with SMTP id h6-20020a05620a13e600b0077f99be897bmr5487449qkl.152.1702688772662; Fri, 15 Dec 2023 17:06:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702688772; cv=none; d=google.com; s=arc-20160816; b=eVQeivdlvqqv17oRkxuXDqG/fmHX4lAMa/xNtgOaJpLpcxnDzh8liT3rAmffpaRYLO vn4mZ+1bEVfcJ3ZWbuJEOz47VGskkDQXqus6YA69D533xvC+DC7JhJhiVODkQ9aqRqRS XkFNp4/EDYkpzivIzhVmZ3mJCfS/KIDJoYf7g5V1a4LAhfW5HdIGw41eKicAvR8kwwLN TPckRMm3QmhxENL9zLO34GN4KHIS+iqDpgh+e0gmfn76Hrs+PTD8vvpiJqPUuAI6yLB2 Sh/XvlXJdFmOMGkZhOdgwHb77uTlp9muq+gJnZF83MopgBx4mzPMUX0t9T8Qvr/hoXC9 pNSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=g/pk44TzNH3ZRSNKGwsYFkbx94HAO18eb+rtzhsPBYU=; fh=0YRSAtnrSRvhtzUzSfhpD62rtNa0OOsDCBO4xMqK++A=; b=0VPNDpZeYOKEg99oA7y54bwUmKWQ1lryYuL90WVngmY2mI5zSzpf0rZPeD1FlE6vUq YrsIraAYyUl+S6arZpJfp4MVXggR5GyCqwd7z+0HWSZ9X6qg2B/rtjhg12P5G4j4+s0Y rgazecqHwwsuCs8deVQ5ZIJoT/e1BgbeEbBMsi9Ix9LCTR87Vv78APyn52d6VfDNBwYF 3FONkZICMGz2hZPlurAzmFQcdzZvbheR0EOE8vyC2UrNinuSJ8KXMLowzoYxL6fDzET7 c7LKHOZFHlDdh0mji5RCF3XNGh4XVfBt5cNqRnTsZsPEA25lSncrNzUIxoIneIwjw7jb ynJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1921-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1921-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id v2-20020a05620a440200b0077f357665d5si20135052qkp.400.2023.12.15.17.06.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 17:06:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1921-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1921-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1921-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 714BF1C23693 for ; Sat, 16 Dec 2023 01:06:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5FE1C185A; Sat, 16 Dec 2023 01:05:57 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (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 4DD1710F1; Sat, 16 Dec 2023 01:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.163]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4SsSZK5xLpz2mGxd; Sat, 16 Dec 2023 09:05:45 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id E2B7E180027; Sat, 16 Dec 2023 09:05:50 +0800 (CST) Received: from huawei.com (10.175.127.227) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Sat, 16 Dec 2023 09:05:50 +0800 From: Ye Bin To: , , CC: , , Ye Bin Subject: [PATCH v2] ext4: fix inconsistent between segment fstrim and full fstrim Date: Sat, 16 Dec 2023 09:09:19 +0800 Message-ID: <20231216010919.1995851-1-yebin10@huawei.com> X-Mailer: git-send-email 2.31.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500010.china.huawei.com (7.192.105.118) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785238597020390383 X-GMAIL-MSGID: 1785398582506025768 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 --- 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 d72b5e3c92ec..d195461123d8 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -6753,13 +6753,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; @@ -6768,7 +6770,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);