From patchwork Fri Jan 26 15:24:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang Li X-Patchwork-Id: 13532815 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 95B4BC47DDF for ; Fri, 26 Jan 2024 15:25:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE7C06B0082; Fri, 26 Jan 2024 10:25:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E97116B0085; Fri, 26 Jan 2024 10:25:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D60CB6B0087; Fri, 26 Jan 2024 10:25:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C2ADC6B0082 for ; Fri, 26 Jan 2024 10:25:00 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6F528120FD9 for ; Fri, 26 Jan 2024 15:25:00 +0000 (UTC) X-FDA: 81721835160.15.814DBEB Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by imf19.hostedemail.com (Postfix) with ESMTP id BBEBB1A001B for ; Fri, 26 Jan 2024 15:24:58 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Z2mGLWb9; spf=pass (imf19.hostedemail.com: domain of gang.li@linux.dev designates 95.215.58.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=1706282698; 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=P9aNrm9Rl6VWe92w5Q1+H7U7+x0T3IY85gF9i1XPLD0=; b=FTy+AQFl0ym3i218UPEm3DQ/1IMEG1yWXW8uWxSKWjDSdc98l+4SPd8sd0+rNb9nB5BJWj AwAoI8Fk4Awaq0YGND8Odbp0s9BBZz2me3rx+Tf/5ONgrB8YETCmNP5NW9wXL+Z15LIC+k MYc1Rx9MNGW3hZ2bn6h4BmDpnAtzUZU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706282698; a=rsa-sha256; cv=none; b=qVQ4o2eWGqPAJbqnKs3koQszn3/A7rMjgWMwwbplYM4GQuq65i6zQ+Lqwi6zYTzlw4op0t Km6XOS4XDTHa7zzWrZYIo284CScCg4qQutEbRzXUkbR49JbpggZr+MuJwxS8wALxa4znep OQea6JMPb4SWLMk+JH7Rn/tP9fOpJO4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Z2mGLWb9; spf=pass (imf19.hostedemail.com: domain of gang.li@linux.dev designates 95.215.58.178 as permitted sender) smtp.mailfrom=gang.li@linux.dev; dmarc=pass (policy=none) header.from=linux.dev 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=1706282697; 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=P9aNrm9Rl6VWe92w5Q1+H7U7+x0T3IY85gF9i1XPLD0=; b=Z2mGLWb9xrBuI0vOVD3E/NJFwQiuaje5gheixSf/WVC/8b+43XxkctLePzaM1b5Q45N43H jiACbC9uRwNgXG1Aj/uKYCxw/54Qrw4qopzYmDpDtD28Eu+qzsQAz6NeImrzqeJQQJWWKD oNdPxdCl8DH8xl4A48uiL4uj+fNJQvE= 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 v5 1/7] hugetlb: code clean for hugetlb_hstate_alloc_pages Date: Fri, 26 Jan 2024 23:24:05 +0800 Message-Id: <20240126152411.1238072-2-gang.li@linux.dev> In-Reply-To: <20240126152411.1238072-1-gang.li@linux.dev> References: <20240126152411.1238072-1-gang.li@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 61jfnek6sm567rccba5hck65qwtwod4n X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BBEBB1A001B X-Rspam-User: X-HE-Tag: 1706282698-121606 X-HE-Meta: U2FsdGVkX1+o0/aGAwj0sDk5wi+OqF9I33fxZgznnn50AYln3BLuWbS1+uX95EUQ+7hni+u6XqtpaVwbw0xKwujXQnouOwXbr8k380U88yGVKMOPeuADUofFBePbVGZPVVFdlVfc707+4hq8wa0fezBJ7GBR4Ym5wx8NyYvzzt+h9Xm+uzv0GBUs+PCnEcOp4OY6B+KtEFzmd2/P8f/rsieGrVN9XB33EcrHKNTtuopd8KKnwY/rGGs9z13ETvONaw4G1zy3b2m0qanglR9L+RLUrsaK6oK8Rfrg+mEoEsdgJiOENCrSezvj48vDZe36G8MP6nF2vNTKAlwu5ofoveylPtLu8rDVlK+NcOJlsIkJm4qy7wxoa2w9UAqcoXP+Csc11Xd7xYC8MT/dA/LP/4ipL9m3aSCrnY3WihvYwQaffLc+ZjpeaMvf7qJvIiHP2AdVug4T1CxFbXWbE4yepQNFzeWI55rzeza74hMoRm1pgyQtJ0APZg92V2B/5Xyf9v4kcWrkzlfmP0ulrZZ1HrQ5dgpKU56NWiaio9hMRXBqDKUkQ6/NsNTQfwn2ogEt2vGV06i93MRFOG1hZH6NUKD509ceWKEaiYua1HzdvuWk4cfhxiA4CYy1dlI7ClMCw1jXYungMwnnnFq+cWyywqLuzb9OllZUb3wPPmyfl8u8AIk0B4X/Pp0d6e+i0tU19Fn0nKwNbTL5CiSMTDG97yAcsaqLbVnYwytxgx8lSfh/ytp0S3WCnS8Uj6b4RyjiIklaDPEfXU80B1IFeygF5Q+MPpiefq/lfOlZULHM3TJ1itxEqeZTGE9Bv7FtunblCUCMUPSovfgr31VrI3pac9OsHnHpCCvXAwqYg7b18QJbOEZz7IOoOKthsuIxofmT10TkEURyP79gbumVjugtgo5slb469iaCSkLDqeJlntRr2Dr/nmfnGlaOMIA2xO7Okcao6qtdPKYc7QzKTDd 6ozAXWST pNSvD67NeUDSiD/oTeVG7kFG41CNxgmytGAR8k7QamFoB44kuqF3pwlm81tkhbDy1zm2Vs7TpxO+xV91Mf3dIA+hlDVMfYu3V3KX8/GJgGeO5tiYW8GAwVMpwz183ck5UeHpSoZjjk1cv+LYXG9WALmjvBYm2iVAUWAFYHOWGTTAiiiqMJEnn75fIjYbFA0rPJWp5ATlGXoQVMfumBPm6946oMnOwK8PIbeD8 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 2cf78218dfe2e..20d0494424780 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); }