Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp2074361rwb; Thu, 27 Jul 2023 01:21:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlH76Bb1TNm3BK6mQAb2XfkyPVbWPKTtMyeqFRlUUo+JjAaUwEdKinIfcVfv1yJFmBzhxtPt X-Received: by 2002:a17:902:e314:b0:1b8:95a1:847c with SMTP id q20-20020a170902e31400b001b895a1847cmr3211972plc.40.1690446103259; Thu, 27 Jul 2023 01:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690446103; cv=none; d=google.com; s=arc-20160816; b=z4mejkAN7fGkq5p5obrxMrR/hn01Zt6kaMV//7/hwOzwmNTJO4FvjN6PuHjX+z9sTI ob1QWe/z9RctVsEcpflimM/Gk6epu7jXYjVK+xOpDBSPi7Rxjm40GLWYN36f6hHIdGWr nE7iR9peyYk6RQJV9+C4FSkOmaM+ddrHWgeHTC87Ab06ORPNfRUX5B/bnERdjjclkq6k ZQ/Ny2sd2/zgnACPyZuiwZ2Wijk+LhJ0J0zgLdsZxahSch2S0wswziCOCXOgvMouADsH bCgNUv+MAbSENc5wo2p9MDnAwU4VvVtgr7wSnZO7BNrYGy7BTZZUPMHjtU70zEWomKKs yAWg== 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=hJ9OcOwqZEZhIoLNGrov7as0vMS5t1dTfm2Sm9qefJI=; fh=NxkGAd430gburLVd9IjvP+jLcLBa8IzZa5IqPWgCN1g=; b=EWQ++lEJADUL9UsN8nmVEQqW6Ox5U4BnyxIdAPGLa8J+tHplVzCiIkNZQ4rvRf9vN0 aozKZa0LZU946xHirGkAlHjl2HRvOy5uEe0mmcukRUqaCG5Qfp8egLS2Qrz1VLcPeuq4 rOFy3RoBPNq0XC2DPv2Y79Ks7QYEnkSvryG9DbMOBVgZldVlAYFniUp/pQDLFvj/Xjdz O6F3aFey1YIXzbahxs4qV+ltNZiV+GBecnYGyCs/H2d6+bbbovPzDsXtmGuHk4+V8eY0 IyN/WOckx8F1fZsQCSfQfFVprZ1A1NsF0M9NnG+qGxcgrA69mhdCYfCqRTpOlHhMrQVh 4pCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=AioCATUl; 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 i13-20020a17090332cd00b001bb935754f0si967478plr.444.2023.07.27.01.21.28; Thu, 27 Jul 2023 01:21:43 -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=AioCATUl; 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 S231868AbjG0IMk (ORCPT + 99 others); Thu, 27 Jul 2023 04:12:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233901AbjG0ILd (ORCPT ); Thu, 27 Jul 2023 04:11:33 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6348C3598 for ; Thu, 27 Jul 2023 01:07:53 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6862d4a1376so188385b3a.0 for ; Thu, 27 Jul 2023 01:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445222; x=1691050022; 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=hJ9OcOwqZEZhIoLNGrov7as0vMS5t1dTfm2Sm9qefJI=; b=AioCATUlkHfrdNMX26y5cMG8yiZzcrqJVPo4kMJoo0a/SPBGZMItYxbURGlfK0qQ3U pdquqHjvBnBibcfcPa96/7pchRYEBHxyNnf24E8fTswl7dwSe4DIa81z6/ovJRcM58gW OCn1XGDPuwokH00bwAsXcK1Gr5D3vpz/ZXjhjYJknWBgLZAbQPwFGeGyEdzXyVgOqH5z Y8WwL8gpftvasBEeZpl0cei4t7+d2ZCdr5qxpBrrzaVJwzr8lwB/25SUTyxKcTGn9xox E7xpcSMCUuenHibKLxGm6dPJne0R4y90eWbLKKoQI9m29dm8UqZ2/hC+L12FcXTeAlus bdTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445222; x=1691050022; 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=hJ9OcOwqZEZhIoLNGrov7as0vMS5t1dTfm2Sm9qefJI=; b=l+voM2nIXQOaXxeM+95bRa+lYFae4SNtL6s7FVv5DPr6suKIFa/i2RBhV1gUhMTdA5 HyEg3E9liu+DkBbU96MrdduyLMY46P6TEZcn//Mt1/wfULvdqXhWYKbCmxHDWurVO0Mv cCc85MGJk2FpNscGjEX2FRTyLVaGUk1jgvk41eFBzIyof0+ZYiIUmLpgs0N0dD2PeS1y N1588oxVIHTUpzeOg2R9PDNIT5kQ8Fv3zKp4D2fHoWrnCxlH3J2USLzA1YVxHoKrmudw pihTSPGMPJGiESSgM4YPM5mxy0JzBOBwoetE/F+vdful4smaFOBMOJNvSJkoOqq+EaC9 VZtw== X-Gm-Message-State: ABy/qLb6j1R/8maQgkyevghqRdwh2lXnSIpoQ1UtiXL2LJ3Y1XON/pYh s/fvCZcvHciA33zHwwhESrXskA== X-Received: by 2002:aa7:8615:0:b0:681:9fe0:b543 with SMTP id p21-20020aa78615000000b006819fe0b543mr4619538pfn.2.1690445222261; Thu, 27 Jul 2023 01:07:02 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.06.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:07:01 -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 , Muchun Song Subject: [PATCH v3 06/49] kvm: mmu: dynamically allocate the x86-mmu shrinker Date: Thu, 27 Jul 2023 16:04:19 +0800 Message-Id: <20230727080502.77895-7-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-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_NONE,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 Use new APIs to dynamically allocate the x86-mmu shrinker. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- arch/x86/kvm/mmu/mmu.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index ec169f5c7dce..15fc92a24a26 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -6847,11 +6847,7 @@ static unsigned long mmu_shrink_count(struct shrinker *shrink, return percpu_counter_read_positive(&kvm_total_used_mmu_pages); } -static struct shrinker mmu_shrinker = { - .count_objects = mmu_shrink_count, - .scan_objects = mmu_shrink_scan, - .seeks = DEFAULT_SEEKS * 10, -}; +static struct shrinker *mmu_shrinker; static void mmu_destroy_caches(void) { @@ -6984,10 +6980,16 @@ int kvm_mmu_vendor_module_init(void) if (percpu_counter_init(&kvm_total_used_mmu_pages, 0, GFP_KERNEL)) goto out; - ret = register_shrinker(&mmu_shrinker, "x86-mmu"); - if (ret) + mmu_shrinker = shrinker_alloc(0, "x86-mmu"); + if (!mmu_shrinker) goto out_shrinker; + mmu_shrinker->count_objects = mmu_shrink_count; + mmu_shrinker->scan_objects = mmu_shrink_scan; + mmu_shrinker->seeks = DEFAULT_SEEKS * 10; + + shrinker_register(mmu_shrinker); + return 0; out_shrinker: @@ -7009,7 +7011,7 @@ void kvm_mmu_vendor_module_exit(void) { mmu_destroy_caches(); percpu_counter_destroy(&kvm_total_used_mmu_pages); - unregister_shrinker(&mmu_shrinker); + shrinker_free(mmu_shrinker); } /* -- 2.30.2