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 23732C10F04 for ; Fri, 8 Dec 2023 02:53:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 53A836B0083; Thu, 7 Dec 2023 21:53:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EBE86B0085; Thu, 7 Dec 2023 21:53:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 364C86B0087; Thu, 7 Dec 2023 21:53:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1F4346B0083 for ; Thu, 7 Dec 2023 21:53:10 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id EBB55403A1 for ; Fri, 8 Dec 2023 02:53:09 +0000 (UTC) X-FDA: 81542129298.08.AF63E5D Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) by imf27.hostedemail.com (Postfix) with ESMTP id 416A84000B for ; Fri, 8 Dec 2023 02:53:08 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=lfAm3Ag0; spf=pass (imf27.hostedemail.com: domain of gang.li@linux.dev designates 91.218.175.181 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=1702003988; 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=nScQm/fmNOjGhlLnCGYZOl5/YmPviWpS9XmgJR18QP0=; b=F4ZgcvOAev/1jJG3LdTbqfTlJl1irX7nBZ7uQWPTg1PyN1v69Fv98j5lYKMlUbPcuL/XWz fG1Uuolnw+d8rgx47S2rJCje/5ASGKH/LOE6Lu2HvjeisdRDPB4K/8ys+BbatGcAZ0H+DF fdbtINXe+jmRjZt9qzOarBtMNFvKy0o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702003988; a=rsa-sha256; cv=none; b=gJ+yPqyY0qQorBSFk0l7xsIdMbYIHfvFHQshdyOSU6MyBNQyWzTJBRC2zpynEmJGUL0WSN +VicwxkVAX0sNG31V9fU7zxDT1AILlTl7mcUsA0l7Sl7Lz36QvVm7Xo63eUNihM0r9AwAf Zp2tNXZsIM2KRg/csl5EPmZWURD3VoI= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=lfAm3Ag0; spf=pass (imf27.hostedemail.com: domain of gang.li@linux.dev designates 91.218.175.181 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=1702003986; 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=nScQm/fmNOjGhlLnCGYZOl5/YmPviWpS9XmgJR18QP0=; b=lfAm3Ag0u+nVvzsnpysTBQspAGEV7RQMWtcMnK+sgx5xG663oyDL2ImjlVJztS/qUUC2Bu ASnstCjN2e7RvnSs5QQnB61n9SzrCi2SL7VTkiqKPo9WPDD641CyExewkH4Cks64v1NnaA Y94xV0mU8qY+cPzuNp+xPfcAHW1VUQI= From: Gang Li To: David Hildenbrand , David Rientjes , Mike Kravetz , Muchun Song , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, ligang.bdlg@bytedance.com, Gang Li Subject: [RFC PATCH v2 1/5] hugetlb: code clean for hugetlb_hstate_alloc_pages Date: Fri, 8 Dec 2023 10:52:36 +0800 Message-Id: <20231208025240.4744-2-gang.li@linux.dev> In-Reply-To: <20231208025240.4744-1-gang.li@linux.dev> References: <20231208025240.4744-1-gang.li@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 416A84000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: gpynxt3qc5ofm37hw3gjjh6aqhnjgh87 X-HE-Tag: 1702003988-183342 X-HE-Meta: U2FsdGVkX19/iIu2QC8Gn6RnRWoyuk6uW7fdLNv44i+FIpXJrIPf5z+GoJSd6nXLUqGWto+zevm8qBxS2IbjB4IP5+mfs5s8e/A0727c+IWXR1XesiUhRHysZN6AqFE7mXQ22KmXySjN9fb11gCN+rPThzbv25KTGXK0OJwohxaHm4sKbBemFG2iJXBOurijDBPwRDRraCLdbCjq1ogkxPynmZKuzoNWdiXtmiZHIdS0Gn/BCCYTJwT0tYh/YTrP9YQQEGfwQFWS3ndYhIUyI/xeAkOsWimfNIhuy9rqZQVCMZSCRo74u64fEJkXMeMwqSGH984o95OivaasAyEwADvAYk4MInhnbcUcVB1zkjoa5qXQFPiKDq22sV45LDEtXfcmYjDIKoNU227QBOAKsi6gbtCGahTwxfkfnv6BcsDzKjf7/oDIVr+5sE+6czYWAbrZp+A23d5qFF9IIXvsAmzHJIlRCmipgbB5HDBIEtWNxrZDW18ZIdQYIC4xMnVBIHR+d6qj+WZ/+M51bIuEo+bhfYf5m5aLalo1VfO7Xz7hNNbKoOKwRky62LqnzvvdV0TQkkBBuo8azO+Ts/USrXdXEM9Sqxjyvg/QAHU4Af0+oHbNvY0PsHlanFeUzCEtwvGbHPa7PIdkMhZJz2t+9ZRxC7TB5MR6BfN+N4gMKBRZhYdA3YaJys4Vl9HU63xNy5eK19V4+XbZXUdEcW6M6cpoSlRJKr1Lns3iT3Ez9fIqKRnsAktxG6b0RU/S4LgdLsnUDjD+xCC1TwxpOPCAWK3yRoEktr5/VEcFuxt2Tnux2Y4mq57YvWiMV3c8awj4HZMeiN2NfkriAkGec4IWp6rcUut6hWiE8rCx6++SJPVL2BiYfeYBGoCLGJzCyssk5ixGLrebZ8vyYaLdKIIqGbmnOarDCjwIu5fjhfHPQq14xD1gUY2AKRQOvpILN4gUQs1PQhUHn76rR/8rCEE Mhu7Wqpl zUci6ZWcrPELpT7mk6NZx+HuLAmVVJihzPiQTmJoVsdzkQ7xOXdGe5ggZsSX7iJ/8PC+TRcRE7QEEEBIavqUIDz5l7U+F763Yg6z9osptX1OdgEddjZe+rmiKo8/S0/s3utPc 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 --- mm/hugetlb.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 51f50bb3dc092..252d6866a0af8 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3475,6 +3475,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) +{ + 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. @@ -3492,7 +3519,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) { @@ -3501,14 +3527,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 */ @@ -3551,14 +3570,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); } -- 2.30.2