Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1719227rwb; Fri, 13 Jan 2023 16:58:45 -0800 (PST) X-Google-Smtp-Source: AMrXdXtwqjiAaw/EYJqsT4fib9UHRsn8XDRiLi4omF/8LpNbRKSVjdN4g0Mj/2+ayOnEP2P2xSNi X-Received: by 2002:a17:90b:24d:b0:227:248e:35ef with SMTP id fz13-20020a17090b024d00b00227248e35efmr12448449pjb.44.1673657924785; Fri, 13 Jan 2023 16:58:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673657924; cv=none; d=google.com; s=arc-20160816; b=DOM5ctsVDVWCz9DzpfIZHJWC3tT2pdp2MD7tpxUATesa9BJ63gexdf+blBN+0ONShb jCiMvJKULT8I7+V/hn3oFsiRN/yO6xDxo5OIAJjp5MxS8egvqMhMryoRCZTIxvZq/PWV p4S5VG4soaIPPOWmSrAQ1oslKHXEgQFN/FD18AvySDpEy3KPhviNC6I3t6RyHEBWjSqx EelVZ8koWPK9W/kz/QGBfbmVTvuu5/BjbYBwR3xwdLGYK9QYP9CC9MkEmg+fCWc3OUNp e8f8g9Qfg+Ka4hhzchFe8eSiIGET5nHWvZeEgM451rcSHE83/ugvVbVW0lfr8H7da56L mv/w== 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=a4++5XAxHPSXr8r2Hi1wE7grhFX3hFIKa+sRwRd7OwA=; b=rXGxC2VoAqA4M+1xKQgOXB887IcbAhkLgdYzen+8QF5dRt921VZtPLZwXG0eA2TshG L9uUW9KpqVnAnpSJQsoe1N4eaYWNf4hHULfxdr/EUGurkZq6HWcd50YAzCoGpyxYYxiR 1t9CjLZzv0rEPkv+xJLvSk9rJIcIfzz6tZiCJ2+4nFFU8mQ4H+bt/0jg5nf9nmgARdRM Ht3TK4qAarNDBQLgoXWbc1bFX2gyCQDpeH/o2ZoZd0YH4tJfUdwzUNMxalEGXu8VVjP7 C/HMsg2QDVMAhyTzFKgoyE+bhNglv2EOQBl/OKC7Jmgb6F8AwjrEOMkgsJiD+YpVhpIl YFfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=EUtItGeO; 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 e26-20020a63545a000000b0049b37046fbcsi20961835pgm.391.2023.01.13.16.58.38; Fri, 13 Jan 2023 16:58:44 -0800 (PST) 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=EUtItGeO; 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 S231574AbjANAf4 (ORCPT + 53 others); Fri, 13 Jan 2023 19:35:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231301AbjANAe1 (ORCPT ); Fri, 13 Jan 2023 19:34:27 -0500 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 723558A23E; Fri, 13 Jan 2023 16:34:25 -0800 (PST) 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=a4++5XAxHPSXr8r2Hi1wE7grhFX3hFIKa+sRwRd7OwA=; b=EUtItGeOml+SnGyd/aa1i+dhcs O+nSajxiLk3oWLqbNqPd6en6ZMZofO9KCKeOI9NqVQFBlgZfR8XTn5XzVIroGCGy9V3J6uh81tyxl tDfiNYnTOO77UMQhB/zounAKXjgAqoVQPsyQmk4Jqo4QjBjYEbmEwhzujJfwe6a+iF8S8/SOxX1tm YzY2FMNjNgdfH0GT4ZOwP2HFbWrLjWoKuAAW7i1NeH+9tCi9JJN9kf/4+Uno6mucyg8qr+YaMY+jy Nx9aBtOCD7c2h5dTdHw9kQwYMyiNpB8oN7m51BpJdWVg5/9wnrJxXmzYoQi2YzhJdqSb4pIuwWYkC 4NBNHe5A==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pGUUt-004twB-7o; Sat, 14 Jan 2023 00:34:11 +0000 From: Luis Chamberlain To: hch@infradead.org, djwong@kernel.org, song@kernel.org, rafael@kernel.org, gregkh@linuxfoundation.org, viro@zeniv.linux.org.uk, jack@suse.cz, bvanassche@acm.org, ebiederm@xmission.com Cc: mchehab@kernel.org, keescook@chromium.org, p.raghav@samsung.com, linux-fsdevel@vger.kernel.org, kernel@tuxforce.de, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Luis Chamberlain Subject: [RFC v3 08/24] ext4: replace kthread freezing with auto fs freezing Date: Fri, 13 Jan 2023 16:33:53 -0800 Message-Id: <20230114003409.1168311-9-mcgrof@kernel.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230114003409.1168311-1-mcgrof@kernel.org> References: <20230114003409.1168311-1-mcgrof@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Luis Chamberlain X-Spam-Status: No, score=-4.0 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 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 superflous freezer calls: spatch --sp-file fs-freeze-cleanup.cocci --in-place --timeout 120 --dir fs/ext4 --jobs 12 --use-gitgrep @ 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/ext4/super.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index b31db521d6bf..0ae6f13c7fa4 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -136,7 +136,7 @@ static struct file_system_type ext2_fs_type = { .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV, + .fs_flags = FS_REQUIRES_DEV | FS_AUTOFREEZE, }; MODULE_ALIAS_FS("ext2"); MODULE_ALIAS("ext2"); @@ -152,7 +152,7 @@ static struct file_system_type ext3_fs_type = { .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV, + .fs_flags = FS_REQUIRES_DEV | FS_AUTOFREEZE, }; MODULE_ALIAS_FS("ext3"); MODULE_ALIAS("ext3"); @@ -3734,7 +3734,6 @@ static int ext4_lazyinit_thread(void *arg) unsigned long next_wakeup, cur; BUG_ON(NULL == eli); - set_freezable(); cont_thread: while (true) { @@ -3786,8 +3785,6 @@ static int ext4_lazyinit_thread(void *arg) } mutex_unlock(&eli->li_list_mtx); - try_to_freeze(); - cur = jiffies; if ((time_after_eq(cur, next_wakeup)) || (MAX_JIFFY_OFFSET == next_wakeup)) { @@ -7192,7 +7189,7 @@ static struct file_system_type ext4_fs_type = { .init_fs_context = ext4_init_fs_context, .parameters = ext4_param_specs, .kill_sb = kill_block_super, - .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP, + .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP | FS_AUTOFREEZE, }; MODULE_ALIAS_FS("ext4"); -- 2.35.1