Received: by 2002:ac8:45c5:0:b0:405:464a:c27a with SMTP id e5csp997018qto; Thu, 27 Jul 2023 01:22:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlEigY/Y2d4pXi1TxmncmEWibot+zJT1L22p+R0DRnrn/SlR4wGeNQSL79IsyN2i/VK5KBIM X-Received: by 2002:a05:6358:5915:b0:135:4003:7851 with SMTP id g21-20020a056358591500b0013540037851mr2478309rwf.19.1690446133032; Thu, 27 Jul 2023 01:22:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690446132; cv=none; d=google.com; s=arc-20160816; b=FIIwg0zQAV4cphTgU30aH4uLdCt6+/4S6eMoTy1LwZ8rJMPUKvktVwatDj/clsXerE AFITBGKUXp/5SiOTPp+yoa0nD/T5YhC+WdMbMwZb4c4+8zrffzxNx2Uw19yxUpu9hQFc HJuxZdyF7lQTUEEZvGIPfTk315tsGX3KSHlo4YrxXgYbtI2zZ8MkzfIkfpCIc5Z8y+5h zTvdSkrtdvboWRGEY/ocIYiGML/+EYkqbl0MkdK0TlLk1Xgoupx3CzNcIWM2H6Zzyltq zMQqs92cb8naG4g0lfIUMQKIFQE/S5s3QSCxPJoa2h8rxytbvw1czU0UQn1izBfqrW9L AMHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zAZIQD5LE19JLWIPx8KiiULhQHk9tWBr8sqfFcta/MI=; fh=3lDHiAuENCYj3gWFb2bYij2cH/UC7c23rwbOpuSBNc8=; b=k27q6cPIgRGh14NoIGeFmCPRXUJByjjvE0ta+2tFy6WhPhgOMRLjeIMPJDOaBlP4Nj 1W3pz9qIoN6r4vCNYsKXV9VdZwGAA16OzhwSbPL+MD300iMGs/Zlpu/NeLcDR60S0Al1 6By4SPv/IfwXo7/3KNaByb4ZyID5MNwr8GSJG1aG+xm2yc9C0xzOpSNl9JcRG8sgMd8m JShGpBZTQCDswi+FqF6EcW6sbwPE8mxQOp0wOLq6YujlK6iLJoP7sReHYHgsanM3RR5h rIxbtcOSVgHQGGvsn7V9hwDMdNmwpebzfUgAnEpkh2tO2e/H3IAFAu7h6A3PPvDs+uWr dGjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=NqYwP+7q; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d11-20020a63360b000000b00553c2f85085si926016pga.220.2023.07.27.01.21.58; Thu, 27 Jul 2023 01:22:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=NqYwP+7q; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232954AbjG0IUY (ORCPT + 99 others); Thu, 27 Jul 2023 04:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234199AbjG0ISk (ORCPT ); Thu, 27 Jul 2023 04:18:40 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5191F61A3 for ; Thu, 27 Jul 2023 01:10:44 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6748a616e17so183053b3a.1 for ; Thu, 27 Jul 2023 01:10:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445405; x=1691050205; 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=zAZIQD5LE19JLWIPx8KiiULhQHk9tWBr8sqfFcta/MI=; b=NqYwP+7q26BX+05EQAE55Kus0VTZ4uDrn8hA+JsQeQZJT9fqe02P3PtEqTbWL+ex0x YIFFlprB9LN8XpWOyzBWvs6bF2o1el7zRiKvHm2Vd5z2Or8QA2PiX1E8ylBDH7Szeeh9 /iQcvqB1l/KdO3epgECrqpXSIR/s/RJamq92lbZYEsjapR5/FUExLIHgiZunap4eHVCx zA39TmQ89NL3AupWiP9iOshQQO6k89rLp1YMDCuDF8tqw1FNGVEm51b05cxcsW4A6ycO oxBBen2ORAG64Kh5EsfwftGMbRswk1n9HcylImCxbc9GAVmkCHyiC5Q0TKVbaeRFnqta TxEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445405; x=1691050205; 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=zAZIQD5LE19JLWIPx8KiiULhQHk9tWBr8sqfFcta/MI=; b=AfKaC7kIOnDj8xOsktm/WPS625/9Ozddvf8slt+x76yA+oyC5/R//lvwdVwY+W9Vo4 g/zb+GcF41KDCK0C0NmqC94d9FRrDuKAQhXG4j2ZKh2L7e5ihJH7zTBGX3ZUVC05W+Rh sJeG4fXa6URdxQ46LcOF8RO4x6NYrYCQiMPZefTHjq1jkxVem+63qHucqLBi8kTATXsa UEieKVW0lufOsNDQwY1X/wAQzk5qGgcMEpzYevAqGyqmSqGx7o8tGUpKrxmvCIiz5g49 a23dl100zOIWLR8sadp0FwXx5Nae7hYZnWinv6J/L5fh40jRZ9lVMlsgi/uG5rqHJNgl zUsw== X-Gm-Message-State: ABy/qLbRvRqIJFdJM546gAQUPgryDwI7GhbhkYy+rp73tg7WInU6wCSc jrOL8HcZueWFKPXUbkrH7Em8Gg== X-Received: by 2002:a05:6a00:4a83:b0:679:a1f1:a5f8 with SMTP id dr3-20020a056a004a8300b00679a1f1a5f8mr4623296pfb.3.1690445405268; Thu, 27 Jul 2023 01:10:05 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.09.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:10:04 -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, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH v3 21/49] mm: thp: dynamically allocate the thp-related shrinkers Date: Thu, 27 Jul 2023 16:04:34 +0800 Message-Id: <20230727080502.77895-22-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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 e371503f7746..a0dbb55b4913 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); @@ -2833,7 +2862,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); @@ -2907,14 +2936,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) { -- 2.30.2