From patchwork Mon Sep 11 09:44:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13379071 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 B6EFFEE57DF for ; Mon, 11 Sep 2023 09:47:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 567EF6B01F9; Mon, 11 Sep 2023 05:47:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53F4F6B01FA; Mon, 11 Sep 2023 05:47:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 407446B01FB; Mon, 11 Sep 2023 05:47:42 -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 2DDA36B01F9 for ; Mon, 11 Sep 2023 05:47:42 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0B52C1A08EB for ; Mon, 11 Sep 2023 09:47:42 +0000 (UTC) X-FDA: 81223839564.06.FE27F4B Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf03.hostedemail.com (Postfix) with ESMTP id 33D7F2001E for ; Mon, 11 Sep 2023 09:47:40 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Pn0C7JJG; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.174 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=1694425660; 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=G6aywPS6iXJW+BDe3k7kKZT5Ft1k56ZyEV+KzSPLpG4=; b=QtJ1AcS3j82DOqP/F1Ak9xXvWKHtaaI4U1R/a+K6EWelx9mBdjSlbm5cYu+d/lPmYcQXlc YnH26VJzhPWTJrAHa+yR29zugu87+4fteloCSyQzjhdG6JM6WT2pD2Kq7atZMTpCOHabUb j9hNsKeS+I9ZgDzfYaseO4UfCVZeYr8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694425660; a=rsa-sha256; cv=none; b=LigOl9D1IVRzYu53o4qm+MgiV8DIiLV0mMDmY0PDzmnZLFU2omBlTfOdmVhF+KFXTRcw94 m3t4NIbMwL40yMxP5Y/S7SkpaUqA4dt4KN/+d/yJtjG2yFCz84kpysGWWW6q/Ty9tTBeuS Jd1gajCcw2bAMBHrwtiQwU91QmqpKjA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Pn0C7JJG; spf=pass (imf03.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1bf11a7cf9fso7700315ad.1 for ; Mon, 11 Sep 2023 02:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1694425659; x=1695030459; 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=G6aywPS6iXJW+BDe3k7kKZT5Ft1k56ZyEV+KzSPLpG4=; b=Pn0C7JJGAgcSf2JKcMgWYvpodi/YwA8vh/l++qxLDqKSv6V3lAz+WWm/5p/vQEDIRi BORvopGa0d/f6z/xvuChlJydN5ddjTr7/EV26ZpHZkM9bxi0S73teFUnRu3SY6c4VZh6 qVpbZ/zwwU6jFuY/vFo9Ng3C9EzkSgffAW5H9kNgnk+2+kMwd9woy/1qvMXQZj014E0N jMwYCzRZQN6aVopRL5N4fZE0u+UA6EAZDVQTiIzeoReg2pLDPW53tFGEyT8KJcux7TMr wwoTxuaEdUPtc91yKIUgeyBOqoqVNOM7hVM05FaHLqVrT2CBDUsq7XR7uDwnKRyTcwmA kvog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694425659; x=1695030459; 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=G6aywPS6iXJW+BDe3k7kKZT5Ft1k56ZyEV+KzSPLpG4=; b=a9iElZMqk2h2aJ1YJrENA2B98qm7968hePxhCr0hqDWNLookA8xhKFhUXmVy6SdHOV YRM0sNg8ciynZ4PfdscpimHVX7d9Tc73vZVA5UnrKa11eq6PkKj0W0EqEI4fiAt/bRJF +PKMJduLBbiS3NrmR465BUUFvde+Lpiget7gl7NIHWowRYh7wjtiFlZvtzFA+Gs6/ZCN f/JnkGDB6HoGktFOb0/w6HuB9iZKY884qFLqIrVj7Lv/mkJhiPCo8m1FaB+mLh0hSOy5 h7ObLSfDKGT/OQaXQjn+pJBiyxF4XhYDYj8gukl8S+xlw9BK8f9ZXsxHeE4JDPrSdVgs GgiA== X-Gm-Message-State: AOJu0YyaENwtlevPGUOsoZMF1rFjJbrHV2dAKzGqaCdxVNIR35Rer3ZQ 5IoBU5XidT7odWq9ZYDAtIkTeA== X-Google-Smtp-Source: AGHT+IH2KVNM9Hi/PmmKcKS4mr3sE9GLoL02lCaa5Z7/hioPtgcvnrY94ZAiH3SYey8unqQ3Icvz8g== X-Received: by 2002:a05:6a20:4401:b0:140:ca4c:740d with SMTP id ce1-20020a056a20440100b00140ca4c740dmr14470391pzb.4.1694425659098; Mon, 11 Sep 2023 02:47:39 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Sep 2023 02:47:38 -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 17/45] mm: thp: dynamically allocate the thp-related shrinkers Date: Mon, 11 Sep 2023 17:44:16 +0800 Message-Id: <20230911094444.68966-18-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-Stat-Signature: tsumiux5mj1inai5d88pcuuds7bx1rxh X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 33D7F2001E X-Rspam-User: X-HE-Tag: 1694425659-622439 X-HE-Meta: U2FsdGVkX18OloMShyYu0/j06px+/+c0CVVBxGDcOAXww73sVjMoUr0OyLNZm7rsEeZsnb0m3lrYlAOWQjG3Ultuy9iCew6HsLr5RxxseWhYHAARWA7GJkyvyIK/R/PLnCOnyDmuF+afRmR122Pyz1l4GK0f6zW5lceiuLx8+cbKqPDdDJs5NaowJBD535VdkQVRg+QEW6JHYQ2ebdd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zMWJZ92X7reVubLxNDFNlHofTwFjasoBOLaQEWsuUl91IzTIRe6BnEhackKi9+ISP9hRcF35p2udJi3Mw7fTr0ZnHvLPMI83JPGPRxgw4kMeelxtH40LvlP2oSHFJLdTc 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 thp-zero and thp-deferred_split shrinkers. Signed-off-by: Qi Zheng --- mm/huge_memory.c | 67 +++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 064fbd90822b..1cfd83e91748 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -65,7 +65,11 @@ unsigned long transparent_hugepage_flags __read_mostly = (1<count_objects = shrink_huge_zero_page_count; + huge_zero_page_shrinker->scan_objects = shrink_huge_zero_page_scan; + shrinker_register(huge_zero_page_shrinker); + + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; + shrinker_register(deferred_split_shrinker); + + return 0; +} + +static void __init thp_shrinker_exit(void) +{ + shrinker_free(huge_zero_page_shrinker); + shrinker_free(deferred_split_shrinker); +} + static int __init hugepage_init(void) { int err; @@ -482,12 +514,9 @@ static int __init hugepage_init(void) if (err) goto err_slab; - err = register_shrinker(&huge_zero_page_shrinker, "thp-zero"); - if (err) - goto err_hzp_shrinker; - err = register_shrinker(&deferred_split_shrinker, "thp-deferred_split"); + err = thp_shrinker_init(); if (err) - goto err_split_shrinker; + goto err_shrinker; /* * By default disable transparent hugepages on smaller systems, @@ -505,10 +534,8 @@ static int __init hugepage_init(void) return 0; err_khugepaged: - unregister_shrinker(&deferred_split_shrinker); -err_split_shrinker: - unregister_shrinker(&huge_zero_page_shrinker); -err_hzp_shrinker: + thp_shrinker_exit(); +err_shrinker: khugepaged_destroy(); err_slab: hugepage_exit_sysfs(hugepage_kobj); @@ -2828,7 +2855,7 @@ void deferred_split_folio(struct folio *folio) #ifdef CONFIG_MEMCG if (memcg) set_shrinker_bit(memcg, folio_nid(folio), - deferred_split_shrinker.id); + deferred_split_shrinker->id); #endif } spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); @@ -2902,14 +2929,6 @@ static unsigned long deferred_split_scan(struct shrinker *shrink, return split; } -static struct shrinker deferred_split_shrinker = { - .count_objects = deferred_split_count, - .scan_objects = deferred_split_scan, - .seeks = DEFAULT_SEEKS, - .flags = SHRINKER_NUMA_AWARE | SHRINKER_MEMCG_AWARE | - SHRINKER_NONSLAB, -}; - #ifdef CONFIG_DEBUG_FS static void split_huge_pages_all(void) {