From mboxrd@z Thu Jan 1 00:00:00 1970 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 B2838C43334 for ; Tue, 5 Jul 2022 05:21:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E40146B0074; Tue, 5 Jul 2022 01:20:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DC8396B0075; Tue, 5 Jul 2022 01:20:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C69E16B0078; Tue, 5 Jul 2022 01:20:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B15246B0074 for ; Tue, 5 Jul 2022 01:20:59 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 741E720F30 for ; Tue, 5 Jul 2022 05:20:59 +0000 (UTC) X-FDA: 79651897038.24.8E7A53E Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) by imf19.hostedemail.com (Postfix) with ESMTP id 65CD31A0054 for ; Tue, 5 Jul 2022 05:20:58 +0000 (UTC) Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-31c8a1e9e33so45562917b3.5 for ; Mon, 04 Jul 2022 22:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SCVzYAf8Ry1kx4tzjm0xtpxQrKLwUnpUZ/IpIuvVBsw=; b=UrY7H/FILQyfAI3YTBmbcC8oSf5c2vzX3aM39AELofS+pvpGy/pJSpvDGWk7ow8aCq sPb1XK2ww9lwq0a9S+FoUcj/llLHkEUKUs4HZ5OdQE0HncGnn/eAhg0rXbiVr6HlOGfR MyJAVWBNU/lU35hcX3+GWbkaItFU2MYqUBGXYX10JFkBRrZNWV21od3zZy9c/j0RIwvX MIApigCo9D6zlHgMe11q2chkmGZxtLjWHeqVy/FkNZK4DifeaRGQ2fmyi+vjVZYU8uF7 1psqitj/046dkLAKwDs9/bLo3XRwv1c4FXV5qKQlfWqvej6KMLhrROp1RA1GFwFmZAGQ uJUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SCVzYAf8Ry1kx4tzjm0xtpxQrKLwUnpUZ/IpIuvVBsw=; b=LL3JXGznCFCQO4UOlOdtTF18twWJxR49J99fPe+dr89HcGnsdAITs34DiDwIOBdQQd rjyGoYjg9vVkuQQN0K7E60nMyGJ03EqYe2teBal8/oWvSV5JWolOQrvYcj4MNm6xfrPr 24+O94/hsSU1yMOsGGFpOhWkZ2ubU4b+49UFn2g2ky8+LE30lCrgMOTQsKF+OR1i5i7v cgmks51eEF6Eq6v8r6IrnzqgVzGUO0yTCuN5beuxOnL9ypvoHbpowpa6nKn+iTt1o5+A KNMUiUsr4etHpCfbfbRHv3HRyfQemU1/+kwZG3NzHv2Dv5MChFWcbYSZSfRgd5oNIwty l9aw== X-Gm-Message-State: AJIora9+YH03mls970EeEff917O2Yi5jGOWkf0DSqPeSEEzq7ky/4EPm Dms3mzNiLjO7PdgBVKbQIAEheRvPDAHxeH221j7jtg== X-Google-Smtp-Source: AGRyM1sMifOPi8MloaMBhNhfVAE0Y5BcKvecu2CtTb+I9/WgbR9lJMpe4XF8OZvBqDLUvay5IQzt8wfWDxZV47IIIa0= X-Received: by 2002:a81:f0d:0:b0:31c:8860:c59f with SMTP id 13-20020a810f0d000000b0031c8860c59fmr14279076ywp.31.1656998457400; Mon, 04 Jul 2022 22:20:57 -0700 (PDT) MIME-Version: 1.0 References: <20220705034841.40931-1-ligang.bdlg@bytedance.com> In-Reply-To: <20220705034841.40931-1-ligang.bdlg@bytedance.com> From: Muchun Song Date: Tue, 5 Jul 2022 13:20:19 +0800 Message-ID: Subject: Re: [PATCH v2] mm, hugetlb: skip irrelevant nodes in show_free_areas() To: Gang Li Cc: Mike Kravetz , Andrew Morton , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656998459; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SCVzYAf8Ry1kx4tzjm0xtpxQrKLwUnpUZ/IpIuvVBsw=; b=zrhpUmisCOUVNIKVVHL6EKKqGZ630tIK8k1+l2Hd1bG8S//yJFLx8l2mdVePGixv+qbcly ApDXTOZGOvwI1kdnrMrZ75h/WAf2SOF69vmocOnsWkXjUd5qqlx2BTAyVeLlp/7MsQ1Hto I/gY/o3zBPxGmNKsaZTUt8gfCXiajMM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="UrY7H/FI"; spf=pass (imf19.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656998459; a=rsa-sha256; cv=none; b=TRMArobE3cStQQtgRDckhPPTgY89qcURZaKVwHvo4NyAO/CAcnVVnoeLuPUX8tFla7waVm rpWapFD6E4Jb1sdWNMclRNIIZJrASjA2OxCa37I0x583FFLLRcxc/C71NpPj5ji9XPKVpj 9YnNAEzzDcxDZAQco3SOhjK8ui97pXs= X-Stat-Signature: ryj989ichx4swwgrp93jgjezcsiaq55e X-Rspamd-Queue-Id: 65CD31A0054 Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="UrY7H/FI"; spf=pass (imf19.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.128.171 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspam-User: X-Rspamd-Server: rspam02 X-HE-Tag: 1656998458-361961 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: On Tue, Jul 5, 2022 at 11:49 AM Gang Li wrote: > > show_free_areas() allows to filter out node specific data which is > irrelevant to the allocation request. But hugetlb_show_meminfo() still > show hugetlb on all nodes, which is redundant and unnecessary. s/show/shows/g > > Use show_mem_node_skip() to skip irrelevant nodes. And replace > hugetlb_show_meminfo() with hugetlb_show_meminfo_node(nid). > > Signed-off-by: Gang Li > --- > v2: replace hugetlb_show_meminfo() with hugetlb_show_meminfo_node(nid) to avoid > exporting show_mem_node_skip. > --- > include/linux/hugetlb.h | 4 ++-- > mm/hugetlb.c | 21 ++++++++------------- > mm/page_alloc.c | 10 ++++++++-- > 3 files changed, 18 insertions(+), 17 deletions(-) > > diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h > index 29c4d0883d36..21795e62398b 100644 > --- a/include/linux/hugetlb.h > +++ b/include/linux/hugetlb.h > @@ -155,7 +155,7 @@ void __unmap_hugepage_range_final(struct mmu_gather *tlb, > struct page *ref_page, zap_flags_t zap_flags); > void hugetlb_report_meminfo(struct seq_file *); > int hugetlb_report_node_meminfo(char *buf, int len, int nid); > -void hugetlb_show_meminfo(void); > +void hugetlb_show_meminfo_node(int nid); > unsigned long hugetlb_total_pages(void); > vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, > unsigned long address, unsigned int flags); > @@ -301,7 +301,7 @@ static inline int hugetlb_report_node_meminfo(char *buf, int len, int nid) > return 0; > } > > -static inline void hugetlb_show_meminfo(void) > +static inline void hugetlb_show_meminfo_node(int nid) > { > } > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index ca081078e814..c87049c4126e 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -4490,22 +4490,17 @@ int hugetlb_report_node_meminfo(char *buf, int len, int nid) > nid, h->surplus_huge_pages_node[nid]); > } > > -void hugetlb_show_meminfo(void) > +void hugetlb_show_meminfo_node(int nid) > { > struct hstate *h; > - int nid; > > - if (!hugepages_supported()) > - return; It is better not to delete this, I know you want to lower the overhead for users when !hugepages_supported(). However, it is not a common case and not a hot path. > - > - for_each_node_state(nid, N_MEMORY) > - for_each_hstate(h) > - pr_info("Node %d hugepages_total=%u hugepages_free=%u hugepages_surp=%u hugepages_size=%lukB\n", > - nid, > - h->nr_huge_pages_node[nid], > - h->free_huge_pages_node[nid], > - h->surplus_huge_pages_node[nid], > - huge_page_size(h) / SZ_1K); > + for_each_hstate(h) > + pr_info("Node %d hugepages_total=%u hugepages_free=%u hugepages_surp=%u hugepages_size=%lukB\n", It is better to use printk here. Two reasons. 1) To keep consistent with the print in show_free_areas(). 2) If we want to introduce the macro "#define pr_fmt(fmt) "HugeTLB: " fmt" to hugetlb.c in the future, the print here will not be affected. > + nid, > + h->nr_huge_pages_node[nid], > + h->free_huge_pages_node[nid], > + h->surplus_huge_pages_node[nid], > + huge_page_size(h) / SZ_1K); > } > > void hugetlb_report_usage(struct seq_file *m, struct mm_struct *mm) > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index 2eb6ad5a650a..684c2e410923 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -6014,7 +6014,7 @@ static void show_migration_types(unsigned char type) > void show_free_areas(unsigned int filter, nodemask_t *nodemask) > { > unsigned long free_pcp = 0; > - int cpu; > + int cpu, nid; > struct zone *zone; > pg_data_t *pgdat; > > @@ -6202,7 +6202,13 @@ void show_free_areas(unsigned int filter, nodemask_t *nodemask) > printk(KERN_CONT "= %lukB\n", K(total)); > } > > - hugetlb_show_meminfo(); > + if (hugepages_supported()) { As I said above, embed this check into hugetlb_show_meminfo_node(). > + for_each_node_state(nid, N_MEMORY) { Please use for_each_online_node here. Thanks. > + if (show_mem_node_skip(filter, nid, nodemask)) > + continue; > + hugetlb_show_meminfo_node(nid); > + } > + } > > printk("%ld total pagecache pages\n", global_node_page_state(NR_FILE_PAGES)); > > -- > 2.20.1 >