Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp3720780rwr; Sun, 7 May 2023 18:41:01 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ68gCs/W2JMCf1s9qkM67/9RYDbtBWTrQbUT9t+7J5p3F1niOZ+/qifz8iasMXXaryeNEzX X-Received: by 2002:a17:90a:cb02:b0:249:6098:b068 with SMTP id z2-20020a17090acb0200b002496098b068mr9128439pjt.45.1683510060705; Sun, 07 May 2023 18:41:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683510060; cv=none; d=google.com; s=arc-20160816; b=B0zvAYc44J2f+obpMRLX5rROpWS+U7jaQp13paDTwBz9ecpb3UDM9vS5B/vulOEfLU tEi+REyQ150YDmhgp/l72k82Fx9XfIFEXLIJIbZfVyY6IOKb5rdqTrWRKjQDfuk+LYrQ RAM0R6O5EoPA/SMhkk7Qbgi2aSuaCNy/qLRF0r3Fz0wy3CRjQfwEWIvwzx7R5hKOpfN2 9I+wX1vQdTVCxzm3TBdNFo/NaQtNjA2Sav335xAYKT7lwdIbAqflNZNYFsqDXUBlXsVz Txi6uA5+YYhThon5JuzeYc9lh5hhoziriGGCA2YK6qOsrnbTEzt8qkWscGOSUp6yZ/dN Xh4g== 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=Iq+GJy0SYT3EQ729uzX+WNTK2VcOhGS7edVn1rT+bXU=; b=fh3lhJIFvUAJY7rH/K90UXjU4imVDREXuDwMt851Sb03PD0I7oZTlnMVTERn6jo1xY MrL25rXVq92sEZ6Hq6woUzqjU4pcCMaMLlP+5AsJzkFtgqMP97L0cjTHXweHh3YFnQ1X KeRUaLtabPTqaW+dwEvbVKntrKdbxCjInRtMFNxwrSfR6QlCIM0QnIMGzI/tkLuz8BGr ryjG8k3tiafn0PyGNAiq2bysvh+LTPyu5dbvrmrWIzSxZPusnDo751C1XziAj3hUrDop JP/hwTnonDwRXGvrKGwWtc5JeiLwqlPOLM6HYQed6atJ/+m/8/mRlFbZzc3cqdtLsM3t n2Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b=cxcuXLsw; 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 pc12-20020a17090b3b8c00b00246596483a3si18865998pjb.37.2023.05.07.18.40.48; Sun, 07 May 2023 18:41:00 -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=cxcuXLsw; 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 S232484AbjEHBTt (ORCPT + 99 others); Sun, 7 May 2023 21:19:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232291AbjEHBTl (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 04996124B3; Sun, 7 May 2023 18:19:36 -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=Iq+GJy0SYT3EQ729uzX+WNTK2VcOhGS7edVn1rT+bXU=; b=cxcuXLswjH61dwpHVdEYkT59Qa pleqlWyhX5duQKH30dhD/5GI2gFJvg2gpVm0Rr5DVj5BXtEU/UO4Cg6LLvBM4E1hmPL9aPqBxl/mz yLDtJZ3SgJRQ2PFgkf4vcnRyx4MTml7DGYxXqi9AwyzDmrdOZsJIX9ozSAhtBneTGZc9nJNxwGmT7 vZ2hkNH7dKAFjsV2UZFx/Q4U6QTTA0avlF9shdGnT4P1g/iHcEXuC96K33DnDeHR6BAeMet7Yh37d ZSDEURcJ8nazX9pHqEE70ymf9kQ31FdLezxqKVp2boGJXFaTsFCmMyww4rP8l5oZIA7tFlgaY6pXl dRPsB6Cw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1pvpXE-00Gw8O-1P; 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 1/3] ext4: replace kthread freezing with auto fs freezing Date: Sun, 7 May 2023 18:19:25 -0700 Message-Id: <20230508011927.4036707-2-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/ext4 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/ext4/super.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index d39f386e9baf..1f436938d8be 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"); @@ -3790,7 +3790,6 @@ static int ext4_lazyinit_thread(void *arg) unsigned long next_wakeup, cur; BUG_ON(NULL == eli); - set_freezable(); cont_thread: while (true) { @@ -3842,8 +3841,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)) { @@ -7245,7 +7242,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.39.2