Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2891241rwo; Mon, 24 Jul 2023 03:02:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlFfq1gVe2tlGmxNdFI5fML+YwYgHjMPEdLFwf2tzGooQmz3PesdQORXcVdyaF0n/g5sMloK X-Received: by 2002:a17:906:1046:b0:991:cd1f:e67a with SMTP id j6-20020a170906104600b00991cd1fe67amr10367009ejj.29.1690192935187; Mon, 24 Jul 2023 03:02:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690192935; cv=none; d=google.com; s=arc-20160816; b=mmuGJj5aulz28DEUoK4N1bnv2Iw5tr3CtCugt7eAxfWWJ1r4gH2qSTvK0ObIesaRhN HSUolBHAy1l5SrLigApXZG6PiFxHKu7q2Je6AxnUE+FQ3LoMh2FRu7ZC8n4zH7TVYLpN KcVGdiUXDwzXSnvTxnwL3N3qXsyUwn+AdPMspGe3HSKgvz9FConBFmaHQSYMYLxn6a3Y WxexH6wkfW9JdFIV0qBsr8xezyihp+J0gMyaj+oo7q9rey2t8qyDr1zfIaJ0Egh+BMKz Y7HracowGUort8NIzUQuCtLWN03PbU0+0116iJ+yhFXR29hBDnRMZtzaHRrKBlPNRPU1 QXxQ== 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=guTIXae/kI3JPez6Art55JYiwmImAmg2GBvF3i236eo=; fh=3lDHiAuENCYj3gWFb2bYij2cH/UC7c23rwbOpuSBNc8=; b=uhMwDTjMsk3w2VdjOyhG8dYkD1DF4HsFaNrNGYtRjdkAstB9XmN6CPfaz16X+7NkPh +Y2shQugwrBW9SPHeiMolt5qy4+eO06XcBJkOMJZ2bw/xZO/Yz7M72IZxDDhH9fO43Qw F69q+7FkJqybUwkvtHOW7colA/vPOsH8xYjVMlTM7MFB05szMQgH+ukXupDGWM5PUPta U/wfiCVadXlNfyJzPld+r4rYwo3yNtcv3oPgiCmpb1mMx6NUYxU4cr6tQUFjxs4PkgwX LdPv2Lkh8L1o72g/sJQ3pot785Q5v2M74WxNyJlOdBD/nZ37DlxvMVqo0IeW/RLe/pBi IZyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ZQ68ZN0k; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a170906850e00b0099265d36c8dsi6649248ejx.294.2023.07.24.03.01.50; Mon, 24 Jul 2023 03:02:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@bytedance.com header.s=google header.b=ZQ68ZN0k; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232931AbjGXKA4 (ORCPT + 99 others); Mon, 24 Jul 2023 06:00:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232933AbjGXKAY (ORCPT ); Mon, 24 Jul 2023 06:00:24 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C8A4C21 for ; Mon, 24 Jul 2023 02:54:08 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3a1e8fe2cbbso461130b6e.0 for ; Mon, 24 Jul 2023 02:54:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690192370; x=1690797170; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=guTIXae/kI3JPez6Art55JYiwmImAmg2GBvF3i236eo=; b=ZQ68ZN0kCjYEK1vOBYHh5/GRW+Szyu7pr3yUqOL3SQfE0cp4MYovv5XZ6hMMoZB8vd JlCpnzTb4Znjd+WhJyML0f/qU68cTqaTf18vrALfozs6cYUNtyEcmW3W3sCgjwWObvFp 6KO92T+cSITJ5XygGnBxineLZSmvgVjXYf6TvBrp6XfnMyspqDj8aTAinmwvjq2C13r0 DUHCoZjSTK8JnlE/SFXErLLOLnUgP8syd1DOx8c50h2MnxR2GI2lIWsNt+8iGTuTLbcx JgCoO2XcYz0W8EFbrIk5gXv4ZTLCC8j+ZWM+/qYIVbLDZB5K27c5kz5M9wxFzZOqQXDW 13ZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690192370; x=1690797170; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=guTIXae/kI3JPez6Art55JYiwmImAmg2GBvF3i236eo=; b=UW3QPKqUaOFsjDdfzGe8LsaAf5zK8ydqv/hKIcJxP22wS3LKrmeAlrl5l/YsSHoAHt +HswiNTvRFv6qAEmQLrPYLiEH5qbCHqmhAbsxPsd6gjv/oWGb1rE30vtGhPgYJu9YY9D 3ZRFjQrh9Lu505K/N/6koyjEQvHjkAvYDwzse1iqwejxxVYKSv2y/c46ArwWbLkjjDGb pRHNF5FlTn9mUyMmr/cz9aekC/3rtoFJW2lCAWFVb+/ViKYIjKr0iZh9l+/Zti5sOnpN PDozckz56/kV6RHzIcztl+3Z4DYF1FEOTUJe9kSUAyY6X+wvOIBoyEoDz8ByGJyQcvuM 44rA== X-Gm-Message-State: ABy/qLYPplLxZgjlg4bC+suVeVruTMkLoBPRMj3cKrP98zliOD9BLQfx hAHhvgYivPTIX+pYyTIzyje4VcNqUCb2Hb3HGSA= X-Received: by 2002:a17:903:41cd:b0:1bb:9e6e:a9f3 with SMTP id u13-20020a17090341cd00b001bb9e6ea9f3mr4119632ple.4.1690192350104; Mon, 24 Jul 2023 02:52:30 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id d5-20020a170902c18500b001bb20380bf2sm8467233pld.13.2023.07.24.02.52.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 02:52:29 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH v2 37/47] xfs: dynamically allocate the xfs-inodegc shrinker Date: Mon, 24 Jul 2023 17:43:44 +0800 Message-Id: <20230724094354.90817-38-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230724094354.90817-1-zhengqi.arch@bytedance.com> References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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-ext4@vger.kernel.org In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the xfs-inodegc shrinker, so that it can be freed asynchronously using kfree_rcu(). Then it doesn't need to wait for RCU read-side critical section when releasing the struct xfs_mount. Signed-off-by: Qi Zheng --- fs/xfs/xfs_icache.c | 26 +++++++++++++++----------- fs/xfs/xfs_mount.c | 4 ++-- fs/xfs/xfs_mount.h | 2 +- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c index 453890942d9f..751c380afd5a 100644 --- a/fs/xfs/xfs_icache.c +++ b/fs/xfs/xfs_icache.c @@ -2225,8 +2225,7 @@ xfs_inodegc_shrinker_count( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_mount *mp = container_of(shrink, struct xfs_mount, - m_inodegc_shrinker); + struct xfs_mount *mp = shrink->private_data; struct xfs_inodegc *gc; int cpu; @@ -2247,8 +2246,7 @@ xfs_inodegc_shrinker_scan( struct shrinker *shrink, struct shrink_control *sc) { - struct xfs_mount *mp = container_of(shrink, struct xfs_mount, - m_inodegc_shrinker); + struct xfs_mount *mp = shrink->private_data; struct xfs_inodegc *gc; int cpu; bool no_items = true; @@ -2284,13 +2282,19 @@ int xfs_inodegc_register_shrinker( struct xfs_mount *mp) { - struct shrinker *shrink = &mp->m_inodegc_shrinker; + mp->m_inodegc_shrinker = shrinker_alloc(SHRINKER_NONSLAB, + "xfs-inodegc:%s", + mp->m_super->s_id); + if (!mp->m_inodegc_shrinker) + return -ENOMEM; + + mp->m_inodegc_shrinker->count_objects = xfs_inodegc_shrinker_count; + mp->m_inodegc_shrinker->scan_objects = xfs_inodegc_shrinker_scan; + mp->m_inodegc_shrinker->seeks = 0; + mp->m_inodegc_shrinker->batch = XFS_INODEGC_SHRINKER_BATCH; + mp->m_inodegc_shrinker->private_data = mp; - shrink->count_objects = xfs_inodegc_shrinker_count; - shrink->scan_objects = xfs_inodegc_shrinker_scan; - shrink->seeks = 0; - shrink->flags = SHRINKER_NONSLAB; - shrink->batch = XFS_INODEGC_SHRINKER_BATCH; + shrinker_register(mp->m_inodegc_shrinker); - return register_shrinker(shrink, "xfs-inodegc:%s", mp->m_super->s_id); + return 0; } diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c index fb87ffb48f7f..27c2d24797c9 100644 --- a/fs/xfs/xfs_mount.c +++ b/fs/xfs/xfs_mount.c @@ -1018,7 +1018,7 @@ xfs_mountfs( out_log_dealloc: xfs_log_mount_cancel(mp); out_inodegc_shrinker: - unregister_shrinker(&mp->m_inodegc_shrinker); + shrinker_unregister(mp->m_inodegc_shrinker); out_fail_wait: if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) xfs_buftarg_drain(mp->m_logdev_targp); @@ -1100,7 +1100,7 @@ xfs_unmountfs( #if defined(DEBUG) xfs_errortag_clearall(mp); #endif - unregister_shrinker(&mp->m_inodegc_shrinker); + shrinker_unregister(mp->m_inodegc_shrinker); xfs_free_perag(mp); xfs_errortag_del(mp); diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h index e2866e7fa60c..562c294ca08e 100644 --- a/fs/xfs/xfs_mount.h +++ b/fs/xfs/xfs_mount.h @@ -217,7 +217,7 @@ typedef struct xfs_mount { atomic_t m_agirotor; /* last ag dir inode alloced */ /* Memory shrinker to throttle and reprioritize inodegc */ - struct shrinker m_inodegc_shrinker; + struct shrinker *m_inodegc_shrinker; /* * Workqueue item so that we can coalesce multiple inode flush attempts * into a single flush. -- 2.30.2