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 245F5C47DAF for ; Thu, 18 Jan 2024 12:39:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B10846B007E; Thu, 18 Jan 2024 07:39:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A99746B0082; Thu, 18 Jan 2024 07:39:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 912906B0087; Thu, 18 Jan 2024 07:39:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 814406B007E for ; Thu, 18 Jan 2024 07:39:26 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5CED71A027C for ; Thu, 18 Jan 2024 12:39:26 +0000 (UTC) X-FDA: 81692387532.27.1903B88 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) by imf26.hostedemail.com (Postfix) with ESMTP id 8B4E6140022 for ; Thu, 18 Jan 2024 12:39:24 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pG+RITuc; spf=pass (imf26.hostedemail.com: domain of gang.li@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=gang.li@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705581564; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ExNhxk12A1ggZeTlNcXFGggLGZAANw7/uA5h1igFwws=; b=QlBmUKPpppi5Pn6E1azqj19CoopjYosOIYzVg/Z4kGPxSL+fThiQ4qNzA/aHmQv0pGSiVh Z/bsimyA+vpGa3Wg3a25uu1WSUuT2PKtQTUa8hC1iHVD7OVzP3X99ssRUpC+QqaBy1SY5y wZ5XuiHBVO33NLtl8FCC9soyf2tUk9s= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=pG+RITuc; spf=pass (imf26.hostedemail.com: domain of gang.li@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=gang.li@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705581564; a=rsa-sha256; cv=none; b=cssQ6FrbGtErr7nyBbj/MeqWFHPLC+KN1tBBhzEPSqtXPKNA07+9qYTrjKU0DzneQUnUW+ /Hk4+g8YXmEdVBTMcoL/McGULySJUMEfVb7Fqfz6rSpnD2waD28pBmbblgHoX9K77Zhsn0 E94FD780LyopIgPJOQQjC01zsB6SUGM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1705581562; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ExNhxk12A1ggZeTlNcXFGggLGZAANw7/uA5h1igFwws=; b=pG+RITucTavbLnmWFp3E6QAPFq6rT1oIcvMFugCJGPD5YHA51y/POAMaILEiYttWA6sMqo fe6xZrMWrKZkEmcTKROczOtPuUp9k7PzdRptuHFedB7YlplZR/bOKcT3VabFLJ3wGJqTlz HkA+MBmGSrPMVAGd220o9Ilf16iE0ac= From: Gang Li To: David Hildenbrand , David Rientjes , Mike Kravetz , Muchun Song , Andrew Morton , Tim Chen Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com, Gang Li Subject: [PATCH v4 1/7] hugetlb: code clean for hugetlb_hstate_alloc_pages Date: Thu, 18 Jan 2024 20:39:05 +0800 Message-Id: <20240118123911.88833-2-gang.li@linux.dev> In-Reply-To: <20240118123911.88833-1-gang.li@linux.dev> References: <20240118123911.88833-1-gang.li@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 8B4E6140022 X-Rspam-User: X-Stat-Signature: n86713it91cb4ij5iacazejxk8btmgqt X-Rspamd-Server: rspam01 X-HE-Tag: 1705581564-916009 X-HE-Meta: U2FsdGVkX1//9XOm0Kw6KB32RRZONX3o37Bmz4A4XcpCtN6DVbIZwZAODtfR+n+MaR9ujBRC2pC75iOpQmV+w+dTtoTW3OUCOmZLwoAUkvfNo+qv5rkThiYWWZMCw3BxTSYd2BTVogKjlcVbmtdAPzN+HHOLMAsUGOilHaCAAxss3O7y8zBqrruaanvrohjll0wt0PwU5gAk6DgA27hjQ4FPjSVULVW8/8k0S0QIiKMGzRWUxYzpe4nrMgWIXKvcX/k2y+M50KMS/5e5uJwEHsaUnfSM/PWex+jxTWCaCLkIvIPqLVurTQM1051Fn2V2xZff+NRLKKgtfl1xEpgsh6SCFSaSSCDQDIp0xqHeCUE7LSoPsVvEi0+KomlPx06t5KwqIZouSIhQuB0n+eVzy9Khuc0O9DrTlbkFEKY8CxZUup+uf9qdghXsnxPKoNxrWhnvgB5rwlbvVitZF/8crTBa8r1st+zuEs9AP/hGGLb2xtttJd5pgRH7/oB9tpo0FRRJoNjBUboS+gCis1EpXqbFR5WliDxV8qocsNcAyo7c0H4GYa5LsEUQW/A3qNoPTrCkGrW+drIlCV7voEjfGGHqwZsJCNo0o6Y0T/7C6K2tcbLbkAFdul/b8DAoiG78a0XGoKYcPa4Nsv61HpZXz7IrLYQfDUa6kljI+TA56ju+n6ueZnbNPXiMz59Zzgi3Nf2cqzl9O3rzNFjQjmxEHYtx5yoWkJKEXIq29kCz2S/BCWLYXHeKMZGvQq/l839hd/KQ7jBKFXnT/LqkAZemdjjRB0+D81fITnwOvW9KsSdMm9Z1AF5wrAlrOf94VdhJOqR8CvkpvU/RTIZBJDi6f3ooecJYR1J3/rhnF3D0tDT9wfswDiPYeqG7IuiinfswiniArOCTkGOHWTau/WzJg3ZIUy8HC9CagNsaBFXUPxwv5DcU5OBTJ5D4iiwgOMs6oSiZLb4lFdHNNUJ9NBx jw8puKEo dWnWRBRADikcvNUvHE14EJu/Fn/n/Hh6XkYz6Vtl7tALl6o+QdYgDblLxBbbkTOWGJrKTt/Bqie8CdAE/Y+Ls/8XfH0iKI6VQVzpOigCiziF+R/Y6NRTYoGKpIWeSn88k8Zsh6XlyrNfVr/HpT74WTaVrbUU/i1F0+Zh27jFhw96EO6E= 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: List-Subscribe: List-Unsubscribe: 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 Tested-by: David Rientjes Reviewed-by: Muchun Song Reviewed-by: Tim Chen --- mm/hugetlb.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ed1581b670d4..b8e4a6adefd6 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_specific_nodes(struct hstate *h) +{ + 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_errcheck(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_specific_nodes(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_errcheck(i, h); kfree(node_alloc_noretry); } -- 2.20.1