Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp511548pxb; Wed, 3 Nov 2021 07:53:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2X2mhxJfFRYF9A2onWX4i9IFaEZZogv6wJc07ipkl2McKfg8Au9UKuxOokPSJjj2A8Dxz X-Received: by 2002:a02:c503:: with SMTP id s3mr20886279jam.65.1635951190386; Wed, 03 Nov 2021 07:53:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635951190; cv=none; d=google.com; s=arc-20160816; b=QjprALQ7Dv6U+Efol1JoiBYoweCU2zjTwfx+JIQJN5v4EeSnB5UTmMWL4kmwURP8aS yAdkz24ezAIpRObjR3jHUToNDImJclWuUTQVc6WYU0cqfMO17f2hOBj6yoTbaM9tTyfB ZLEN7Ed+aLcWxsoNw6ElsjQ+QKiJHra5QvsuaiVGxdaVNtRwR72mgQ1D2QxeGE8Us18N EHfZ/lM5/WtUYEGEBbOEAUOrrcSHmYmj64X+pc4E6dqTkUvV8OKyQuyT/igB5nsnAU6X LhALjxAWUNKOOD8dA6ZrHCiMr/um5TdTvsp5TPe/aYVmVEzC4CsdDJK9GvGCegEV3KCV JjUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kTzGd0AKmjFHRo7fXFpfjY5blmceuKFi00MsYOAPKc0=; b=DmR3ua6OC5TptUV1V9zRvqIcB4dQN2URJBRMoFSQSSdBYLbq967urUYit4M0yOG23W 1ppjk8v2PKhHyMGKpMc/AAW5qRc/3/JPnF6uq43iEfKXOOYLSaKu1fyJ22MK2TV/g8Pf v3y7CVAOYG6ZKYODXBrkrKoK8EAkw0UgMrVDnDYuoi0ZhUHgYYz+DTQqv3vwhJjB7i2H aWAUcixcWwpjW3hslTzlljqV/HhtW/jjmUJ0G8JN+z1pNFg+nVhHQrLGLmrD1cMYoxGn LbI6BQgscyB4fZGW+h56uoYTUuwV5jucT2+Io/AcF6pP70v47GGWSqR8TzkoPk7eOXox RDtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GgQtuX52; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h24si3219505ioe.67.2021.11.03.07.52.37; Wed, 03 Nov 2021 07:53:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GgQtuX52; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbhKCOzI (ORCPT + 99 others); Wed, 3 Nov 2021 10:55:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56589 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230132AbhKCOzI (ORCPT ); Wed, 3 Nov 2021 10:55:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635951151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kTzGd0AKmjFHRo7fXFpfjY5blmceuKFi00MsYOAPKc0=; b=GgQtuX520aqol8ve0QVlaQR9WizOO/cUMrkZt9hnFdLcp0P1nknDCCwM/ufKfuE6QNdu1n lIkTU9ZPPEikjdDjmfoS+STObjqXCpuGrxFm90WGrWQzV29T+n0jMWarV/Ik4Fm74RJbeu 1cjVz0Gh8tU5UKMSgukc7sF1m7YNaPo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-462-s3WqVMe_Opi-PaffJS9v5Q-1; Wed, 03 Nov 2021 10:52:27 -0400 X-MC-Unique: s3WqVMe_Opi-PaffJS9v5Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75624A40E1; Wed, 3 Nov 2021 14:51:29 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2298C19741; Wed, 3 Nov 2021 14:51:27 +0000 (UTC) From: Lukas Czerner To: linux-ext4@vger.kernel.org, tytso@mit.edu Cc: adilger@dilger.ca, Laurent GUERBY Subject: [PATCH v3 2/2] ext4: Allow to change s_last_trim_minblks via sysfs Date: Wed, 3 Nov 2021 15:51:22 +0100 Message-Id: <20211103145122.17338-2-lczerner@redhat.com> In-Reply-To: <20211103145122.17338-1-lczerner@redhat.com> References: <20211103145122.17338-1-lczerner@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Ext4 has an optimization mechanism for batched disacrd (FITRIM) that should help speed up subsequent calls of FITRIM ioctl by skipping the groups that were previously trimmed. However because the FITRIM allows to set the minimum size of an extent to trim, ext4 stores the last minimum extent size and only avoids trimming the group if it was previously trimmed with minimum extent size equal to, or smaller than the current call. There is currently no way to bypass the optimization without umount/mount cycle. This becomes a problem when the file system is live migrated to a different storage, because the optimization will prevent possibly useful discard calls to the storage. Fix it by exporting the s_last_trim_minblks via sysfs interface which will allow us to set the minimum size to the number of blocks larger than subsequent FITRIM call, effectively bypassing the optimization. By setting the s_last_trim_minblks to ULONG_MAX the optimization will be effectively cleared regardless of the previous state, or file system configuration. For example: getconf ULONG_MAX > /sys/fs/ext4/dm-1/last_trim_minblks Signed-off-by: Lukas Czerner Reported-by: Laurent GUERBY --- v2: Remove unnecessary assignment v3: s_last_trim_minblks is now unsinged long which simplifies this fs/ext4/sysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ext4/sysfs.c b/fs/ext4/sysfs.c index 2314f7446592..95d8a996d2d8 100644 --- a/fs/ext4/sysfs.c +++ b/fs/ext4/sysfs.c @@ -245,6 +245,7 @@ EXT4_ATTR(last_error_time, 0444, last_error_time); EXT4_ATTR(journal_task, 0444, journal_task); EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch); EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit); +EXT4_RW_ATTR_SBI_UL(last_trim_minblks, s_last_trim_minblks); static unsigned int old_bump_val = 128; EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val); @@ -295,6 +296,7 @@ static struct attribute *ext4_attrs[] = { #endif ATTR_LIST(mb_prefetch), ATTR_LIST(mb_prefetch_limit), + ATTR_LIST(last_trim_minblks), NULL, }; ATTRIBUTE_GROUPS(ext4); -- 2.31.1