From patchwork Mon Sep 11 09:44:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1282CA0EC4 for ; Mon, 11 Sep 2023 21:03:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238569AbjIKU4T (ORCPT ); Mon, 11 Sep 2023 16:56:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235951AbjIKJqz (ORCPT ); Mon, 11 Sep 2023 05:46:55 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A32BD116 for ; Mon, 11 Sep 2023 02:46:29 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1befe39630bso9364655ad.0 for ; Mon, 11 Sep 2023 02:46:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425589; x=1695030389; darn=vger.kernel.org; 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=eZxqpi7coMh8ftID9yaYhwXiGQ4pT4wdMxIpYIgs7HE=; b=RTmhkn/o4Xr2tinOoNz5+m5dythyjhHW01w6UVJAp1mTgvZYfNM4UgFAArHcR9CTUv esx18cEpE4l+9HJoG52z8HfqyHDI3CwMQKyWFOAykaFFNnhkuAkdqQWiSxPnCqklnKaq WeoV5ggGHFuSNJBk45cpyHYNy0IunQpDYOYf4LkzrIhk1eQ9EnYrbJ883zudHLXbB8Cl qB6Fk2JKtWE3F/+TtijI1Zhq2xAP+ggy4FdZPIfQ3Wqqa3pkeEQI6a2zOiju0qcG9jg4 CHHYcnSTagf8zquoMREemrB5KrKDRFozPc7GPAAlnZLhml7tJ6BqTSyP7a9hbyn9Rr2z 48Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425589; x=1695030389; 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=eZxqpi7coMh8ftID9yaYhwXiGQ4pT4wdMxIpYIgs7HE=; b=aMs771Niq11Gtct596kpkvyeZYs32J7nW+zELQlqyCOoTufnDOMFPxOintwCV5H3uZ DV/9uk2PB8QMx8iqKUxCTvaPC/qOo8TaVeKkGJeamrlb1/BNJNV7YNVz3QD15Mp3tKgp KfGUqrv1Ii8u5rque1D/GCSY+Yc2oGh/q5vIDCo6IPvnBkzafSKAHXBSxOJrNhJSVCMY pJg9ZAa0F+gXNbF89iDHYVN/XseUfVfwr+1Tk8rbRLT2r05XeQhu1h0QzQn0wNZg6kbr fnjNOgen1P8LhlSbYcUqReOuATkULvwEkRSsKUfHYzTkcYLeVoD8WF6F85W9QD5M4Fwo 8nUA== X-Gm-Message-State: AOJu0Yx4S2CumZSVgqhSzTpm3y6uwiXfQ/DmzqsmRZQq6asjaG6oNldK lQbxExxG4FCYAu1G4AjArgM23Q== X-Google-Smtp-Source: AGHT+IErSLcCsEqsbL+707FM3SjghmcKvBuY/KdVR6v7hA7UKBMg35jal9WCdltKnJHFJ2qaL3tLGg== X-Received: by 2002:a17:902:d645:b0:1c3:c687:478a with SMTP id y5-20020a170902d64500b001c3c687478amr326782plh.2.1694425589143; Mon, 11 Sep 2023 02:46:29 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id az7-20020a170902a58700b001bdc2fdcf7esm5988188plb.129.2023.09.11.02.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:46:28 -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, linux-fsdevel@vger.kernel.org, Qi Zheng , Muchun Song , Bob Peterson , Andreas Gruenbacher , cluster-devel@redhat.com Subject: [PATCH v6 09/45] gfs2: dynamically allocate the gfs2-qd shrinker Date: Mon, 11 Sep 2023 17:44:08 +0800 Message-Id: <20230911094444.68966-10-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230911094444.68966-1-zhengqi.arch@bytedance.com> References: <20230911094444.68966-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Use new APIs to dynamically allocate the gfs2-qd shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: Bob Peterson CC: Andreas Gruenbacher CC: cluster-devel@redhat.com --- fs/gfs2/main.c | 6 +++--- fs/gfs2/quota.c | 25 +++++++++++++++++++------ fs/gfs2/quota.h | 3 ++- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c index 66eb98b690a2..79be0cdc730c 100644 --- a/fs/gfs2/main.c +++ b/fs/gfs2/main.c @@ -147,7 +147,7 @@ static int __init init_gfs2_fs(void) if (!gfs2_trans_cachep) goto fail_cachep8; - error = register_shrinker(&gfs2_qd_shrinker, "gfs2-qd"); + error = gfs2_qd_shrinker_init(); if (error) goto fail_shrinker; @@ -196,7 +196,7 @@ static int __init init_gfs2_fs(void) fail_wq2: destroy_workqueue(gfs2_recovery_wq); fail_wq1: - unregister_shrinker(&gfs2_qd_shrinker); + gfs2_qd_shrinker_exit(); fail_shrinker: kmem_cache_destroy(gfs2_trans_cachep); fail_cachep8: @@ -229,7 +229,7 @@ static int __init init_gfs2_fs(void) static void __exit exit_gfs2_fs(void) { - unregister_shrinker(&gfs2_qd_shrinker); + gfs2_qd_shrinker_exit(); gfs2_glock_exit(); gfs2_unregister_debugfs(); unregister_filesystem(&gfs2_fs_type); diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c index 171b2713d2e5..d3d013d1d5ac 100644 --- a/fs/gfs2/quota.c +++ b/fs/gfs2/quota.c @@ -196,13 +196,26 @@ static unsigned long gfs2_qd_shrink_count(struct shrinker *shrink, return vfs_pressure_ratio(list_lru_shrink_count(&gfs2_qd_lru, sc)); } -struct shrinker gfs2_qd_shrinker = { - .count_objects = gfs2_qd_shrink_count, - .scan_objects = gfs2_qd_shrink_scan, - .seeks = DEFAULT_SEEKS, - .flags = SHRINKER_NUMA_AWARE, -}; +static struct shrinker *gfs2_qd_shrinker; + +int __init gfs2_qd_shrinker_init(void) +{ + gfs2_qd_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE, "gfs2-qd"); + if (!gfs2_qd_shrinker) + return -ENOMEM; + + gfs2_qd_shrinker->count_objects = gfs2_qd_shrink_count; + gfs2_qd_shrinker->scan_objects = gfs2_qd_shrink_scan; + + shrinker_register(gfs2_qd_shrinker); + return 0; +} + +void gfs2_qd_shrinker_exit(void) +{ + shrinker_free(gfs2_qd_shrinker); +} static u64 qd2index(struct gfs2_quota_data *qd) { diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h index 21ada332d555..f0d54dcbbc75 100644 --- a/fs/gfs2/quota.h +++ b/fs/gfs2/quota.h @@ -59,7 +59,8 @@ static inline int gfs2_quota_lock_check(struct gfs2_inode *ip, } extern const struct quotactl_ops gfs2_quotactl_ops; -extern struct shrinker gfs2_qd_shrinker; +int __init gfs2_qd_shrinker_init(void); +void gfs2_qd_shrinker_exit(void); extern struct list_lru gfs2_qd_lru; extern void __init gfs2_quota_hash_init(void);