Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp673824rwb; Wed, 26 Jul 2023 00:29:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlHm3xDhZnGQgzeqCeDfDsLvLGEg031R5ylZRrj71mYRz+T500HlTTcuiJ8Lv0HqO5jGBvpG X-Received: by 2002:a17:90a:d482:b0:268:15da:44fe with SMTP id s2-20020a17090ad48200b0026815da44femr942434pju.14.1690356583399; Wed, 26 Jul 2023 00:29:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690356583; cv=none; d=google.com; s=arc-20160816; b=j/4LP2R8ORwT7u5M8/pUDzCWAzWqe6dVAfuUJVhgLG3CvQi9+aB+hLUOI3ZjbzrfGU UQmLyJ7ESa+HjZuVoiNOY5xT3pRB5lL4YVT24pcODjhaD2XW1rxiYqdr9k4L2m7Fzywz hdGf5sEGOHWQhehv2hnbT0mCFgPmiq4yz9RkzKXk4np4aPoH0HB6YT7o5HdwtvIf7AdA Aw9YcyKozgKYHT2OHfZ9pDZ6ILi8gQD4ZDC63qZBmaMmvKTxic54WgSExRZ/h+iCUUCe hBf/vBoSZqR3W6OClKwgk7sC5X1OrDtGE+tKmE6FQN0OKTTEOG/2HhYPPg3k/dwU37c1 eLeg== 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:subject:mime-version:date:dkim-signature :message-id; bh=Jvc7jyiFGsEgqDLQ8SvDwKCvjECMcl21zak/YPsttTU=; fh=2aXCQdnPCRGWbb3+3TWBb4ivLG2Pbs4VxrYTn6yMgTk=; b=v7XniSHef7XrnqL1J+3NgLA6vCtmgOAM0VwT4yenoIDaCetHQOAm2Qyseptm3xkRKA O75T2ojFAwf9igD72HMlT3pwpWS2mUk/29y2RZVa3XyWM2LwX4RI20S57LpoehRFKcew MXZa4p461A3YsL5drqOB3Ys+p/JxbqLfy+ie/Sky8NdABs5RbSy3K2EtMEzvKSuuqPz4 Qiir3q2fwscawI7xamcCvtj773fg4gq/lINVhe0MBE5pDxBgV2U/VC/gaAUY0T74eF9E s0DreH+rTHDtBkcHm9gFh4Dl2tWV1MXqumxYyVKl3qc5WwtFlrHPwj9U5c2jP35iZIyo fBrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=MJNzwcgK; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t33-20020a634461000000b0054fdc588111si12804823pgk.438.2023.07.26.00.29.29; Wed, 26 Jul 2023 00:29:43 -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=@linux.dev header.s=key1 header.b=MJNzwcgK; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232241AbjGZHOp (ORCPT + 99 others); Wed, 26 Jul 2023 03:14:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232180AbjGZHOX (ORCPT ); Wed, 26 Jul 2023 03:14:23 -0400 Received: from out-47.mta0.migadu.com (out-47.mta0.migadu.com [91.218.175.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97B212D67 for ; Wed, 26 Jul 2023 00:10:50 -0700 (PDT) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1690355449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Jvc7jyiFGsEgqDLQ8SvDwKCvjECMcl21zak/YPsttTU=; b=MJNzwcgKcI8WMs1vcHIk9odpFzXJXYJZkCEqMlLlvbf0FvKHK96bLJs5XTXQyUPcTsHXLS nIqAIZhilsKlD4q7ONNAKGG+YEnzT1SMJk3OhEOossreA6CsEZNAbhHhb/1A0W8D/Gm3Q3 yKiIjz335Q++bI56PmpRINRM4YbGaI0= Date: Wed, 26 Jul 2023 15:10:21 +0800 MIME-Version: 1.0 Subject: Re: [PATCH v2 19/47] mm: thp: dynamically allocate the thp-related shrinkers To: Qi Zheng 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> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20230724094354.90817-20-zhengqi.arch@bytedance.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable 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/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. > > #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. > +{ > + 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. > +{ > + 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) > {