From patchwork Thu Nov 23 13:30:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang Li X-Patchwork-Id: 168932 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp450415vqx; Thu, 23 Nov 2023 05:37:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IHwghWoKAZQcjEEgtT3mBrGhQJm99B/SGjrB6SQg1UM4yRRpk3P5JPiUSQjZFL7ef1j32P0 X-Received: by 2002:a05:6a00:2d10:b0:6c6:58ae:b39f with SMTP id fa16-20020a056a002d1000b006c658aeb39fmr7076151pfb.6.1700746628485; Thu, 23 Nov 2023 05:37:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700746628; cv=none; d=google.com; s=arc-20160816; b=C5/JUoliXJl0kECjNucp7NUToFl5Ffx6NwUUwHjAWYhrT3z6kkpvS47GrM9WgWCGkQ jwGSo1aPRpvkxYYKU70F1a2ttWavscs8kegOQK1cAMi5P+E1YKq3mor5lEsSJ2IQ/Ecl TwOabZujmh03t4kWsWe8njxjiDZWLN29HHJX+vQ+LGcaq4WzxcL9+qrzY3+dkx1TDQir c6unu2dyVQzeLsmYwCTN32nak9Th1TuLJOYlNCiZ5+zo9hEEKet9gFsTILnNr5zoSnPR 8jE9P+/cfpVI+ijpPfTfiocN2Lhi3/NPrlN3lh5ZMFH/NDECdQDB543kvBN7u19sF+5l m+uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rZ0xmMUhKXlLEkuqOXd+S2Kz2QguNe+dVlDKaJye92A=; fh=Mfp6tXIfhm0wKwJBfrCMEq/ET4PmqmqmqGe1ZOy3t1A=; b=lpwbjtCliDah3TniNyDdSDJhiVsneX80kYQso4DXMW2//bk0pj58De8rahhU1virSO k7QYvk3kZTcZhoFMaem3RR38r7eDebOP7Won81+Q6qR3Ik7HUtUwNow/Ea8BkPAKvRsY 4nzSOVDm1XAQcuCOXMi1xvStOMi/DofQBjguPUWHeT/MuZ85hclB2QVdPFwfjwB6JPBo LsuirHTyr1pXtGwfHZ79WQ1gCszimvZV6b31MvLd5gMZndlXnsQY9oVp5JtMRuNTeGZ8 ibtqPAeccVyhgeOEN9QJARKNswgXAI77VGnr0R3N0ipTNC4GahHjDaKehv2JmBftJNGl Enag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=PvITNhCa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id j9-20020a056a00174900b006cbab77d0easi1260937pfc.162.2023.11.23.05.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:37:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=PvITNhCa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8BCAA807245A; Thu, 23 Nov 2023 05:37:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345528AbjKWNgc (ORCPT + 99 others); Thu, 23 Nov 2023 08:36:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345495AbjKWNg0 (ORCPT ); Thu, 23 Nov 2023 08:36:26 -0500 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [IPv6:2001:41d0:1004:224b::af]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D59A1B6 for ; Thu, 23 Nov 2023 05:36:31 -0800 (PST) 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=1700746266; 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=rZ0xmMUhKXlLEkuqOXd+S2Kz2QguNe+dVlDKaJye92A=; b=PvITNhCauLhoxZoDafpy0vQRZZqHvieig+ygz0sJ0KwQBDvhV9RPQ7WPfQpMHtWDAup4Yw MSno402iwprJTutoIIV7sPIPvxuHCpkEExhh6mVM441U9SnVOxB2WXeqSKZJ89qeRTXCh6 7CujJmPaqH11kwtg96cXGzPn5Hr9Caw= From: Gang Li To: Mike Kravetz , Muchun Song , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Gang Li Subject: [RFC PATCH v1 1/4] hugetlb: code clean for hugetlb_hstate_alloc_pages Date: Thu, 23 Nov 2023 21:30:33 +0800 Message-Id: <20231123133036.68540-2-gang.li@linux.dev> In-Reply-To: <20231123133036.68540-1-gang.li@linux.dev> References: <20231123133036.68540-1-gang.li@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 23 Nov 2023 05:37:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783362096404508856 X-GMAIL-MSGID: 1783362096404508856 From: Gang Li This patch focus on cleaning up the code related to per node allocation and error reporting in the hugetlb alloc: - 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. This patch has no functional changes. 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 c466551e2fd9..7af2ee08ad1b 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) +{ + 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); }