Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp7055006rdb; Fri, 15 Dec 2023 17:01:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEXlQlPcR7KVpOjiPRmPY/FnGVPNQcYwW1yVdXiUzZXPWjPL70tViA1NGUsed5di+9V4XYS X-Received: by 2002:a05:6122:3b88:b0:48f:8e3a:5b83 with SMTP id fs8-20020a0561223b8800b0048f8e3a5b83mr11167135vkb.14.1702688517664; Fri, 15 Dec 2023 17:01:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702688517; cv=none; d=google.com; s=arc-20160816; b=tZxAuz22O7aL3a5C1RQ5pW+9PVr3ayoE90RbTNT9T0ll5Jltxzjscv255VRmLKmxaG nuoBtjHRl6wTG/o4t5or4KCjO/w6MJstq38vKeGKUjPSP6484rFMRvnOZmpmoB4mH+GC FXpBz97d0ntbmNZdQJPxQw21RxeTg96NujJDm2sqQy7BOODMmKxxSm/b1JIbYgO4asPO YdBi0h3U1yoh6RVCrLXfS4SgwJFCMWhp0GrYxtOJJcOZVgZxMw9tfx/Dd/4m7Qk2N9Sm QPBp8Otfvvzt/P5kJbjlz+h6qGE/ahSDY32vPZKaO0s404a3hmmkkj+nl3N3+eeC2sRW eBOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :cc:references:to:subject; bh=IpcERUI+sHS5r901S8Yrx/g5fk/4huHhJjWRGLQMmFk=; fh=Ms06AGjSb6Dmdfil7574tCSVQ3bTZM4mbhUvLuXpSvc=; b=tFLjZ+NKiIEltj8vgzWexZ9MwQdKlKatCUNN3YOItYawTf6zt4UuQ01s0piY3Uevyx ocI7s/EjtyCc2YdZqr6Xh+tybhrjgoLuyrVFBQK2HaJARdNvptqWHE3BXif482W1SGLI idjXkz0cnHWuYPD+wAOfw9aacSG702hJH1jeKH4eKgHNQ9VrFPGNo1rNLjOFqe49Akln j21DNcmL9imZfwk1G7wrRzWJW1rag2hxiywyrZ3xs6dKJ3hxaE7GUG4M6ZBaitcdYfuE 0GrA9U6XdKxx3MScYZFUyswz/aqCwf4BxjwB5ifdQWu0r7k+adIWXmI8jlsWTOxr1CKx zm3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-474-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id k2-20020a1fec02000000b004b2895bbb84si2695223vkh.267.2023.12.15.17.01.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 17:01:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-474-linux.lists.archive=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 635311C235B2 for ; Sat, 16 Dec 2023 01:01:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3EDA718AE6; Sat, 16 Dec 2023 01:01:40 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (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 26A8615493; Sat, 16 Dec 2023 01:01:34 +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.162.112]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4SsSPC4pnBz1FDwq; Sat, 16 Dec 2023 08:57:51 +0800 (CST) Received: from canpemm500010.china.huawei.com (unknown [7.192.105.118]) by mail.maildlp.com (Postfix) with ESMTPS id A74D21402CF; Sat, 16 Dec 2023 09:01:30 +0800 (CST) Received: from [10.174.178.185] (10.174.178.185) 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:01:30 +0800 Subject: Re: [PATCH] ext4: fix inconsistent between segment fstrim and full fstrim To: Jan Kara References: <20231214064635.4128391-1-yebin10@huawei.com> <20231215114135.qwdoscxg7myw3r6x@quack3> CC: , , , From: "yebin (H)" Message-ID: <657CF6E9.602@huawei.com> Date: Sat, 16 Dec 2023 09:01:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20231215114135.qwdoscxg7myw3r6x@quack3> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500010.china.huawei.com (7.192.105.118) On 2023/12/15 19:41, Jan Kara wrote: > On Thu 14-12-23 14:46:35, Ye Bin wrote: >> There will not issue discard cmd when do segment fstrim for ext4 fs, however, >> if full fstrim for the same fs will issue discard cmd. >> Above issue may happens as follows: >> Precondition: >> 1. Fstrim range [0, 15] and [16, 31]; >> 2. Discard granularity is 16; >> Range1 Range2 >> 1111000000000000 0000111010101011 >> There's no free space length large or equal than 16 in 'Range1' or 'Range2'. >> As ext4_try_to_trim_range() only search free space among range which user >> specified. However, there's maximum free space length 16 in 'Range1'+ 'Range2'. >> To solve above issue, we need to find the longest free space to discard. > The patch looks good so feel free to add: > > Reviewed-by: Jan Kara > > I'd just rephrase the changelog to make it a bit easier to read: > > 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. > > Honza > Thank you very much for your clear explanation of the patch. I'll update patch's changelog and resend a version. >> Signed-off-by: Ye Bin >> --- >> 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); >> -- >> 2.31.1 >>