Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp886664rdd; Wed, 10 Jan 2024 02:30:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBtMgRzA8GgKgAJunL5bPmcBoSdSxRzLHnrRnxhfSYs7BA9EgXqVw8x6fT1VwizAHVkVzw X-Received: by 2002:a17:902:d545:b0:1d4:88a5:fd87 with SMTP id z5-20020a170902d54500b001d488a5fd87mr781154plf.18.1704882648440; Wed, 10 Jan 2024 02:30:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704882648; cv=none; d=google.com; s=arc-20160816; b=sKf98JOW49yB3U9H92atj8XjHMi+5QRVHAgO1zAnEnEHHwRLEGPL3EQxbr6u3y9thc zjr289k+LnWFtnVGQbTvs90sqqdkWjg4Da1Q+2i/e5ucgYmlKo7txeJQVdCmgIu+sL4c CXUY/B4NTXCMxfuu3fqmmOPPmINnnlKobfNq96fQxBj2wyMqCKQLzzcPo4DkyzusWotd 7lJ1F4Ud3nJCP7d9nGIOTpyGn3+VQATtlbfwJeMhLUGHclWefAS6tuiOuWwv+RQADhlH JwYdZ0JUR5y7eo8/4ZgavovWy8YKj+Gj38Ibu4Mx1Fmg2tXQkFi8tupA8pvKEflVLhv+ 4rmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:dkim-signature:message-id; bh=HqWLnzHdhYYeRCqMae8M6cQn2qiQCuRsbTV+dKiFGmo=; fh=8zGz3B6Pbm0SswbND27LzQeViqNfTlUlYcLO1jRCVKo=; b=FQl+LsXBoyvo3Xr3T7T0IAtYJEYd12nHV+9RcwK3GtytxSjy3gIyMwhHLBpsixEqUv xBjlJEiNAc7LDuH1I8ZkuMW0ardAJRBQZr8iudPcGaYugSjZkR/rYEz95niUnijdNzjs BexOpeJa/GZr0ToVTHa3Hn2qRegITxOdWeknIyXo0M7KLFTf4dirftO7s+7C4nDcrlNw 9i5rvpDlwv3v0Wkd3FJuomJ06MhrqdKwGTSLb1NEh7s1EkUQin97CoKZ2rz181hJV5PA r4tkbaK8osW0TPav+JoCywBXP4jUYPO+6taJG19LkfjYT8DEH4xzvx50S7Ps0LOfzN2E G58Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CK2U00TA; spf=pass (google.com: domain of linux-kernel+bounces-21963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21963-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id b1-20020a170902b60100b001d569371c91si1831523pls.632.2024.01.10.02.30.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 02:30:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CK2U00TA; spf=pass (google.com: domain of linux-kernel+bounces-21963-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21963-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 99F3F28A439 for ; Wed, 10 Jan 2024 10:20:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ECE903FB13; Wed, 10 Jan 2024 10:20:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="CK2U00TA" Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CD3A3FB0A for ; Wed, 10 Jan 2024 10:20:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Message-ID: <73111be3-3077-4821-8c2f-9c5564cb2bb7@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1704882018; 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=HqWLnzHdhYYeRCqMae8M6cQn2qiQCuRsbTV+dKiFGmo=; b=CK2U00TAoeJZ6otiqwyvKNb+WcXawuJ82/NZd9tetCf8iTBiKMn7NAC9B/zf42c5olKs7C jhGDBJMgEPZGg+e/Vd8rlmjcFITXUVHH+g6grdLSJW6vzqXGZSa84zjzRcck0H1BKUtfiD KwxG0N/Cw1i/0IhbkMXjD7tehX+NSVo= Date: Wed, 10 Jan 2024 18:19:49 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v3 1/7] hugetlb: code clean for hugetlb_hstate_alloc_pages To: Gang Li Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com, David Hildenbrand , David Rientjes , Mike Kravetz , Andrew Morton , Tim Chen References: <20240102131249.76622-1-gang.li@linux.dev> <20240102131249.76622-2-gang.li@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20240102131249.76622-2-gang.li@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT On 2024/1/2 21:12, Gang Li wrote: > The readability of `hugetlb_hstate_alloc_pages` is poor. By cleaning the > code, its readability can be improved, facilitating future modifications. > > This patch extracts two functions to reduce the complexity of > `hugetlb_hstate_alloc_pages` and has no functional changes. > > - hugetlb_hstate_alloc_pages_node_specific() to handle iterates through > each online node and performs allocation if necessary. > - hugetlb_hstate_alloc_pages_report() report error during allocation. > And the value of h->max_huge_pages is updated accordingly. > > Signed-off-by: Gang Li > --- > mm/hugetlb.c | 46 +++++++++++++++++++++++++++++----------------- > 1 file changed, 29 insertions(+), 17 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index ed1581b670d42..2606135ec55e6 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -3482,6 +3482,33 @@ static void __init hugetlb_hstate_alloc_pages_onenode(struct hstate *h, int nid) > h->max_huge_pages_node[nid] = i; > } > > +static bool __init hugetlb_hstate_alloc_pages_node_specific(struct hstate *h) I'd like to rename this to hugetlb_hstate_alloc_pages_specific_nodes. Otherwise, LGTM. Reviewed-by: Muchun Song > +{ > + int i; > + bool node_specific_alloc = false; > + > + for_each_online_node(i) { > + if (h->max_huge_pages_node[i] > 0) { > + hugetlb_hstate_alloc_pages_onenode(h, i); > + node_specific_alloc = true; > + } > + } > + > + return node_specific_alloc; > +} > + > +static void __init hugetlb_hstate_alloc_pages_report(unsigned long allocated, struct hstate *h) > +{ > + if (allocated < h->max_huge_pages) { > + char buf[32]; > + > + string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32); > + pr_warn("HugeTLB: allocating %lu of page size %s failed. Only allocated %lu hugepages.\n", > + h->max_huge_pages, buf, allocated); > + h->max_huge_pages = allocated; > + } > +} > + > /* > * NOTE: this routine is called in different contexts for gigantic and > * non-gigantic pages. > @@ -3499,7 +3526,6 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) > struct folio *folio; > LIST_HEAD(folio_list); > nodemask_t *node_alloc_noretry; > - bool node_specific_alloc = false; > > /* skip gigantic hugepages allocation if hugetlb_cma enabled */ > if (hstate_is_gigantic(h) && hugetlb_cma_size) { > @@ -3508,14 +3534,7 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) > } > > /* do node specific alloc */ > - for_each_online_node(i) { > - if (h->max_huge_pages_node[i] > 0) { > - hugetlb_hstate_alloc_pages_onenode(h, i); > - node_specific_alloc = true; > - } > - } > - > - if (node_specific_alloc) > + if (hugetlb_hstate_alloc_pages_node_specific(h)) > return; > > /* below will do all node balanced alloc */ > @@ -3558,14 +3577,7 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) > /* list will be empty if hstate_is_gigantic */ > prep_and_add_allocated_folios(h, &folio_list); > > - if (i < h->max_huge_pages) { > - char buf[32]; > - > - string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32); > - pr_warn("HugeTLB: allocating %lu of page size %s failed. Only allocated %lu hugepages.\n", > - h->max_huge_pages, buf, i); > - h->max_huge_pages = i; > - } > + hugetlb_hstate_alloc_pages_report(i, h); > kfree(node_alloc_noretry); > } >