From patchwork Thu Aug 24 03:42:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363450 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 02CDAC71145 for ; Thu, 24 Aug 2023 03:46:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CB1428008E; Wed, 23 Aug 2023 23:46:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 97BE88E0011; Wed, 23 Aug 2023 23:46:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8437B28008E; Wed, 23 Aug 2023 23:46:18 -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 72A9D8E0011 for ; Wed, 23 Aug 2023 23:46:18 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4AE49401B4 for ; Thu, 24 Aug 2023 03:46:18 +0000 (UTC) X-FDA: 81157610436.11.ADFB8F9 Received: from mail-qv1-f48.google.com (mail-qv1-f48.google.com [209.85.219.48]) by imf10.hostedemail.com (Postfix) with ESMTP id 54DF3C000B for ; Thu, 24 Aug 2023 03:46:15 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="Q+jrV/hG"; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.219.48 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=1692848775; 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=tX52Pl2ixlte2DgzQshaqIg6eWURIO9mWebQRHEbYyg=; b=XmvOZsmpwEy3DNzeB+rDGAjT535gc+gfeMiS9DNB0dNDLBZtmcE5Euxv/Zx4eKC5BuGRVf LoGwvs82oj+roFnQ1ayX5/V+i9Jb+1Db4R3KnO87zPLlNq6385ydGWHq07kzerOWvpm6uD XxPdmn3qIgXyEE161ClWYz0eWhieBaM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848775; a=rsa-sha256; cv=none; b=iC8Yjocfy45k6WLhfM/TN2pKp6r40P2HPHfCW2CPKBBopIGdMjMMjsrN2l1/xQpYa5wCDN BFJbFUyLDCH6/J4xrRLHj1ptcRzAppsuwHDO0jFrMIhmv3LFCMlPsJUFDEJdtUlELNT8I+ 3k0q/Jy9tbGKaQDRO7Z+wB0dI4J6Owk= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b="Q+jrV/hG"; spf=pass (imf10.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.219.48 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-qv1-f48.google.com with SMTP id 6a1803df08f44-64ad88fb05fso13533086d6.1 for ; Wed, 23 Aug 2023 20:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848774; x=1693453574; 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=tX52Pl2ixlte2DgzQshaqIg6eWURIO9mWebQRHEbYyg=; b=Q+jrV/hGwdEttsGppUy814f7YoNw7WLWERgtsHAz86kQBKxj+TwydnndBa3fx5Mojy ECKGkzHYTccZTk/ju/rx6/0rBO0AWUyJrxTf4tLFtE0NCnjpFETXw7W6EA4c5z8dmmI5 Mzd1L79nvDcVnmA/mp+Mr5AM+IOB8WlP1Md/ZoMBn6KxpJSqr2P0bUsWrRAqdA3HaOVb rXZNiWvWtEzgAe28hRTsBN8wfqOr+4cyoG8c4tVvfgtjY+g8QdJJrjn4Sd/SAgoEdw5l Pg6JoFXmZC6Y4NP7c/E9oJrpfxykw6pyY7UCaE+cUQY/aKOjEPVGg7IEt5P1HJPUslAL g5PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848774; x=1693453574; 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=tX52Pl2ixlte2DgzQshaqIg6eWURIO9mWebQRHEbYyg=; b=c3zc+aRGR1/V/aBi+iBUROFuwExFy6mlRlB86SrIkSInSFWavXlhQHgGfaEArUL0DC YYilB5Paa070rcF9Ws1mOx6U2Urow+DIXKIGI1g36xsYLbj9kdcnKTHA4JahSMArL7PF lIp3ItAT6Io9jlMz4+gWqyozhpGOwiwLXqT+fcoP24BUHXS6t8yuuGYHO341bhzj4srX MIBiQUwVNAdaM/34Ft+/mAq7YNzKwAjm6H6pQD8dC1f7UExFQg9QItDrtEPf2aDh82mx mXpvfJyzHZpS62dynSvUXQNyf3uwvjgrbFCB7OrQMHDurPOS8FPV2wwBJZwPUjfEhlFN 8rJA== X-Gm-Message-State: AOJu0YwOLLCmd0ZfjlFj1kVXUslniC1aOSU/qRdFbp/nHtxhZpikQTTY lZO/3hvBSVxj1c4AzxhsW+TV8A== X-Google-Smtp-Source: AGHT+IH/giC2LTn0MvvTP7+hN9g6irIUBPRUUI2oOCQCQVh9on93KM4yAzkZ9PUzh/cWTAn10rsxmg== X-Received: by 2002:a05:6214:501b:b0:635:e528:521a with SMTP id jo27-20020a056214501b00b00635e528521amr16845477qvb.5.1692848774439; Wed, 23 Aug 2023 20:46:14 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:46:13 -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 17/45] mm: thp: dynamically allocate the thp-related shrinkers Date: Thu, 24 Aug 2023 11:42:36 +0800 Message-Id: <20230824034304.37411-18-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: 54DF3C000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 6c3o95i8ua5k1558w5r4h1guz17gmcac X-HE-Tag: 1692848775-357020 X-HE-Meta: U2FsdGVkX1/0osaC02chZ4L+MgSvC6GfbyBZIl0GCcb6HZZb088Aotc5LNU1l/FMC4htwlLb+eoDK4K6SSq8+zQtWJ9Ug6o2LjPtiynlSh5qmPJwYWQ+S12sNFVOtbMJRRhnLs2m6lVP7QovceHTcgkKDrOiLmXkg3+1AIdhgzMmmxfMga1VAmGT+Fm9oAJASy4N+I8c4ir52ltOGNAWdCEIP+CMXqymYHNZIVsFLW5V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KioXJGa7gTHMRXvzLPgu7OPOgc9PjEMhKMlLsxgm5nq/q6jeK2j/R9TilwatvfScjXqHOfkruL914ftaYlul2CA2ykYRBGx52920MzaDUO5QKvtIpvF 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 | 69 +++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 3e9443082035..3c9c692e3376 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; + huge_zero_page_shrinker->seeks = DEFAULT_SEEKS; + shrinker_register(huge_zero_page_shrinker); + + deferred_split_shrinker->count_objects = deferred_split_count; + deferred_split_shrinker->scan_objects = deferred_split_scan; + deferred_split_shrinker->seeks = DEFAULT_SEEKS; + 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 +516,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 +536,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 +2857,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 +2931,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) {