Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4960896rdb; Fri, 29 Dec 2023 23:09:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6cvITaCwr4f2WGvB53yOtWii8N4/lxCnQVbraAcugG0RfNtesHGONvzObrZu51FGhblya X-Received: by 2002:a50:ab50:0:b0:551:90f1:125b with SMTP id t16-20020a50ab50000000b0055190f1125bmr5615876edc.23.1703920181080; Fri, 29 Dec 2023 23:09:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703920181; cv=none; d=google.com; s=arc-20160816; b=HSywgGDIUoNztMWtR2cHLMuWwlV5NV949YnOUMe0x4xo2FgV3yv2dwXCBFc2p1OvkO VsqJbUDAMRmAt4BFVrlipo61Qrm+P72cnK93emmJpYGU1Ia+6NGv2rPplQy3kWVVniap 7NvSQlnicw//8xU/xue/UoP6IH2nZduBtXqu9vniTiKP51vtIy/LK2bvBTRp2SCb+6Yn VWM+DmK5IzzE+ZT4XG84GV6yjfvRSdJwScZKu8wJsqHGWrS3opB6xg887SHbrrokaA7A gv/kZx0C8jyoYUzShWsQZeCZ/MKTAybsNFgCjM9Zt5vh7rXqKPKOck4tgP1mO04vfMLg h2iQ== 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=jxN9moxlNQrtg9bkZEXYHO+C0d2EYwkgipWov9oA2cg=; fh=1HnvQemhvX9wrHkH/hA1icVzz5/0Ktx5VYMDm9KzffU=; b=xcdx+v5r6Boki7g4eO/Wi8vyTRd8WSk1Dm4D/8l9ohy7o21kPtRfne0AppAmh83gn0 Qu8u57XWCcrldxIvYqADgHpQm7Dyn1M2DH+HCtb13DKxLAIz+f/qjVoTc/RSudfQD61L 1RGP9Yrdr0Vjdx81jhcnVYlHf6aMjHuhSiiRKYfSTyv/Xhes2cVhfppmTwUxU6CiOCpn J8a4iAQYLazJkw3gztGj553vtlYcqBbwp+PNzkTQ+iKa2OaIedbMnT5Gw2k/zu6itq9K ail/d3L95SM4B19eIUdATfqwJeRWy1aJ7Yrv4oR//XcC1tbpL50vD2uJ/94+kNevPBLM rifg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-584-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-584-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x19-20020a05640226d300b005548f3e2ea2si6353683edd.109.2023.12.29.23.09.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Dec 2023 23:09:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-584-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-584-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-584-linux.lists.archive=gmail.com@vger.kernel.org" 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 am.mirrors.kernel.org (Postfix) with ESMTPS id CE20A1F215F1 for ; Sat, 30 Dec 2023 07:09:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0691F1FAF; Sat, 30 Dec 2023 07:09:34 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 BEF5F1843 for ; Sat, 30 Dec 2023 07:09:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4T2CzP0Ds3z4f3l12 for ; Sat, 30 Dec 2023 15:09:21 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 876981A0532 for ; Sat, 30 Dec 2023 15:09:26 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgA3iA4hwo9ln8obFA--.40130S4; Sat, 30 Dec 2023 15:09:26 +0800 (CST) From: yangerkun To: tytso@mit.edu, adilger.kernel@dilger.ca Cc: boyu.mt@taobao.com, linux-ext4@vger.kernel.org, yangerkun@huawei.com Subject: [PATCH] ext4: clear EXT4_GROUP_INFO_WAS_TRIMMED_BIT even mount with discard Date: Sat, 30 Dec 2023 15:06:54 +0800 Message-Id: <20231230070654.178638-1-yangerkun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgA3iA4hwo9ln8obFA--.40130S4 X-Coremail-Antispam: 1UD129KBjvJXoW7CFy7Jw18Zr45Xr4rKry3Arb_yoW8uw48pr ZxKr1ayw4Yqr109anrWw40qayfGw48Gw1UGrWSgr4UArWfKFySgFnFk3W5AFyjgFWxA3Wq vFs8W345CFyxu37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUgCb4IE77IF4wAFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Y z7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zV AF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4l IxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrZr1j6s 0DMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsG vfC2KfnxnUUI43ZEXa7IU1zuWJUUUUU== X-CM-SenderInfo: 51dqwvhunx0q5kxd4v5lfo033gof0z/ Commit 3d56b8d2c74c ("ext4: Speed up FITRIM by recording flags in ext4_group_info") speed up fstrim by skipping trim trimmed group. We also has the chance to clear trimmed once there exists some block free for this group(mount without discard), and the next trim for this group will work well too. For mount with discard, we will issue dicard when we free blocks, so leave trimmed flag keep alive to skip useless trim trigger from userspace seems reasonable. But for some case like ext4 build on dm-thinpool(ext4 blocksize 4K, pool blocksize 128K), discard from ext4 maybe unaligned for dm thinpool, and thinpool will just finish this discard(see process_discard_bio when begein equals to end) without actually process discard. For this case, trim from userspace can really help us to free some thinpool block. So convert to clear trimmed flag for all case no matter mounted with discard or not. Fixes: 3d56b8d2c74c ("ext4: Speed up FITRIM by recording flags in ext4_group_info") Signed-off-by: yangerkun --- fs/ext4/mballoc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index d72b5e3c92ec..69240ae775f1 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -3855,11 +3855,8 @@ static void ext4_free_data_in_buddy(struct super_block *sb, /* * Clear the trimmed flag for the group so that the next * ext4_trim_fs can trim it. - * If the volume is mounted with -o discard, online discard - * is supported and the free blocks will be trimmed online. */ - if (!test_opt(sb, DISCARD)) - EXT4_MB_GRP_CLEAR_TRIMMED(db); + EXT4_MB_GRP_CLEAR_TRIMMED(db); if (!db->bb_free_root.rb_node) { /* No more items in the per group rb tree @@ -6481,8 +6478,9 @@ static void ext4_mb_clear_bb(handle_t *handle, struct inode *inode, " group:%u block:%d count:%lu failed" " with %d", block_group, bit, count, err); - } else - EXT4_MB_GRP_CLEAR_TRIMMED(e4b.bd_info); + } + + EXT4_MB_GRP_CLEAR_TRIMMED(e4b.bd_info); ext4_lock_group(sb, block_group); mb_free_blocks(inode, &e4b, bit, count_clusters); -- 2.39.2