Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3708473rwr; Sun, 7 May 2023 18:24:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7t+1zHm39aPQXkgemg7UWAj0D8G9BUxbkuDDiHs4WdSqCB/Z9KQntMaL6oGDtWzE/ypMDj X-Received: by 2002:a17:90a:514a:b0:23b:d506:226e with SMTP id k10-20020a17090a514a00b0023bd506226emr9438094pjm.42.1683509057588; Sun, 07 May 2023 18:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683509057; cv=none; d=google.com; s=arc-20160816; b=geqvbs7Ir7P6DLndgukuJCQRsVHrVGR5wBwqHJXZWLhgQhH9vvrDyx2+Q4YiIO7Mv2 4KDOrVa2NGyPO2Mi4/BRrWXStDTIK3JbRoDjEjXxQbYA99oGAJqpHbM9FrTo2OD7oy52 gBhQ+ZhwFruNVIPAYIb/krH4kW9ps5LSfasNckJBNA/i4Om60vJr3yYf5DC3NjsL95fK s9AWe/yF1QamnPCsgOFyxA8o8N1OUptNCakL8EiTadFYctmOx+ZnHcpEXj1dsiGj7MF0 4c0+18mJM1KbOTdypeMTZc1RpsX7Szw8Rlhu3BYkavA9VMmIqBfYbmaCXlkquX8M+sCY v3nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EsvFyZdxKR9Xo2oUHLItivX9RP06VANJ3BHs/qzrgb8=; b=p3iU46RSJrT5R/seZh/VZua16ps9Zdisw5VmUtLUrn5GpGYzX+DtRZ9xGW7CxHrTJC zyPPLxDuIQ1Hm1JpWZ0KZ0RNRhw2IxbslUJaAcULGcmXS4yczAldCG6+0Zu4XfyYFy9/ 5qIwXnKY1lcD2WAMzZhpyuq1FW2fFki+E2Rw/FALRIOLDgd4rm/OOyHqHEO0V8OxSE5S ZZ80fl0WEhL6QOkk2bmYs12VQujNeTXbN3gudXInXUvUdd226MUaP5PN1RzQMEqD3dez AOXphl2InSuWHhf+rfrBPUIdM8kam96Ch8IW/0WQZM3yStv+JSTCRMbHc/BM9zTCYIvb Lzlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=NtUMcEp2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a21-20020a63e855000000b00507249cdbb4si7368469pgk.296.2023.05.07.18.24.02; Sun, 07 May 2023 18:24:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=NtUMcEp2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232455AbjEHBTp (ORCPT + 99 others); Sun, 7 May 2023 21:19:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232442AbjEHBTl (ORCPT ); Sun, 7 May 2023 21:19:41 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0079120BC; Sun, 7 May 2023 18:19:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=EsvFyZdxKR9Xo2oUHLItivX9RP06VANJ3BHs/qzrgb8=; b=NtUMcEp2/YdBVpX/d7jO0SgEsc JY+bficTtXU0MiAkClFvxXTn1N3z4sKyVhGFd8KWbwfbGDTT7SmBZI61a1xuJuZqtMsJ5h6QMXGv0 AEgWEFOFfAV6Hp9L0Ead0gG+eyH/YOElBM5q00Ufhb4tcxiYaIjuwi+PmxHs2CbcbIPAO/2iMjiG/ cGPC8od2t7HSuhQGXLey4F5JnRqXYVUselIg/VW+jxIYeg+nR+8MoKVNfOXkF47vOrLKwaxZzjNCj 6jiGtCIukSBekGHbw4Mluj26qO48ty3HroFFQp7pLE1WKBUW3pyJYapuAOpjpgWfbmlzHfMdhnzwZ gUxYPydw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pvpXE-00Gw8b-1Y; Mon, 08 May 2023 01:19:28 +0000 From: Luis Chamberlain To: hch@infradead.org, djwong@kernel.org, sandeen@sandeen.net, song@kernel.org, rafael@kernel.org, gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk, jack@suse.cz, jikos@kernel.org, bvanassche@acm.org, ebiederm@xmission.com Cc: mchehab@kernel.org, keescook@chromium.org, p.raghav@samsung.com, da.gomez@samsung.com, linux-fsdevel@vger.kernel.org, kernel@tuxforce.de, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [PATCH 2/3] btrfs: replace kthread freezing with auto fs freezing Date: Sun, 7 May 2023 18:19:26 -0700 Message-Id: <20230508011927.4036707-3-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230508011927.4036707-1-mcgrof@kernel.org> References: <20230508011927.4036707-1-mcgrof@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Luis Chamberlain X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The kernel power management now supports allowing the VFS to handle filesystem freezing freezes and thawing. Take advantage of that and remove the kthread freezing. This is needed so that we properly really stop IO in flight without races after userspace has been frozen. Without this we rely on kthread freezing and its semantics are loose and error prone. The filesystem therefore is in charge of properly dealing with quiescing of the filesystem through its callbacks if it thinks it knows better than how the VFS handles it. The following Coccinelle rule was used as to remove the now superfluous freezer calls: make coccicheck MODE=patch SPFLAGS="--in-place --no-show-diff" COCCI=./fs-freeze-cleanup.cocci M=fs/btrfs virtual patch @ remove_set_freezable @ expression time; statement S, S2; expression task, current; @@ ( - set_freezable(); | - if (try_to_freeze()) - continue; | - try_to_freeze(); | - freezable_schedule(); + schedule(); | - freezable_schedule_timeout(time); + schedule_timeout(time); | - if (freezing(task)) { S } | - if (freezing(task)) { S } - else { S2 } | - freezing(current) ) @ remove_wq_freezable @ expression WQ_E, WQ_ARG1, WQ_ARG2, WQ_ARG3, WQ_ARG4; identifier fs_wq_fn; @@ ( WQ_E = alloc_workqueue(WQ_ARG1, - WQ_ARG2 | WQ_FREEZABLE, + WQ_ARG2, ...); | WQ_E = alloc_workqueue(WQ_ARG1, - WQ_ARG2 | WQ_FREEZABLE | WQ_ARG3, + WQ_ARG2 | WQ_ARG3, ...); | WQ_E = alloc_workqueue(WQ_ARG1, - WQ_ARG2 | WQ_ARG3 | WQ_FREEZABLE, + WQ_ARG2 | WQ_ARG3, ...); | WQ_E = alloc_workqueue(WQ_ARG1, - WQ_ARG2 | WQ_ARG3 | WQ_FREEZABLE | WQ_ARG4, + WQ_ARG2 | WQ_ARG3 | WQ_ARG4, ...); | WQ_E = - WQ_ARG1 | WQ_FREEZABLE + WQ_ARG1 | WQ_E = - WQ_ARG1 | WQ_FREEZABLE | WQ_ARG3 + WQ_ARG1 | WQ_ARG3 | fs_wq_fn( - WQ_FREEZABLE | WQ_ARG2 | WQ_ARG3 + WQ_ARG2 | WQ_ARG3 ) | fs_wq_fn( - WQ_FREEZABLE | WQ_ARG2 + WQ_ARG2 ) | fs_wq_fn( - WQ_FREEZABLE + 0 ) ) @ add_auto_flag @ expression E1; identifier fs_type; @@ struct file_system_type fs_type = { .fs_flags = E1 + | FS_AUTOFREEZE , }; Generated-by: Coccinelle SmPL Signed-off-by: Luis Chamberlain --- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/scrub.c | 2 +- fs/btrfs/super.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 59ea049fe7ee..6552ade25ef2 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2176,7 +2176,7 @@ static void btrfs_init_qgroup(struct btrfs_fs_info *fs_info) static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info) { u32 max_active = fs_info->thread_pool_size; - unsigned int flags = WQ_MEM_RECLAIM | WQ_FREEZABLE | WQ_UNBOUND; + unsigned int flags = WQ_MEM_RECLAIM | WQ_UNBOUND; fs_info->workers = btrfs_alloc_workqueue(fs_info, "worker", flags, max_active, 16); @@ -2217,7 +2217,7 @@ static int btrfs_init_workqueues(struct btrfs_fs_info *fs_info) fs_info->qgroup_rescan_workers = btrfs_alloc_workqueue(fs_info, "qgroup-rescan", flags, 1, 0); fs_info->discard_ctl.discard_workers = - alloc_workqueue("btrfs_discard", WQ_UNBOUND | WQ_FREEZABLE, 1); + alloc_workqueue("btrfs_discard", WQ_UNBOUND, 1); if (!(fs_info->workers && fs_info->hipri_workers && fs_info->delalloc_workers && fs_info->flush_workers && diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 836725a19661..55b82a55de19 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -2727,7 +2727,7 @@ static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info, { struct workqueue_struct *scrub_workers = NULL; struct workqueue_struct *scrub_wr_comp = NULL; - unsigned int flags = WQ_FREEZABLE | WQ_UNBOUND; + unsigned int flags = WQ_UNBOUND; int max_active = fs_info->thread_pool_size; int ret = -ENOMEM; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 0f2f915e42b0..2c08c2a37b8b 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2145,7 +2145,7 @@ static struct file_system_type btrfs_fs_type = { .name = "btrfs", .mount = btrfs_mount, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_AUTOFREEZE, }; static struct file_system_type btrfs_root_fs_type = { @@ -2153,7 +2153,7 @@ static struct file_system_type btrfs_root_fs_type = { .name = "btrfs", .mount = btrfs_mount_root, .kill_sb = btrfs_kill_super, - .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_BINARY_MOUNTDATA | FS_ALLOW_IDMAP | FS_AUTOFREEZE, }; MODULE_ALIAS_FS("btrfs"); -- 2.39.2