From patchwork Mon Sep 11 09:44:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379070 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8BDFCEE7FF4 for ; Mon, 11 Sep 2023 09:47:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25AD36B01F7; Mon, 11 Sep 2023 05:47:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 20B676B01F8; Mon, 11 Sep 2023 05:47:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0AC836B01F9; Mon, 11 Sep 2023 05:47:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EAFF46B01F7 for ; Mon, 11 Sep 2023 05:47:33 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BD71DB3A3C for ; Mon, 11 Sep 2023 09:47:33 +0000 (UTC) X-FDA: 81223839186.24.67D266A Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf26.hostedemail.com (Postfix) with ESMTP id DD2D4140006 for ; Mon, 11 Sep 2023 09:47:31 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MVCFztXg; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694425651; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ig/SU8otDOD6RD9FAzIUrJXv86Es+SJs+TyE8glTevc=; b=LxImgOy9+C6GgSr5jyZhkoxaWnx6+xiPSNyOKxxbd51JN689chYd3H4JIQZqgGL2/v+sPA e4G9Vyc2HkcPxm2q7Q0L+rIUwIbGvfgo8Fz9xspDUZOzW4pKMHrmxAP08NPSKHlffE4x/e O+bd997DfmW9DPwA9pO84Sdl3UsiO/4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425651; a=rsa-sha256; cv=none; b=oCbF9jBl1m7PG9qrK7FwyJERIr3ljmI2tL0lEq62Uj6+D11wrHSTgpQoRxavU+eX8p2J9m ikq69vgh/14QmWnzho5Y2pZ5b1SKYyyGTLwHFAMqrF7oRe3Dirg78ZPWUpDK77NfY7PpUq zUJhNRvWUsAS55w6L9YaxcPzXEVhrl4= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=MVCFztXg; spf=pass (imf26.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.175 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1c3c4eafe95so466035ad.1 for ; Mon, 11 Sep 2023 02:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425651; x=1695030451; darn=kvack.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=ig/SU8otDOD6RD9FAzIUrJXv86Es+SJs+TyE8glTevc=; b=MVCFztXgZ+GmO4r/HgtM/ZI8Cp+atdpWVwHMM3FtgVCYCgCfXcV2p+6kwvcpupZXkW 7vj38FaG3OODbQU8yT3ZTs4O2YT72gpUOiDO6K1JS7UpRc/akAT/EumNgxn39ZXlwSoh zW7VO14cSzLWWx629+YEVpnofRIz4coGibg6lvMOZ8/DBfs5+TKWQmqRaepVzYoitRAS A7EcARreGe71Df5AqqYECMkwy0UV6zROkRY9yWrHcYSSuItsZ+Hztx7iupSHDSFrQhKE z7Ms1KHGlqdUxa9JtVrzvXDSOsPuOiTGuCxycolK4MMbwyaUgqpjdh2nJciPstJ90B0T Q1EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425651; x=1695030451; 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=ig/SU8otDOD6RD9FAzIUrJXv86Es+SJs+TyE8glTevc=; b=awug1UEwPrxruafUA0goVAnFkxHQ38CCWrAKw5tsQ50/6X4RxyiGNTGEBMbdvkFtDK S7Unyq7xT0GfAfbUDdI9t3u2+0qu/0ML6vpiqDWE4aDYmvTN+FymT/tqak32HzNmfxkg Pxk9spi5J1ZOUY7go3sUy4gQzpABMphCVbIQqsHq9UzL7mgXoOCCTS0VcdkHc8RdzQlV 2KYYTCQPrL7Ho5AJk1cbtIL2YLUVuyzyLsZQv3LjmT8Bqi51YZWP+A6AZWbPcCBo34g4 SjsflX7z6xNISczleDAPRvuXmB7NntZqRLisolmTuB7sEd8MKi+BSVdzoXmR9f3bybpo ozzw== X-Gm-Message-State: AOJu0Yz/SI8dtuMughlOf0VVu6Z2i4XiKNzvnUf+sb7jgNz5JtfvwvIL zh9VVWwvogfvjHQWFfYkm1kQaw== X-Google-Smtp-Source: AGHT+IEl2mpYTODnECMCuBDNAite2AZ131Yxo4SMEA3+9uaLlCuqsjdY37DnC78Awa2ltcDCzu5lqA== X-Received: by 2002:a17:902:d4c3:b0:1c3:411c:9b98 with SMTP id o3-20020a170902d4c300b001c3411c9b98mr11085339plg.3.1694425650814; Mon, 11 Sep 2023 02:47:30 -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.47.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:47:30 -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 , Joel Fernandes , Muchun Song , rcu@vger.kernel.org Subject: [PATCH v6 16/45] rcu: dynamically allocate the rcu-kfree shrinker Date: Mon, 11 Sep 2023 17:44:15 +0800 Message-Id: <20230911094444.68966-17-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 X-Rspamd-Queue-Id: DD2D4140006 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 6niqb3ynxe6ccnwzi81m64ipuzmf44r7 X-HE-Tag: 1694425651-968507 X-HE-Meta: U2FsdGVkX18D5sSe5gJaX8khjTyOb510rrTo2hU07e6/ZFjbEpWM1erfLkNLR4zGzI2rnFt5DGzNdXfsTswN54NTH3gRdCvekAx268KpOtBnWEM5mrAVTKmuI/zwuBx85NCFH4BxfV9W6G4VZpscyrEtsESWIMZiwfakBuIugVylinWVK/M1TdqoRCzywjdO3LbaYDdqzdxAKY6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cLWf6oqDWriiAYYzG4JmOHv/Caxrv7J9MspLzKC+pDgIdmSrUdjU0wxIJ9QoyIoJAipko+VclWSHGLpqzgpfyLWbtfaCmynH7/wlikdvKsek4LXwKRrJCKc3bSfNUxY3fqW6eeshp6TaDcE1mxlslHJKkNbMdCbN99ljBQ+cXh110GxmE3GvEoZxgCXEDlk5arg0waZJhMVW8plLmQHtFFznIAOC+r3bwF+jw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use new APIs to dynamically allocate the rcu-kfree shrinker. Signed-off-by: Qi Zheng Reviewed-by: Joel Fernandes (Google) Reviewed-by: Muchun Song CC: rcu@vger.kernel.org Reviewed-by: Uladzislau Rezki (Sony) --- kernel/rcu/tree.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index cb1caefa8bd0..06e2ed495c02 100644 --- a/kernel/rcu/tree.c +++ b/kernel/rcu/tree.c @@ -3449,13 +3449,6 @@ kfree_rcu_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) return freed == 0 ? SHRINK_STOP : freed; } -static struct shrinker kfree_rcu_shrinker = { - .count_objects = kfree_rcu_shrink_count, - .scan_objects = kfree_rcu_shrink_scan, - .batch = 0, - .seeks = DEFAULT_SEEKS, -}; - void __init kfree_rcu_scheduler_running(void) { int cpu; @@ -4931,6 +4924,7 @@ static void __init kfree_rcu_batch_init(void) { int cpu; int i, j; + struct shrinker *kfree_rcu_shrinker; /* Clamp it to [0:100] seconds interval. */ if (rcu_delay_page_cache_fill_msec < 0 || @@ -4962,8 +4956,17 @@ static void __init kfree_rcu_batch_init(void) INIT_DELAYED_WORK(&krcp->page_cache_work, fill_page_cache_func); krcp->initialized = true; } - if (register_shrinker(&kfree_rcu_shrinker, "rcu-kfree")) - pr_err("Failed to register kfree_rcu() shrinker!\n"); + + kfree_rcu_shrinker = shrinker_alloc(0, "rcu-kfree"); + if (!kfree_rcu_shrinker) { + pr_err("Failed to allocate kfree_rcu() shrinker!\n"); + return; + } + + kfree_rcu_shrinker->count_objects = kfree_rcu_shrink_count; + kfree_rcu_shrinker->scan_objects = kfree_rcu_shrink_scan; + + shrinker_register(kfree_rcu_shrinker); } void __init rcu_init(void)