From patchwork Mon Sep 11 09:44:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379073 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 7925CEE57DF for ; Mon, 11 Sep 2023 09:48:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14A2C6B01FE; Mon, 11 Sep 2023 05:48:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FA206B01FF; Mon, 11 Sep 2023 05:48:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EDD226B0200; Mon, 11 Sep 2023 05:48:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D8BC46B01FE for ; Mon, 11 Sep 2023 05:48:01 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B57B4B3A3C for ; Mon, 11 Sep 2023 09:48:01 +0000 (UTC) X-FDA: 81223840362.12.2DED7C5 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf04.hostedemail.com (Postfix) with ESMTP id DEFCF4001E for ; Mon, 11 Sep 2023 09:47:59 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VqbaKfB0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.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=1694425679; 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=hBwbAk8n+4/KwMrK4IB+eTsyBHwRgi9e5IimtDnToKs=; b=5/3kXUNtUSdYNKsbAZZe3ps88FmJNaWIFu37hefjPyumYRuPkUS1mOQAvPxDkGbIQEyQk3 tWX0FsuheyyXsL6+Om0UsbkpxpsGTv8Bv4xJNKITEgqTQ/N+v5WqgMClTlzBz0BE7o87Qd X++4Lnk7AtrsUgw02I6aW7We2zVxs/w= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=VqbaKfB0; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf04.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425679; a=rsa-sha256; cv=none; b=FBYUNXgavxzDQRxjTOgyWzj57vQWxJaCNRkhBSRh1q7JBlqfj0p3msFifOcP773/ETrbGN SrGFzhqWWib6XV7alniOlgJW9KHugEeS2yN9yTJpC8v/7JljogQOCqln0l8BtJg67JNLMx J1UUfkDOFdlvmWdP/Y4iV7XLdDcNazg= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1befe39630bso9366215ad.0 for ; Mon, 11 Sep 2023 02:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425679; x=1695030479; 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=hBwbAk8n+4/KwMrK4IB+eTsyBHwRgi9e5IimtDnToKs=; b=VqbaKfB0TjKGUBTjzT7m4gGqpq440TvWueN7RM87KgFRP5VxUjiWWFFiCHXSem+TY3 J63nZyQArugBeF+4u7Q+rlfklJXHTggeAJnA8oNw+ZyZDd7IU+atN4NBTSuAtitZxdGr eyUN5CJDQHFPFp4qYo/+ArlSwpzPjUYD7GcU+BjX0AtSh0PZCk6mjkZZKr+2k9uiHMBv /Zq9Kukei5YLXc9AjWMuowPM8Yug4B+MR5IoJiivAL5q0KMmb+NyGfV9BSJMbexVSID6 tdY0vqRdKzCBth+gyyrWhkLVPTcFbVwu+mm1/q7/m/IVAUKppt0p6igwDsShvCnYo8Nu ZWQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425679; x=1695030479; 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=hBwbAk8n+4/KwMrK4IB+eTsyBHwRgi9e5IimtDnToKs=; b=tH5utb7YaIc8lRSw401MXytwOCeinXiX+XhNyMG6JmG7opyDU5Z4jbbADksNbM+EMl 8XvwTZHJ/irDa2t+WxPAJ+jbgVKzIr4gZE6e/3GdZpcXrfGgWCs4z3nOFuOa9yso6Nod VfCo35DfVxZPNkLvzCFN2fCtxFymgI3lUdxd6BEYoa2o+NAT/JMzgoS5o31TJBnPDswx sfFibYsM5gOJnS6lcCSF+m3GdPgO5hC1+WrUM1e8JzgbyTmFsP3XrV7ZNDtz4LpInIzz VgUpycuckIjrs+KJNwiDtP7iUGpUDWISAMiUyKK8V1kZ8h9/EsABIregReekHdrCwkEb GtTg== X-Gm-Message-State: AOJu0Yyl7Kfl9mUoiGDbPBjoGSiloyPFYpPYRqx+uN8d7brThOTCksTC xAtLeQDEzjrPYCCo638ArXFy+Q== X-Google-Smtp-Source: AGHT+IGdro6LiLO9vRH4IIg6fznBAneFLTeHoPfwnGVLVhVa7r8b9KXvi4A+Mo8zyY74vr4cIKuVLg== X-Received: by 2002:a17:902:e546:b0:1bb:9e6e:a9f3 with SMTP id n6-20020a170902e54600b001bb9e6ea9f3mr10988406plf.4.1694425678844; Mon, 11 Sep 2023 02:47:58 -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.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:47:58 -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 v6 19/45] mm: workingset: dynamically allocate the mm-shadow shrinker Date: Mon, 11 Sep 2023 17:44:18 +0800 Message-Id: <20230911094444.68966-20-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: DEFCF4001E X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: pgp1ne5ghkifza48tjxjwwze48634nuw X-HE-Tag: 1694425679-15258 X-HE-Meta: U2FsdGVkX19SaMj53LnhhLtY4Kl+1+4asmBN7IvjZ8bj7yhL6EshOuMNnNias1oaldy/0HIMjPoJzEt7nRG1urnRPN9/4ciXdCkT1gGegtwmG5mE0252ixnAODgnwdmL62rUnDd7CEerOyQjMN6lwsvZ2MIa/s2doh7jeVX+MDFQ7yau2XAO+2SG1RNsIy+vguRTWKni7B/xU4O1x+ntkckF/Wfl9fagVc+EShK0q5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40QFQMBEX7UN+ZXmLh7uY/4heYO0W3fjy31j9gJ/E0ave5LjbpL3Nmj3vkYLcwt887NyE994otWsznM7gbOUdLek 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 Acked-by: Muchun Song --- mm/workingset.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index da58a26d0d4d..b192e44a0e7c 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,26 @@ 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; + /* ->count reports only fully expendable nodes */ + workingset_shadow_shrinker->seeks = 0; + + shrinker_register(workingset_shadow_shrinker); return 0; err_list_lru: - free_prealloced_shrinker(&workingset_shadow_shrinker); + shrinker_free(workingset_shadow_shrinker); err: return ret; }