Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp932848pxb; Wed, 29 Sep 2021 12:51:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu3QDj5EgabCJyCxOuGZgADxb+/4pkv4BaJ0fnPiJLG//5l6+gFukgu2CeLQ2HKlrzJBLD X-Received: by 2002:a17:906:ca4f:: with SMTP id jx15mr1909956ejb.186.1632945094699; Wed, 29 Sep 2021 12:51:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632945094; cv=none; d=google.com; s=arc-20160816; b=1E9b5vuignMgFHc+WUbWFS3HisKkdz/QemEbzf1xnna4Lt9ov60bZDpsJERNyj4GS9 LihrtCKRsZrqWipKnrL7j9+uJ3MvGGiQKWhKDonxcJa3ljgXQNyCK9UgFOck8a+ysa7i DBrFDiFcgUCnKcFqfBZVR6Rc4YjGyVZua2Goq/SuWX0NxewsEaAWARaF9xiQiM5Lw5WK 5o8d5kaHJ1JGC+wVTGByPBYQSa1IW7PqQZAcHwFzj+CcjAkXzZHxS128dRwftoGCdHvF zwSrh/I8xGomBWh9buGo06r8uOIVBEB7n0FyvXEA2dEB+EozKoJ4RBaqB7E9qT5lGHuQ NIEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=VO8cLZ1BhknkUoUPAiXEJPTrCIYZ3JSoaJljjIqHJMg=; b=DCfmS6OinrzYenN1WsRlhWkxLz3DVhXHjtnjZ2ab9/ZTIGOILOVZLVIUL8yofnOiXP wwWv42lAsNr19+H+gyPQWWpa2i+/BQfWYaQbnptNPVZuP3EriivaVUjzi4Q0nsJiNAjf QchQmgTV76klukBDLJm5w2Ca+4rQjqzJOrZJKODVUoGJYdI+cKT9iBGcrVL3WLG5u+2I TtfmFcwxaTTy0Li15y5ubaRlUMmuBO5ekLjsfHy0bmT+mQ2xveIXq3+WNNYV+JBOZhZa VfaGWxf3QaXUx7HS6LaiL7RQ3JoRhQiueqKMxO35zvLaL5f0xom4+HiJ9bFDGmQAiDhI Gdtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IV9s+ltd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m5si921682ejn.633.2021.09.29.12.51.08; Wed, 29 Sep 2021 12:51:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IV9s+ltd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346568AbhI2TZy (ORCPT + 99 others); Wed, 29 Sep 2021 15:25:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:52020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343505AbhI2TZx (ORCPT ); Wed, 29 Sep 2021 15:25:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D669F6140F; Wed, 29 Sep 2021 19:24:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632943452; bh=Kic1xJl340EDGWe45l8iOlr2pQS1CGNbWFMeOBeCVnQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=IV9s+ltdhsqghIwkv47ivP4VliZE95ZjYph5zm7PrF+feipDFsaYdAfYHrYHP+o0A 4XjDdKqz5o9ZKLmYkZF2bJmEqO0FE8mdOU9FAaDQfOCnPReQrWPkMvs28GQdMxaXU8 MB38pj16HImpN4iSocIU0nRR7gU9Niv5fMZTmXK39CczqigP9s9jSQ+kFJ7d3seBFA K35UkTtgv8ZKKFtE7b+ljU8gW91H6CA6DHe8dIcv1JCHku47lSJlc8EDC5/kuwIynw l6VM7HOhMvDgT8DAqopy6fodKqmpWD1AjYNKqNrn53dAP2iqyB+SeBK3/3XquBLVAE J/Kno9ZVXtRCw== Date: Wed, 29 Sep 2021 12:24:06 -0700 From: Nathan Chancellor To: Zhenguo Yao Cc: mike.kravetz@oracle.com, mpe@ellerman.id.au, benh@kernel.crashing.org, paulus@samba.org, corbet@lwn.net, rppt@kernel.org, akpm@linux-foundation.org, yaozhenguo@jd.com, willy@infradead.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, llvm@lists.linux.dev Subject: Re: [PATCH v7] hugetlbfs: Extend the definition of hugepages parameter to support node allocation Message-ID: References: <20210927104149.46884-1-yaozhenguo1@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210927104149.46884-1-yaozhenguo1@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 27, 2021 at 06:41:49PM +0800, Zhenguo Yao wrote: > We can specify the number of hugepages to allocate at boot. But the > hugepages is balanced in all nodes at present. In some scenarios, > we only need hugepages in one node. For example: DPDK needs hugepages > which are in the same node as NIC. if DPDK needs four hugepages of 1G > size in node1 and system has 16 numa nodes. We must reserve 64 hugepages > in kernel cmdline. But, only four hugepages are used. The others should > be free after boot. If the system memory is low(for example: 64G), it will > be an impossible task. So, Extending hugepages parameter to support > specifying hugepages at a specific node. > For example add following parameter: > > hugepagesz=1G hugepages=0:1,1:3 > > It will allocate 1 hugepage in node0 and 3 hugepages in node1. > > Signed-off-by: Zhenguo Yao > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 95dc7b83381f..ca00676a1bdd 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -66,6 +66,7 @@ static struct hstate * __initdata parsed_hstate; > static unsigned long __initdata default_hstate_max_huge_pages; > static bool __initdata parsed_valid_hugepagesz = true; > static bool __initdata parsed_default_hugepagesz; > +static unsigned int default_hugepages_in_node[MAX_NUMNODES] __initdata; > > /* > * Protects updates to hugepage_freelists, hugepage_activelist, nr_huge_pages, > @@ -2868,33 +2869,41 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, > return ERR_PTR(-ENOSPC); > } > > -int alloc_bootmem_huge_page(struct hstate *h) > +int alloc_bootmem_huge_page(struct hstate *h, int nid) > __attribute__ ((weak, alias("__alloc_bootmem_huge_page"))); > -int __alloc_bootmem_huge_page(struct hstate *h) > +int __alloc_bootmem_huge_page(struct hstate *h, int nid) > { > struct huge_bootmem_page *m; > int nr_nodes, node; > > + if (nid >= nr_online_nodes) > + return 0; > + /* do node specific alloc */ > + if (nid != NUMA_NO_NODE) { > + m = memblock_alloc_try_nid_raw(huge_page_size(h), huge_page_size(h), > + 0, MEMBLOCK_ALLOC_ACCESSIBLE, nid); > + if (m) > + goto found; > + else > + return 0; > + } > + /* do all node balanced alloc */ > for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) { > - void *addr; > - > - addr = memblock_alloc_try_nid_raw( > + m = memblock_alloc_try_nid_raw( > huge_page_size(h), huge_page_size(h), > 0, MEMBLOCK_ALLOC_ACCESSIBLE, node); > - if (addr) { > - /* > - * Use the beginning of the huge page to store the > - * huge_bootmem_page struct (until gather_bootmem > - * puts them into the mem_map). > - */ > - m = addr; > + /* > + * Use the beginning of the huge page to store the > + * huge_bootmem_page struct (until gather_bootmem > + * puts them into the mem_map). > + */ > + if (m) > goto found; > - } > + else > + return 0; > } > - return 0; > > found: > - BUG_ON(!IS_ALIGNED(virt_to_phys(m), huge_page_size(h))); > /* Put them into a private list first because mem_map is not up yet */ > INIT_LIST_HEAD(&m->list); > list_add(&m->list, &huge_boot_pages); This hunk causes a clang warning now: mm/hugetlb.c:2957:33: error: variable 'm' is used uninitialized whenever '&&' condition is false [-Werror,-Wsometimes-uninitialized] for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ mm/hugetlb.c:1254:3: note: expanded from macro 'for_each_node_mask_to_alloc' nr_nodes > 0 && \ ^~~~~~~~~~~~ mm/hugetlb.c:2974:18: note: uninitialized use occurs here INIT_LIST_HEAD(&m->list); ^ mm/hugetlb.c:2957:33: note: remove the '&&' if its condition is always true for_each_node_mask_to_alloc(h, nr_nodes, node, &node_states[N_MEMORY]) { ^ mm/hugetlb.c:2942:29: note: initialize the variable 'm' to silence this warning struct huge_bootmem_page *m; ^ = NULL 1 error generated. I am not sure if it is possible for nr_nodes to be 0 right out of the gate so might be a false positive? Cheers, Nathan