From patchwork Thu Aug 24 03:42:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363452 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 966BCC71145 for ; Thu, 24 Aug 2023 03:46:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 389CE280090; Wed, 23 Aug 2023 23:46:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 33AD88E0011; Wed, 23 Aug 2023 23:46:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 20234280090; Wed, 23 Aug 2023 23:46:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0F48B8E0011 for ; Wed, 23 Aug 2023 23:46:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DFF99B1918 for ; Thu, 24 Aug 2023 03:46:38 +0000 (UTC) X-FDA: 81157611276.26.49052A7 Received: from mail-il1-f178.google.com (mail-il1-f178.google.com [209.85.166.178]) by imf15.hostedemail.com (Postfix) with ESMTP id DC6C3A000A for ; Thu, 24 Aug 2023 03:46:34 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=NcBMtAaa; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692848797; 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=uDu/4z0sff3MNLq2Hem41DvJLtW9HR7Ht2OY0+o3IBw=; b=Nyw8PJRJOg9guWWtvwd3Jn2HFdj9T3QdN9VbBOM+2BwZhuR9QJx64m9x2WPeeOqRioh9/v cEX1JCjt/QXFUksA5f/M7SVIx4rdSxeN0rTNwDF1j+zDkIU6bZQjutnT8vXNlFvYlowS6C AUmZLNgXYt4oMV/rcOxLwztP6pWyDQo= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=NcBMtAaa; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf15.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.166.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848797; a=rsa-sha256; cv=none; b=mqYn7q6PxWmzZhUxLmyn4k/6zV9mCBIMN17KOaSv/2Gj73XiS57cNdGupH7vzmWlsnTrfr zxaddu3w0grFPhFWPkLR+reUTVuYREiWccX7BNRneGesW8G+FUkf0AXwhq5py8WDyUXhe8 y4u2IdYkmW2K0iDH1yj3PSecvY4fbbo= Received: by mail-il1-f178.google.com with SMTP id e9e14a558f8ab-34bbc394fa0so5580505ab.1 for ; Wed, 23 Aug 2023 20:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848794; x=1693453594; 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=uDu/4z0sff3MNLq2Hem41DvJLtW9HR7Ht2OY0+o3IBw=; b=NcBMtAaaLE0r3U9cq1G5ArkW7KseQfBeg2oIVpo0zwEHj2pxIXv396lmpHWvqNY6WL JjyXJcQ+71rZjpvUyUbfQ8TBZw5eC/hpC4SZQrI5yyx8ZDcSfC61r6xS0cAm/1P5jMWZ mkFz/DOMsozI6+D11/YuxeVQCAHIevBxkzEmHriraQYG91HLeEL/u8PL5wK3f8VZRjuT cz8d/r+S9nMPLi5iQaiL+tTIS8oLRmffsx3mniOICQT+h1azffq4WqSFD7IduUw5wFnG KASaAakXH9kG67rUD+T3XOhVhqWNxRqdqrYEnF7FkbsAyj3LDEWSCHCaKrbISFen/hwS Jp2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848794; x=1693453594; 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=uDu/4z0sff3MNLq2Hem41DvJLtW9HR7Ht2OY0+o3IBw=; b=bWXObE978tOzygUhkfTP17D+iYdyk11rKNtxqUNICgp0powT4IlU8IjpdAi+3jKRhM biTpdptyHRaeRZhpCL99/gD/sfn3W75QrcqNRRky4PxkDVj/fQj1su+4Q6YCJ6OH+k+Q HqaAbdpTQSYwjTNC3R1ZC6J5mC4nsHMEwBggzNEIQJfNGAvbovFxahqAQygtn16N+fz9 j7M0ddQ9rZUc/EfEdMv6hxbmIx1ja5lqhBmoKG7/VKuXXicVSed2VTrNuc4Y7lNFGndF 2S3qlGRtwyN1qizXBEWjKDSQ2rpIjlKWNgb35f0wIZFWHfjQv6vjXAh8e5ye7vs1zaqI PzWA== X-Gm-Message-State: AOJu0YxFeWPydli9YawARnJ+Pk80LL02n/FXxgc550mDERkFbK0S9YWW C+KPgDtqETIH6VkNseFAjUb16w== X-Google-Smtp-Source: AGHT+IF6gasrupmNMEd6iGY3g7E0ID/cc6G3nenUlRac5+F8aF1f3dod8FyRICkvmINEgAPLaLvdgQ== X-Received: by 2002:a92:c90c:0:b0:345:a3d0:f0d4 with SMTP id t12-20020a92c90c000000b00345a3d0f0d4mr15091049ilp.3.1692848794044; Wed, 23 Aug 2023 20:46:34 -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.46.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:46:33 -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 Subject: [PATCH v5 19/45] mm: workingset: dynamically allocate the mm-shadow shrinker Date: Thu, 24 Aug 2023 11:42:38 +0800 Message-Id: <20230824034304.37411-20-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: DC6C3A000A X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: atcgjsf8gyh87grpcxa7spfjkpg7wrsi X-HE-Tag: 1692848794-789981 X-HE-Meta: U2FsdGVkX19CLV1KPIm4iZpCKhWYZmIoXB0rjSH6jV185Fz8Jg5mHahmKDHjAr0IwjiyXSCuEIEC8gCjuptK+wG/5K+9xcrmKHWNShV8FdeDlEL2x9R+xmsp1nkJgMKJ15WRMr8Nigimlk+l5jqumkYPi95V9KWfhE3kNgME6YSYDOqR1hRfAYOMb1PyF/39aqY4IntU5gcDyA27SSTT1px6KjMC3KyOXwECC1gzKA9ydoTl4x/dvuc4+iTxoR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WalcvJybrUvIqf3rfYIr7GHpvkw/fM0kDbGcOFe0A761ewG1L2r+UQ8+Wk5VgvIavRY+z9mj 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 mm-shadow shrinker. Signed-off-by: Qi Zheng --- mm/workingset.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index da58a26d0d4d..3c53138903a7 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -763,13 +763,6 @@ static unsigned long scan_shadow_nodes(struct shrinker *shrinker, NULL); } -static struct shrinker workingset_shadow_shrinker = { - .count_objects = count_shadow_nodes, - .scan_objects = scan_shadow_nodes, - .seeks = 0, /* ->count reports only fully expendable nodes */ - .flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE, -}; - /* * Our list_lru->lock is IRQ-safe as it nests inside the IRQ-safe * i_pages lock. @@ -778,9 +771,10 @@ static struct lock_class_key shadow_nodes_key; static int __init workingset_init(void) { + struct shrinker *workingset_shadow_shrinker; unsigned int timestamp_bits; unsigned int max_order; - int ret; + int ret = -ENOMEM; BUILD_BUG_ON(BITS_PER_LONG < EVICTION_SHIFT); /* @@ -797,17 +791,24 @@ static int __init workingset_init(void) pr_info("workingset: timestamp_bits=%d max_order=%d bucket_order=%u\n", timestamp_bits, max_order, bucket_order); - ret = prealloc_shrinker(&workingset_shadow_shrinker, "mm-shadow"); - if (ret) + workingset_shadow_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE | + SHRINKER_MEMCG_AWARE, + "mm-shadow"); + if (!workingset_shadow_shrinker) goto err; + ret = __list_lru_init(&shadow_nodes, true, &shadow_nodes_key, - &workingset_shadow_shrinker); + workingset_shadow_shrinker); if (ret) goto err_list_lru; - register_shrinker_prepared(&workingset_shadow_shrinker); + + workingset_shadow_shrinker->count_objects = count_shadow_nodes; + workingset_shadow_shrinker->scan_objects = scan_shadow_nodes; + + shrinker_register(workingset_shadow_shrinker); return 0; err_list_lru: - free_prealloced_shrinker(&workingset_shadow_shrinker); + shrinker_free(workingset_shadow_shrinker); err: return ret; }