From patchwork Tue Apr 1 00:32:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 14034236 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 1EBE215D5B6; Tue, 1 Apr 2025 00:33:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743467615; cv=none; b=sm/CuhECPyJNJqH7VpN6hcONDib7b5cXgCpfVCzcBrt4pz9Gx9fXFFHk4c6Hdm0hqGSF0dh7Yl33m+gWrndws9srfGG8cswGNXPa1csEN4CG+tb4bdgVwu+bem3lJpMo5AlzvSLsO91GF2pHhX4EY8nsFM8g+jrR7DPRrI4FNFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743467615; c=relaxed/simple; bh=lCY/KJW9ikBmlJ/oV/9jDJ7hT8RIfBH0XkGe2K3kJYw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aKPlxz5UZkt7YxDrLL40f6YGRiyYTpYyA5peP7XVCVR4qnW84abl38X9FOogFOB40dV6ts82JmLtw1c/Z3wn6shWzrl9K9P0pc2n+MRokDK3u0+C/s1LWCbOlTO6SJ61wKSpRUKYyekT++4NWs+dZLWSz/IKNOaKH1TDvxAcZ5U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IoCzgbjj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IoCzgbjj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6BB4C4CEEE; Tue, 1 Apr 2025 00:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743467614; bh=lCY/KJW9ikBmlJ/oV/9jDJ7hT8RIfBH0XkGe2K3kJYw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IoCzgbjjADfRLGcBq8tQxtzAh+nw9hJTYSo1OFfKB4zT7VsZ7m8xZ2SiorMmHZThc SLmeaXTjuyKa1TdRxX35IRjX15UZpeG9HVUtBU/xcfre0Gv9Wc1aPzr7rUs5buzYo9 0DuBgxVLKBK0iGDuHdHmtQVjetfr13yVEE2W/AJQm3lsEde5QtUb+ikWQ3HEf81dI5 zgtHLR6kRTNFpPKx2TMwnBMylSN2ArPzKVmLmOeNJp0UTn5cSuYKlsWeYOHIzjj1wf TxxXXEXIuCijpGfnm618zzUfdtioMA5rzPNGgL+qXH74cMfcHJaq1MGqSKPOsiArlb I/1kqtF+NJ5/A== From: Christian Brauner To: linux-fsdevel@vger.kernel.org, jack@suse.cz Cc: Christian Brauner , Ard Biesheuvel , linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, James Bottomley , mcgrof@kernel.org, hch@infradead.org, david@fromorbit.com, rafael@kernel.org, djwong@kernel.org, pavel@kernel.org, peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun.feng@gmail.com Subject: [PATCH 2/6] btrfs: replace kthread freezing with auto fs freezing Date: Tue, 1 Apr 2025 02:32:47 +0200 Message-ID: <20250401-work-freeze-v1-2-d000611d4ab0@kernel.org> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250401-work-freeze-v1-0-d000611d4ab0@kernel.org> References: <20250401-work-freeze-v1-0-d000611d4ab0@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-42535 X-Developer-Signature: v=1; a=openpgp-sha256; l=4192; i=brauner@kernel.org; h=from:subject:message-id; bh=d3lub6zszyAvvsjIX6sIGC+CVKRgSmI0RRk0r2As0ac=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaS/NrGZYPf7dvHUt8sULp+RD/Yp9+Y7vj/isdrjz+orO /luMnArdpSyMIhxMciKKbI4tJuEyy3nqdhslKkBM4eVCWQIAxenAEyk6TjDH87C7t13p9/JMjb6 y+32xnrnzAVls7eukwkx/Oq2olGgdSFQRUqbf0d048Kv7FZ2vUrJh6TrdKceNeHRYF+aYHPB/ws HAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 From: Luis Chamberlain 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 Link: https://lore.kernel.org/r/20250326112220.1988619-6-mcgrof@kernel.org Signed-off-by: Christian Brauner --- fs/btrfs/disk-io.c | 4 ++-- fs/btrfs/scrub.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 1a916716cefe..bce3ae569fe0 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1962,8 +1962,8 @@ 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 ordered_flags = WQ_MEM_RECLAIM | WQ_FREEZABLE; + unsigned int flags = WQ_MEM_RECLAIM | WQ_UNBOUND; + unsigned int ordered_flags = WQ_MEM_RECLAIM; fs_info->workers = btrfs_alloc_workqueue(fs_info, "worker", flags, max_active, 16); diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 2c5edcee9450..5790177b4c2f 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -2877,7 +2877,7 @@ static void scrub_workers_put(struct btrfs_fs_info *fs_info) static noinline_for_stack int scrub_workers_get(struct btrfs_fs_info *fs_info) { struct workqueue_struct *scrub_workers = NULL; - unsigned int flags = WQ_FREEZABLE | WQ_UNBOUND; + unsigned int flags = WQ_UNBOUND; int max_active = fs_info->thread_pool_size; int ret = -ENOMEM;