From patchwork Thu Aug 24 03:42:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363449 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 99B21C3DA6F for ; Thu, 24 Aug 2023 03:46:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22B8828008D; Wed, 23 Aug 2023 23:46:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DA908E0011; Wed, 23 Aug 2023 23:46:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0A3B128008D; Wed, 23 Aug 2023 23:46:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EBF1F8E0011 for ; Wed, 23 Aug 2023 23:46:09 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C40461601A0 for ; Thu, 24 Aug 2023 03:46:09 +0000 (UTC) X-FDA: 81157610058.08.061F61C Received: from mail-ot1-f46.google.com (mail-ot1-f46.google.com [209.85.210.46]) by imf15.hostedemail.com (Postfix) with ESMTP id 090D1A000F for ; Thu, 24 Aug 2023 03:46:07 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="IiUiN/bj"; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.46 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=1692848768; 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=jbLfXpJ5k+PGfjQYbmEIBs5kJh5lwx6o5Ugx6JEi6xI=; b=1uOv89bXY0ztS89HwYM/VkEy2azSar5NNcEbjdq9FrzlGprfYIOSOiu0eNowwQQ3t4PhK1 47hgfO1LywBHYgDBvmeGNcuv3Y1xAF7FV5tY2hcsKODoGR15Z3kfVmsjb7SpwetHGNFmvF Vu1P3tG1rfeq3Ree+71dDCAkh8foNcE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848768; a=rsa-sha256; cv=none; b=dfss6X3B3aIMRzP7LzxJt9rwk7PVebMco1JjHNR0Bo4hESkxZqE932huZIiYU207oCNXXK imxstSdOO7ppOe2ab911uFezQQJuJiodQtl3tWBl67EAEScAWs4UpFK8Narfte3dPM6dwM etfdvzuEi8H7Ks6PKvTyAGZOPgau3CI= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="IiUiN/bj"; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.46 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-ot1-f46.google.com with SMTP id 46e09a7af769-6b9cd6876bbso1576339a34.1 for ; Wed, 23 Aug 2023 20:46:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848767; x=1693453567; 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=jbLfXpJ5k+PGfjQYbmEIBs5kJh5lwx6o5Ugx6JEi6xI=; b=IiUiN/bjqiAul2GXQb13RT5me6vau/bBJzSckp9JXiUe4upPQ4em6kTToIKAFTll3V Od3tGDJwfVOeeuoD7X2EdAVfF3HPWTlZ379KPWAjglBaydKVz0P1Hs1lgLWTBOah8eGj 9W2J0Tg6X9lao7+B7pf3NZT+M+RtKhGRzRyIYKpYq+oH9zZ4ysBCEvJaRnJQ2l+lgMQs g+fM8GGLrltVPCbIHCYmgNFEuprUMghQsdUn/H1ZL0iRuqXsb6LQO6t51GfVcUhEB3FE pFTkHgfMldahqqgP2ReV92FlLRtEuIRBNLkFkh+gLZcEWEOsxcxLNSMAqfjCgA5BXPG+ TcTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848767; x=1693453567; 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=jbLfXpJ5k+PGfjQYbmEIBs5kJh5lwx6o5Ugx6JEi6xI=; b=TvEqWHfTpJ+S8bF/3PG5GJfmRbc89gi9jeLdKONEuh2JhyywZdau/6E7tAVrTao5Mm Q21vpctKJXHpDEdaNQO0nTkSkJxKOFYw3b2dA9q0T0cMQIbytzeR1Oa82we9U3Bjl6VO OBXMduQGyB13HjE1IFJncqFlfqZr7wSLfDt9aqc4JjbeQnFJQpGrV+V/DancvrbFyEfx 2nzyggS09jUPBB7rvZo44rYiGRhMZlXPq91pe8Y2t+FGqcVkqBB3tNs3gFivyoC9TxlO vVll+7Fc5TMgnmxnBcaJ+jD7DrQ47JGol6j5scFwa4FZuWBSUyWvop4n9u4iiFzOmGq+ ifWQ== X-Gm-Message-State: AOJu0Yx3XKwVVJEfweWacgUEhtPpdNS2TD9dqzJnAngIV70JjNRFkoJ0 Q/q6U60jijJiDvaKwR0FMLoEhQ== X-Google-Smtp-Source: AGHT+IElYmAgq8IBCNiz5zLW6QeFhOfwrpP1ZIem3nvpFvdyyt2pB6ZEtNpkzev9+iVdtus0IhkeTA== X-Received: by 2002:a05:6830:65cb:b0:6b9:db20:4d25 with SMTP id co11-20020a05683065cb00b006b9db204d25mr16409143otb.1.1692848767184; Wed, 23 Aug 2023 20:46:07 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:46:06 -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 v5 16/45] rcu: dynamically allocate the rcu-kfree shrinker Date: Thu, 24 Aug 2023 11:42:35 +0800 Message-Id: <20230824034304.37411-17-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 090D1A000F X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 5ejcsb3uctcuz9sz5z1mpyhwa4ypmt9g X-HE-Tag: 1692848767-229021 X-HE-Meta: U2FsdGVkX1+ZqOMkFw87qtX8ccRRmcWZKG16w8F0C53JnBArOEZxPG79bfLY94a/iTDFJzsV1/jQXgKibVrK2sXC/ioQFO1qifKN/MD6oS48tE5aiHskEkwvldLrr0Xl8USg9k1zjda1pUQXj8pfXg4+uKEXjXhLrTNPkB66pPF2B3G/xIvT9vxoREW+UJ1EuaeAtsHJS7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Z+izmTMp6lSfeF5DRknHTvt/aKl5Dcfuyctq9CST08wH4UcM+XdmNo+hDRgIcRLfDkBjbRBzIdLQvHPn6Ih1NO5hluKoqD5LVLVcIkNOZGVd+L12Yeo4E2TuDLzCjNYcGzH+XHV03IJT5SeC5OsIkRe8gTlWiryZFZGReQXi882Exj5a2y6bHLWLjY/4C8wf2+XAVK6KA64lGmiU/ZX++PDje0z0yb5kW3h/uEtDv+VqivLFrT/OuB4gQ== 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 --- kernel/rcu/tree.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c index cb1caefa8bd0..6d2f82f79c65 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,18 @@ 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; + kfree_rcu_shrinker->seeks = DEFAULT_SEEKS; + + shrinker_register(kfree_rcu_shrinker); } void __init rcu_init(void)