From patchwork Wed May 31 09:57:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 101331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2770387vqr; Wed, 31 May 2023 03:23:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ40sKNkRp9KVaWykC3OcGBhgmO8xXH5pV+Ml+V223BtNAfw+ei9M2D1Cx7+G44l5qh/4K3Z X-Received: by 2002:a9d:7dc2:0:b0:6af:887d:a517 with SMTP id k2-20020a9d7dc2000000b006af887da517mr2016567otn.15.1685528583301; Wed, 31 May 2023 03:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685528583; cv=none; d=google.com; s=arc-20160816; b=EailfUWZYb3+39M7RULNPHF5gyUl/bH6ERDaLmWgplZ8VNETBx4gNgrP7XS9P+5wj/ PXuP5huOUtMlRB5xlHD06/N95o78WPNprodUGmFM5Kx1iGe4F8jw+xBbVxTRF10qx48H zMMwyTNA2VLQTeXNurxBu88dQHW24pWqI0HajHfdRQhJHT3I7tjZjOIIqKmAT86BpkLq Ns0IDBZgT0iZL4jyjnpQVqUts6jazDSJt5GQJbHtL8a0brZ3ABGkmKs/Bw+4ABtskLKZ yFPRTjYUDLh1bFiVy4TDB3KqP/wTmDdumiUutDv+xfCiE7I2F7KKKpijzb7cwW5g8H8Y hcnA== 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=mjcsinqX7KwTJ40/JcL+JgGM2W0swatrtd18npIFtVk=; b=Jt9+bK0QjoBCIlkB4uIbbvAhx/o4MkVB1+Hgtlbi3zKC2Oeir3GDDqmjx5an3LnEJt b2i92Rzy3Ooq3ozr7dCywXKG/R6qSyh7kNtcEOe67KH//gehgb1bSGT94MmrEqJc0xze 3bC9YSFN5SUv/irYLS2MYPLHEclTxaNAQtTlrFR5Ozho313THLxyGZ3ZnGL7QX+df8Y3 +2PttuOxr3tDjBe3joubddA7+f/erDAh8ldnI/bMIjHHFTRxcwkatxlQj69HxwBQ80DU uuNgraohSYuOeIiuMym0KLPbhffv62RvPMb/fWOJ/NEXEqLSBnAkOMU2JcgF9tOgJuLf QUWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=baMB2GLV; 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=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m63-20020a625842000000b0063a6dbeaa56si3413520pfb.60.2023.05.31.03.22.49; Wed, 31 May 2023 03:23:03 -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=@linux.dev header.s=key1 header.b=baMB2GLV; 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=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235791AbjEaJ70 (ORCPT + 99 others); Wed, 31 May 2023 05:59:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235740AbjEaJ7Q (ORCPT ); Wed, 31 May 2023 05:59:16 -0400 Received: from out-54.mta0.migadu.com (out-54.mta0.migadu.com [IPv6:2001:41d0:1004:224b::36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8568E10E for ; Wed, 31 May 2023 02:58:53 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1685527129; 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=mjcsinqX7KwTJ40/JcL+JgGM2W0swatrtd18npIFtVk=; b=baMB2GLVbbUmgLTp+CUXyhhVv/9x56bQV3iqZ8MjrGpSa7p5jatJsXPULpCV9EV8+jBrYl PchelLFH6ZF8vYpgvhoNebbx99TRM79XB4NftLwSZ90r/JoVrRMdf+o3xlQ1brouvtCBtm EjXCENjNIePsNVRgiPye7pdqlsEyPGs= From: Qi Zheng To: akpm@linux-foundation.org, tkhai@ya.ru, roman.gushchin@linux.dev, vbabka@suse.cz, viro@zeniv.linux.org.uk, brauner@kernel.org, djwong@kernel.org, hughd@google.com, paulmck@kernel.org, muchun.song@linux.dev Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, Qi Zheng Subject: [PATCH 8/8] fs: use unregister_shrinker_delayed_{initiate, finalize} for super_block shrinker Date: Wed, 31 May 2023 09:57:42 +0000 Message-Id: <20230531095742.2480623-9-qi.zheng@linux.dev> In-Reply-To: <20230531095742.2480623-1-qi.zheng@linux.dev> References: <20230531095742.2480623-1-qi.zheng@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767404819960875216?= X-GMAIL-MSGID: =?utf-8?q?1767404819960875216?= From: Kirill Tkhai Previous patches made all the data, which is touched from super_cache_count(), destroyed from destroy_super_work(): s_dentry_lru, s_inode_lru and super_block::s_fs_info. super_cache_scan() can't be called after SB_ACTIVE is cleared in generic_shutdown_super(). So, it safe to move heavy unregister_shrinker_delayed_finalize() part to delayed work, i.e. it's safe for parallel do_shrink_slab() to be executed between unregister_shrinker_delayed_initiate() and destroy_super_work()->unregister_shrinker_delayed_finalize(). This makes the heavy synchronize_srcu() to do not affect on user-visible unregistration speed (since now it's executed from workqueue). All further time-critical for unregistration places may be written in the same conception. Signed-off-by: Kirill Tkhai Signed-off-by: Qi Zheng --- fs/super.c | 4 +++- include/linux/fs.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/super.c b/fs/super.c index 4e9d08224f86..c61efb74fa7f 100644 --- a/fs/super.c +++ b/fs/super.c @@ -165,6 +165,8 @@ static void destroy_super_work(struct work_struct *work) destroy_work); int i; + unregister_shrinker_delayed_finalize(&s->s_shrink); + WARN_ON(list_lru_count(&s->s_dentry_lru)); WARN_ON(list_lru_count(&s->s_inode_lru)); list_lru_destroy(&s->s_dentry_lru); @@ -337,7 +339,7 @@ void deactivate_locked_super(struct super_block *s) { struct file_system_type *fs = s->s_type; if (atomic_dec_and_test(&s->s_active)) { - unregister_shrinker(&s->s_shrink); + unregister_shrinker_delayed_initiate(&s->s_shrink); fs->kill_sb(s); put_filesystem(fs); diff --git a/include/linux/fs.h b/include/linux/fs.h index 30b46d0facfc..869dd8de91a5 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1929,6 +1929,11 @@ struct super_operations { ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); struct dquot **(*get_dquots)(struct inode *); #endif + /* + * Shrinker may call these two function on destructing super_block + * till unregister_shrinker_delayed_finalize() has completed + * in destroy_super_work(), and they must care about that. + */ long (*nr_cached_objects)(struct super_block *, struct shrink_control *); long (*free_cached_objects)(struct super_block *,