Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp775627rwb; Wed, 26 Jul 2023 02:40:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlHaGTAGdx/klnD9/TYzdu/UqnAjc3/Kw/kacrBYTSp8mTQjtC0xW2SKzIDt/KL15/WTYgOb X-Received: by 2002:a05:6358:9392:b0:135:499b:a68c with SMTP id h18-20020a056358939200b00135499ba68cmr565370rwb.8.1690364429113; Wed, 26 Jul 2023 02:40:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690364429; cv=none; d=google.com; s=arc-20160816; b=OS+TjV/Ot/flqMAjVtudIzSEj5cv4VaoJFhPCpfiFgdh/B6wMWFHDGNSeqMfz+YNq/ qlYrerAxxVasf8XOWekU0RnEZagna8nLveMgrsVuWwGrJCm+OMLMVYVAjaYz+IaS7HR1 w3QplB86H4hRpdPOgiacKCCc6oa9J/QTjxtlMu+aeMuH3IrObSMJe1Tk7kglxSViq/fs efNOc1PpYzEDP6ClHXrBtbvcuGlvR82Yq08gnng7MQPuUK1chn4IxWGgySDlLn1SQGM+ wmHBr12HeAfezj+snpZQ1TpFHWPASysKrX4DyUEcqDSG89Qx2Oh0E1k5BF1Dnq7d0xID HjSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=3q/836hkNQMpcz/8YX2aFfQHacV0FqcsnRX2KDKmGK4=; fh=1tw537HxJj8QfRGQ31nxiSonTz8q3rJnaObM9GVPiPs=; b=xNQFOqOrL5u4+v9ny5dY8Kqh54dNXo3IvhF7caoQCvA6iHHbIcuuyNrVkO4oFIqoU7 lscyp0ytvF72gyCjkdcVLi76SMZS1kMvXg7f6coUrbJgjcLCnpHJ2liLVFqhZpafxJWX wjVj3Gf9IYBD+VrtW9kVpHdswL/69+KeGqLooBPp2G4gN++t4q3T8gaTaKHuqRwdyz9f cBUNag5wxrqxd1vEpCLpDRiXUEHCpSGSN2V4GxUXQjE/u+SjbxrBLatm/Uo5tvzzefhh Z17don3TY4ZZw0NDPsgv8Iao41iuzAGkG91KKgcbm0wyIO6uT7yN9KfrvfrK3geO33Rn qprQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=VrX61tol; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 u11-20020a6540cb000000b0055e607f1e99si12738768pgp.882.2023.07.26.02.40.13; Wed, 26 Jul 2023 02:40:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=VrX61tol; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-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 S232132AbjGZJ3r (ORCPT + 99 others); Wed, 26 Jul 2023 05:29:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232182AbjGZJ3Y (ORCPT ); Wed, 26 Jul 2023 05:29:24 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED11210F6 for ; Wed, 26 Jul 2023 02:28:01 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6864c144897so1488723b3a.1 for ; Wed, 26 Jul 2023 02:28:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690363681; x=1690968481; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=3q/836hkNQMpcz/8YX2aFfQHacV0FqcsnRX2KDKmGK4=; b=VrX61tolI6lx5cf13TzjBUi7Jr7lyRI0PErux25Ugwzya6Gr7la8Z5mF2+cskv3TWz UBVd0Z5Poj3PRTux8odPv45l8gQzAXnTFOr3Tf8UDx7d9uUEKzN37AEVIKYy6agrhmgA YruSiWL83SB/lZ95d/ocS5Ez1ClN1w8sLcjpu26a2KNj8aWhEC89NaIXAD4IQeJcJzfH uYL7oLGt6F17I0XKTtTRSbeLX7ktBDSzYJstMwVG/599hz7kBf24kzbOMqBXrGbap2ZR iYE22Dihl4RYEd6b6MxzHd9sXrRhtrB75dhklT8m88pkRrstmkcW4eCpJX3cURQ8vJOi rydw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690363681; x=1690968481; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3q/836hkNQMpcz/8YX2aFfQHacV0FqcsnRX2KDKmGK4=; b=NKAJ1evDR6kWGuarkSlYVRcYWeNMR209ktaMcIvMVrT1OvscwR0zR3O3or5tZBQGQH 9icauCU5mojcnyaZxp+vnd9aPjaZg6/Jm6n15QV4GuxLPoNybDggRhmD8E39Q3dNynek Tze2AK72fgVGa7gZz10VSV8eK1yOTTmoN3o6dQfI3x/2tBkecaxzlQUfjxN23lz4g3M3 jX3+J0pRFkmuyFSxAr8AmDhrKop0xaYKt+/HjOozJCsbWZK43V3hJFejlq08Vw28oOSp VhunhA/CSjbqPbKS8e/DikzgTa8FA5lJ71wk1lXlUJE+Pugp9s6XSDDQqkmvLUAhgo10 LkKA== X-Gm-Message-State: ABy/qLY1vJ4OT/Toy207XazBKFEVMX+7wzf/sBPEaDM0V1Mx6eYGK70E 0ObfRmXfgrrjywmXcsim3HsaNA== X-Received: by 2002:a05:6a20:3c90:b0:134:d4d3:f0a5 with SMTP id b16-20020a056a203c9000b00134d4d3f0a5mr1941746pzj.2.1690363681365; Wed, 26 Jul 2023 02:28:01 -0700 (PDT) Received: from [10.70.252.135] ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id l73-20020a633e4c000000b00563da87a52dsm1901427pga.40.2023.07.26.02.27.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 26 Jul 2023 02:28:01 -0700 (PDT) Message-ID: <665ccd89-8434-fc45-4813-c6412ef80c10@bytedance.com> Date: Wed, 26 Jul 2023 17:27:47 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [PATCH v2 19/47] mm: thp: dynamically allocate the thp-related shrinkers Content-Language: en-US To: Muchun Song 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, 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 References: <20230724094354.90817-1-zhengqi.arch@bytedance.com> <20230724094354.90817-20-zhengqi.arch@bytedance.com> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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-ext4@vger.kernel.org On 2023/7/26 15:10, Muchun Song wrote: > > > On 2023/7/24 17:43, Qi Zheng wrote: >> 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 8c94b34024a2..4db5a1834d81 100644 >> --- a/mm/huge_memory.c >> +++ b/mm/huge_memory.c >> @@ -65,7 +65,11 @@ unsigned long transparent_hugepage_flags >> __read_mostly = >>       (1<>       (1<> -static struct shrinker deferred_split_shrinker; >> +static struct shrinker *deferred_split_shrinker; >> +static unsigned long deferred_split_count(struct shrinker *shrink, >> +                      struct shrink_control *sc); >> +static unsigned long deferred_split_scan(struct shrinker *shrink, >> +                     struct shrink_control *sc); >>   static atomic_t huge_zero_refcount; >>   struct page *huge_zero_page __read_mostly; >> @@ -229,11 +233,7 @@ static unsigned long >> shrink_huge_zero_page_scan(struct shrinker *shrink, >>       return 0; >>   } >> -static struct shrinker huge_zero_page_shrinker = { >> -    .count_objects = shrink_huge_zero_page_count, >> -    .scan_objects = shrink_huge_zero_page_scan, >> -    .seeks = DEFAULT_SEEKS, >> -}; >> +static struct shrinker *huge_zero_page_shrinker; > > Same as patch #17. OK, will do. > >>   #ifdef CONFIG_SYSFS >>   static ssize_t enabled_show(struct kobject *kobj, >> @@ -454,6 +454,40 @@ static inline void hugepage_exit_sysfs(struct >> kobject *hugepage_kobj) >>   } >>   #endif /* CONFIG_SYSFS */ >> +static int thp_shrinker_init(void) > > Better to declare it as __init. Will do. > >> +{ >> +    huge_zero_page_shrinker = shrinker_alloc(0, "thp-zero"); >> +    if (!huge_zero_page_shrinker) >> +        return -ENOMEM; >> + >> +    deferred_split_shrinker = shrinker_alloc(SHRINKER_NUMA_AWARE | >> +                         SHRINKER_MEMCG_AWARE | >> +                         SHRINKER_NONSLAB, >> +                         "thp-deferred_split"); >> +    if (!deferred_split_shrinker) { >> +        shrinker_free_non_registered(huge_zero_page_shrinker); >> +        return -ENOMEM; >> +    } >> + >> +    huge_zero_page_shrinker->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 thp_shrinker_exit(void) > > Same as here. Will do. > >> +{ >> +    shrinker_unregister(huge_zero_page_shrinker); >> +    shrinker_unregister(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); >> @@ -2851,7 +2880,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); >> @@ -2925,14 +2954,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) >>   { >