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 B7AE0C54788 for ; Thu, 22 Feb 2024 14:05:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D7B26B0088; Thu, 22 Feb 2024 09:05:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 488906B0089; Thu, 22 Feb 2024 09:05:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34FBF6B008A; Thu, 22 Feb 2024 09:05:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 247E46B0088 for ; Thu, 22 Feb 2024 09:05:07 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E5513120E6E for ; Thu, 22 Feb 2024 14:05:06 +0000 (UTC) X-FDA: 81819611412.09.84E32D4 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) by imf08.hostedemail.com (Postfix) with ESMTP id 69D2E160015 for ; Thu, 22 Feb 2024 14:04:48 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=i3uRvd9J; spf=pass (imf08.hostedemail.com: domain of gang.li@linux.dev designates 91.218.175.178 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=1708610688; a=rsa-sha256; cv=none; b=kbZa5HheuprtFMXgDqshxEXfA/r6D3vrw+qUHSj4mvtP6JdmXhGcd4ZKLYdpfEFw2SX2ul BZCMBpIA3kxSU3HoeoVw+hF3uH9gRPmUc+/BNOnwM9Hba8niLCuWsswomZ+umVxgUO8Zd2 L6x5+O8a/b4TFhyTau8NTmZsMlIRLmM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=i3uRvd9J; spf=pass (imf08.hostedemail.com: domain of gang.li@linux.dev designates 91.218.175.178 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=1708610688; 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=qLDJ0oXYyRPh9zz0wE8IXI1bSRdqq7PDnnR6TGU9VgU=; b=oYWKhVKhew7PgRHqMj6UIMvboB6tzJ1456R28iDf3e0/BAE1e8Ceom83th1ss/vuZ7YmQN 6NnlvI7tS92YQfcM1Y7gGHcuqUupdWSSlFstcmUUzMEXWT/HErLSFDrWRLWJ5HibQ4XDy/ SJ8N2hcpxpEX5j80n9AfVEnZAYeSnoY= 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=1708610686; 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=qLDJ0oXYyRPh9zz0wE8IXI1bSRdqq7PDnnR6TGU9VgU=; b=i3uRvd9JstCtGlLa8/tyWtExImE0JtGxaojcIRs7n7nhFDNAP1r0mFxWuFGnV0DVJck360 +ybW3ROURTCTJyB8p7i3fvB985dnVQ3LNtm4RXv8GdUo6fpAsYQ3cBv0H6OF+4mHm7dqT7 SiYS5mOQGsqbMvVVng+9nU3mjbwRkQs= From: Gang Li To: Andrew Morton Cc: David Hildenbrand , David Rientjes , Muchun Song , Tim Chen , Steffen Klassert , Daniel Jordan , Jane Chu , "Paul E . McKenney" , Randy Dunlap , linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com, Gang Li Subject: [PATCH v6 1/8] hugetlb: code clean for hugetlb_hstate_alloc_pages Date: Thu, 22 Feb 2024 22:04:14 +0800 Message-Id: <20240222140422.393911-2-gang.li@linux.dev> In-Reply-To: <20240222140422.393911-1-gang.li@linux.dev> References: <20240222140422.393911-1-gang.li@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 69D2E160015 X-Stat-Signature: qhrhhbei9we3es1amrbidcrbmcctyfzy X-Rspam-User: X-HE-Tag: 1708610688-702230 X-HE-Meta: U2FsdGVkX18NtNBhQ27v6bMiXzRsIL8AZfFsyC5ogJGHvyceohVVphaUOgPV1CczmGM7hMofwWSYX8YkcD6KU8zjxDAgxALzzfYoxR57kXe+HLNHfXXZWXgxs3XSVMBiPY6bmuoR0pvCZFR1T5aXHNeeNP8j+HFv8nTkuz2lJMXtA5Jjlp4TtpVESW+DPnJ8Dn56gpIYs9SoA73NidZaO/9agBettGCsECD7gpR0TLzIWTZ599Vr0zF2LiNhghD4SL8v0ABUSieoXbaUb8+N9m4nGzmvYd4HhsX5SRKwziAVyVDimV1ap/C0yZ3ISKhFEHvT9bbxMEAJkvj5yE6Ru36l2fBwNuL/46lNsYHaBtbqVFP9hPU4lL0TTGHoVnBW2uLDBgG+62yuPRCL6BVrZKjc6JZ1Z+q1Zs1CioYyDuXAyg6PxdYlYjm7ngYf28gkbDnPihDwK3e7DdVTsqaQOMa7VT6WRUzNqEwGjdDikV7VTAorX20mMGvLK1PBr0/zTHdOFlTQIkKK4CRloNrMhIdFVNkz5oOhI/1cQ+cxg3HvYHweTPjD3RD9bjUqHE/1bKRNwMcC5LUefRBUm5PBfYGDNEXozle5c37twXSDHLfYFIa3J4IOvB1jkdMMUZqwMysZrNhaXDLFe4MGbmqnunNDS5c14uguzMNMDOL72RmKHePOvP9FZL0xcS1CteO3SfDRPworMvfGdahqHwJm2ReJE64vKjUUhpza/nkJYtRjmMUabhKwuLM8YW9vOtT/B2fHRstNwokOpc00OtHsmw2UE882cvOJNOyCfxZUu7L/WBxO9YpZ7D0Vuh3LZGnPWJ/JZUYoCP+8reIuO2F7OKL41fpuEObkdkIEczpKDeP0ub5/ab3xkxSjaOluwEuFkjnYH55siBM= 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 c53a41d07cd3a..794f3e6a19bb6 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