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); } From patchwork Thu Nov 23 13:30:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang Li X-Patchwork-Id: 168931 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp450224vqx; Thu, 23 Nov 2023 05:36:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IECKmVosoe8K642mrjRaowJ+ePkcb/DcOYknP55vnUEUdvhxN9ze1CSuZ1JsCuY2wdF/Ksc X-Received: by 2002:a17:90a:3fc7:b0:280:37a0:69d4 with SMTP id u7-20020a17090a3fc700b0028037a069d4mr3684137pjm.19.1700746611394; Thu, 23 Nov 2023 05:36:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700746611; cv=none; d=google.com; s=arc-20160816; b=kaLrtovZeI7oTs0+PPX5i4DdfTvAJdzyP0dTB4YTKYZbCQRhRPMxSwgPgkTjeY11Lf AMVZ9XC+18/OyZ2GRwXOGdqJdetMHpuL8YO4WpLAvvznRua29t99qlZQB7lg0mKfv7WG u72lJxZx1jq68wRmXSP3PIzdAppDb3ONYjhYbbG5kgAcO0hcWwP2LHUf8cwqsa2FqFH2 Aax5nf+QIDfcU6die8dZXehYrGcOzCS/g38kTE1FHfNP7Na2YfP+xNwWOSZA9ahNcz23 xU1CAZ3NzkWx9NZDWeLQL8kt4lk5vIXd3QbAmb4lqHZVpxmzHwhZ5BoLcgiJxeMDGd/l LuAA== 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=nGnKScZww5hZXWYTDAjHhsju7kmgmcYLYNYxHMYgc28=; fh=Mfp6tXIfhm0wKwJBfrCMEq/ET4PmqmqmqGe1ZOy3t1A=; b=jV6TjEQdtHyl6PvQudZbEyGQo9oGskoAh+L+KMQiciVIZs2G+tlZ2fAZVNjfDPFxN9 1eTr+7KlenWgwztjAfy18nX9vnrPmhvOOU6977YMPaDYK7S4EtTlUXhT0rHdXdsZ3w10 A1bnUJAl/0b+DfDBvgNqfaykAcZvehKFojHKLn7Cf6VkhawFPNR9IsPdsDNHM3rBOanQ iE8PV69WZVMXh8mRR0Hk4c8Xd9uhfXMhp+waQj33LAzHs9VqxtxH+FUWbzbER7pfClSP fGDt8YTHtYvgyzg6g1kzu7wuy3v3YYglgIk9XPyS4Kr1bXcMI9u3/WOOtKo1+cGKW3Ow FDwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=d5CHLX57; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id o2-20020a634e42000000b005c1cc7273bbsi1279397pgl.746.2023.11.23.05.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:36:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=d5CHLX57; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id D358B8087508; Thu, 23 Nov 2023 05:36:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345516AbjKWNg3 (ORCPT + 99 others); Thu, 23 Nov 2023 08:36:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345493AbjKWNg0 (ORCPT ); Thu, 23 Nov 2023 08:36:26 -0500 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [IPv6:2001:41d0:1004:224b::b3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAA12BA 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=1700746269; 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=nGnKScZww5hZXWYTDAjHhsju7kmgmcYLYNYxHMYgc28=; b=d5CHLX57cCOGxJdVkM1Rcs5gK8JkZKtdzrPAWDsIIXnn4bLS2WT8PJZozgQuz0CNFwb0nc 0T867ikyskX4+1d3xr9U6o5B04QY6IGfw21Vn6rpkQHu8CmkuXfiaUXsViDqqNzM3Lwggu BarejmtOHYkPWa7BTb5kD5s+K+Zxa3w= 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 2/4] hugetlb: split hugetlb_hstate_alloc_pages Date: Thu, 23 Nov 2023 21:30:34 +0800 Message-Id: <20231123133036.68540-3-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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 23 Nov 2023 05:36:43 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783362078894590644 X-GMAIL-MSGID: 1783362078894590644 From: Gang Li Split hugetlb_hstate_alloc_pages into gigantic and non-gigantic. These patch has no functional changes. Signed-off-by: Gang Li --- mm/hugetlb.c | 86 +++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 7af2ee08ad1b..7f9ff0855dd0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3509,6 +3509,47 @@ static void __init hugetlb_hstate_alloc_pages_report(unsigned long allocated, st } } +static unsigned long __init hugetlb_hstate_alloc_pages_gigantic(struct hstate *h) +{ + unsigned long i; + + for (i = 0; i < h->max_huge_pages; ++i) { + /* + * gigantic pages not added to list as they are not + * added to pools now. + */ + if (!alloc_bootmem_huge_page(h, NUMA_NO_NODE)) + break; + cond_resched(); + } + + return i; +} + +static unsigned long __init hugetlb_hstate_alloc_pages_non_gigantic(struct hstate *h) +{ + unsigned long i; + struct folio *folio; + LIST_HEAD(folio_list); + nodemask_t node_alloc_noretry; + + /* Bit mask controlling how hard we retry per-node allocations.*/ + nodes_clear(node_alloc_noretry); + + for (i = 0; i < h->max_huge_pages; ++i) { + folio = alloc_pool_huge_folio(h, &node_states[N_MEMORY], + &node_alloc_noretry); + if (!folio) + break; + list_add(&folio->lru, &folio_list); + cond_resched(); + } + + prep_and_add_allocated_folios(h, &folio_list); + + return i; +} + /* * NOTE: this routine is called in different contexts for gigantic and * non-gigantic pages. @@ -3522,10 +3563,7 @@ static void __init hugetlb_hstate_alloc_pages_report(unsigned long allocated, st */ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) { - unsigned long i; - struct folio *folio; - LIST_HEAD(folio_list); - nodemask_t *node_alloc_noretry; + unsigned long allocated; /* skip gigantic hugepages allocation if hugetlb_cma enabled */ if (hstate_is_gigantic(h) && hugetlb_cma_size) { @@ -3539,46 +3577,12 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) /* below will do all node balanced alloc */ if (!hstate_is_gigantic(h)) { - /* - * Bit mask controlling how hard we retry per-node allocations. - * Ignore errors as lower level routines can deal with - * node_alloc_noretry == NULL. If this kmalloc fails at boot - * time, we are likely in bigger trouble. - */ - node_alloc_noretry = kmalloc(sizeof(*node_alloc_noretry), - GFP_KERNEL); + allocated = hugetlb_hstate_alloc_pages_non_gigantic(h); } else { - /* allocations done at boot time */ - node_alloc_noretry = NULL; - } - - /* bit mask controlling how hard we retry per-node allocations */ - if (node_alloc_noretry) - nodes_clear(*node_alloc_noretry); - - for (i = 0; i < h->max_huge_pages; ++i) { - if (hstate_is_gigantic(h)) { - /* - * gigantic pages not added to list as they are not - * added to pools now. - */ - if (!alloc_bootmem_huge_page(h, NUMA_NO_NODE)) - break; - } else { - folio = alloc_pool_huge_folio(h, &node_states[N_MEMORY], - node_alloc_noretry); - if (!folio) - break; - list_add(&folio->lru, &folio_list); - } - cond_resched(); + allocated = hugetlb_hstate_alloc_pages_gigantic(h); } - /* list will be empty if hstate_is_gigantic */ - prep_and_add_allocated_folios(h, &folio_list); - - hugetlb_hstate_alloc_pages_report(i, h); - kfree(node_alloc_noretry); + hugetlb_hstate_alloc_pages_report(allocated, h); } static void __init hugetlb_init_hstates(void) From patchwork Thu Nov 23 13:30:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang Li X-Patchwork-Id: 168934 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp450506vqx; Thu, 23 Nov 2023 05:37:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGQX8gF0+ptR/lRJKJ0SoL1+RN40R4qRwgGQu1A9ppF6OPsdkFVi/lNdvyEBgNPTZ0MJ+G X-Received: by 2002:a05:6a20:8e28:b0:187:449d:a4cd with SMTP id y40-20020a056a208e2800b00187449da4cdmr3234326pzj.27.1700746636764; Thu, 23 Nov 2023 05:37:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700746636; cv=none; d=google.com; s=arc-20160816; b=F3o1Y9FqN/sD8jWPyVot6k+RWFHJM/qr997wICrIMWAht/I2eFXQCBchTo8pQaS6ix oNCrYTg0+M6U9U0r/zuyg7RTkivOAuFADcbjnln29XsVXhWsd5m+MJHRJF86yfZHQZNa jzhgT/j1iJ1t+5UoZ8/E5rNBmAylPsS+9o5UVFTkBW5nA9v67lrldI2+dawBYAV4PodU lq/17R+u1A20uQHyw1skDgc5PBz8/5aEvnWsSYqRvZZv/TSZIhrB+HH0sQs4wPtB3fvn mkSp7lwZWqIrjGYUNfxqCpvpsrCUp6flURYDeDDnG+nJkQcvRDC06WlUUf29Q8OJtnLV 65/g== 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=ZmVKGX3xWVsiaI1L9mmzJOcNAtj7qPzayoGRggtSBII=; fh=Mfp6tXIfhm0wKwJBfrCMEq/ET4PmqmqmqGe1ZOy3t1A=; b=XyiHQ9mRUDCI1g+pdrLOHeVakBq4EIRXt5Fh4713csiTzCJmBUwo/y3bn5TL8uJx/x VTHvu07FQTr8UDWgdYMApnKzBE3GY/0BNlfDdn6UySBfgY9zwR9+1/HxWJjawNkRchYU uR3FEjycNQgi94O+ad/CkesBvYmuVw4fz4Tt8f62R7zurg/VrCNri/TC8cWC4Z715iPR XUOXTGBOlHs7p/1ntQbYYPQ90ybc7cd5H+aNSgIhf8KP+5a0wjl036yPpkG7lNT8VxWB GaXTnmpfltvdVEIUpxhFh6/k2sEiVFqIU8tLgzaxQYPcTwNAq8oleH3tBUeDurty+IuV 3Wow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ztzwn0HQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id j6-20020a056a00130600b006cb4c6074c8si1249338pfu.311.2023.11.23.05.37.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:37:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ztzwn0HQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 120938329A28; Thu, 23 Nov 2023 05:37:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345557AbjKWNgj (ORCPT + 99 others); Thu, 23 Nov 2023 08:36:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345504AbjKWNg0 (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 DAABD1B3 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=1700746272; 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=ZmVKGX3xWVsiaI1L9mmzJOcNAtj7qPzayoGRggtSBII=; b=Ztzwn0HQtIgdF3nrfOjRTmuus6uH05VuvO5saXWr5t12Q51VOnt0v0Tdqe3fTgV29LfEAj ZlpS/GGfT1xwjVdXl9k5LFCEe038RDKIRwdprffhWUuffvY73PgEemYmViGVybE5iBDRMn 6grrj48RxSO/qOyc0/yPWH8AYNiUtwQ= 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 3/4] hugetlb: add timing to hugetlb allocations on boot Date: Thu, 23 Nov 2023 21:30:35 +0800 Message-Id: <20231123133036.68540-4-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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 23 Nov 2023 05:37:14 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783362105266948423 X-GMAIL-MSGID: 1783362105266948423 From: Gang Li Add timing to hugetlb allocations for further optimization. Signed-off-by: Gang Li --- mm/hugetlb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 7f9ff0855dd0..ac8558724cc2 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3563,7 +3563,7 @@ static unsigned long __init hugetlb_hstate_alloc_pages_non_gigantic(struct hstat */ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) { - unsigned long allocated; + unsigned long allocated, start; /* skip gigantic hugepages allocation if hugetlb_cma enabled */ if (hstate_is_gigantic(h) && hugetlb_cma_size) { @@ -3576,11 +3576,13 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) return; /* below will do all node balanced alloc */ + start = jiffies; if (!hstate_is_gigantic(h)) { allocated = hugetlb_hstate_alloc_pages_non_gigantic(h); } else { allocated = hugetlb_hstate_alloc_pages_gigantic(h); } + pr_info("HugeTLB: Allocation takes %u ms\n", jiffies_to_msecs(jiffies - start)); hugetlb_hstate_alloc_pages_report(allocated, h); } From patchwork Thu Nov 23 13:30:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang Li X-Patchwork-Id: 168933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp450418vqx; Thu, 23 Nov 2023 05:37:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEKEXkh6LY5PaY+1WOjBLSd1eJpVPPAit6cEty82TcQIXYUpcxji7gIA2ESQdwtAPm5KxmG X-Received: by 2002:a05:6a20:441a:b0:18b:30d1:fcab with SMTP id ce26-20020a056a20441a00b0018b30d1fcabmr6130289pzb.59.1700746629198; Thu, 23 Nov 2023 05:37:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700746629; cv=none; d=google.com; s=arc-20160816; b=es9Cw8OXVVj0eXs3d/EobGb+XS3dGvvqE+U502EyV8ncvzvmL/5Gdj7RqDUjRiuf2c 6jIWKXopIj4NVIYp3SkQuhw+CwNJQbv9LR2Oy6XCPetXh4UwB3NS9b7joCYfdVz6razF awAx00g0B+n/zNzHRAxnJ3iznfByKhIbUlvQ2iEw/SJybtcFL0DAIweb0hDcC1Gd8wdk nqEPogl4HtmL7BqNu4xH64cBmqmhcvrVBayOlS9geN2zpu+7/jqKpplsMLAeLv1tX+QI KEqCyQ1EkW9AW3OHEAnzNW13qDd9BqPlhqV0ugZtZuhhncBP1OETJq/Zn/tWPDWWV3/Y 9GdA== 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=SVmsj9TN/aj38n19fqlW2b7zQkW3VvgWG56LLSCGces=; fh=Mfp6tXIfhm0wKwJBfrCMEq/ET4PmqmqmqGe1ZOy3t1A=; b=JJbUCsqzNs7Nh544jJIu2NXmmGLLlLVftKslulDrWpefkrdzO5cxPdPWkVmtMKOPuF s2gfP3VDiiHd79mR/ykcKPowLArsyHhPhg+DBTRWKHy3L9UlMnxCiezbS7JEnPxkBpJC 4GliiLihQCiJLCFx19bb2pWxwP8cmV3nA8MWg+EjP10XGZboh96i42/4X9J2zurV8ctm dYrTI+rz0tAW+gjuuBSPRkBDxy05gSt8KI7HwVQgQKiQ7zJzEDW6UJD2C8KCK9+ey7aY DfmaEnRD6ItqokeD19aatR5HcRtgEvxDHD4fJxidUeElSSf62lbGYBnyRZVbAhetyr2f OVPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Y71JssED; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id z24-20020a17090acb1800b00285479be838si1291842pjt.179.2023.11.23.05.37.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:37:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Y71JssED; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 119BA8329A28; Thu, 23 Nov 2023 05:36:36 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345509AbjKWNg1 (ORCPT + 99 others); Thu, 23 Nov 2023 08:36:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345468AbjKWNg0 (ORCPT ); Thu, 23 Nov 2023 08:36:26 -0500 X-Greylist: delayed 326 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 23 Nov 2023 05:36:31 PST Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [IPv6:2001:41d0:1004:224b::ba]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A04B81A8 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=1700746275; 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=SVmsj9TN/aj38n19fqlW2b7zQkW3VvgWG56LLSCGces=; b=Y71JssEDzrYWYNV34cyzjaSirgHK0BrpKRWoKYtD+NlDt+B0BHOaS3CWA9Uyhz5yKbgj6g PimBt6l7h2P4kLFfkV0n8MPPjcmR9a/NNorQu2gY5FzktxNGVTBcPtxXi8OV6XSHGDx82i xNn/ddoatbelzCFAmHSUzrB3UJs23Jc= 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 4/4] hugetlb: parallelize hugetlb page allocation Date: Thu, 23 Nov 2023 21:30:36 +0800 Message-Id: <20231123133036.68540-5-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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 23 Nov 2023 05:36:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783362097482201422 X-GMAIL-MSGID: 1783362097482201422 From: Gang Li By distributing the allocation across threads, large hugetlb configurations can allocate pages faster, improving boot speed. Signed-off-by: Gang Li --- mm/hugetlb.c | 89 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 74 insertions(+), 15 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index ac8558724cc2..df3fbe95989e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3509,6 +3509,55 @@ static void __init hugetlb_hstate_alloc_pages_report(unsigned long allocated, st } } +struct hugetlb_work { + struct work_struct work; + struct hstate *h; + int num; + int nid; +}; + +static atomic_t hugetlb_hstate_alloc_n_undone __initdata; +static __initdata DECLARE_COMPLETION(hugetlb_hstate_alloc_comp); + +static void __init hugetlb_alloc_node(struct work_struct *w) +{ + struct hugetlb_work *hw = container_of(w, struct hugetlb_work, work); + struct hstate *h = hw->h; + int i, num = hw->num; + nodemask_t node_alloc_noretry; + unsigned long flags; + + /* Bit mask controlling how hard we retry per-node allocations.*/ + nodes_clear(node_alloc_noretry); + + for (i = 0; i < num; ++i) { + struct folio *folio = alloc_pool_huge_folio(h, &node_states[N_MEMORY], + &node_alloc_noretry); + if (!folio) + break; + spin_lock_irqsave(&hugetlb_lock, flags); + __prep_account_new_huge_page(h, folio_nid(folio)); + enqueue_hugetlb_folio(h, folio); + spin_unlock_irqrestore(&hugetlb_lock, flags); + cond_resched(); + } + + if (atomic_dec_and_test(&hugetlb_hstate_alloc_n_undone)) + complete(&hugetlb_hstate_alloc_comp); +} + +static void __init hugetlb_vmemmap_optimize_node(struct work_struct *w) +{ + struct hugetlb_work *hw = container_of(w, struct hugetlb_work, work); + struct hstate *h = hw->h; + int nid = hw->nid; + + hugetlb_vmemmap_optimize_folios(h, &h->hugepage_freelists[nid]); + + if (atomic_dec_and_test(&hugetlb_hstate_alloc_n_undone)) + complete(&hugetlb_hstate_alloc_comp); +} + static unsigned long __init hugetlb_hstate_alloc_pages_gigantic(struct hstate *h) { unsigned long i; @@ -3528,26 +3577,36 @@ static unsigned long __init hugetlb_hstate_alloc_pages_gigantic(struct hstate *h static unsigned long __init hugetlb_hstate_alloc_pages_non_gigantic(struct hstate *h) { - unsigned long i; - struct folio *folio; - LIST_HEAD(folio_list); - nodemask_t node_alloc_noretry; + int nid; + struct hugetlb_work *works; - /* Bit mask controlling how hard we retry per-node allocations.*/ - nodes_clear(node_alloc_noretry); + works = kcalloc(num_node_state(N_MEMORY), sizeof(*works), GFP_KERNEL); + if (works == NULL) { + pr_warn("HugeTLB: allocating struct hugetlb_work failed.\n"); + return 0; + } - for (i = 0; i < h->max_huge_pages; ++i) { - folio = alloc_pool_huge_folio(h, &node_states[N_MEMORY], - &node_alloc_noretry); - if (!folio) - break; - list_add(&folio->lru, &folio_list); - cond_resched(); + atomic_set(&hugetlb_hstate_alloc_n_undone, num_node_state(N_MEMORY)); + for_each_node_state(nid, N_MEMORY) { + works[nid].h = h; + works[nid].num = h->max_huge_pages/num_node_state(N_MEMORY); + if (nid == 0) + works[nid].num += h->max_huge_pages % num_node_state(N_MEMORY); + INIT_WORK(&works[nid].work, hugetlb_alloc_node); + queue_work_node(nid, system_unbound_wq, &works[nid].work); } + wait_for_completion(&hugetlb_hstate_alloc_comp); - prep_and_add_allocated_folios(h, &folio_list); + atomic_set(&hugetlb_hstate_alloc_n_undone, num_node_state(N_MEMORY)); + for_each_node_state(nid, N_MEMORY) { + works[nid].nid = nid; + INIT_WORK(&works[nid].work, hugetlb_vmemmap_optimize_node); + queue_work_node(nid, system_unbound_wq, &works[nid].work); + } + wait_for_completion(&hugetlb_hstate_alloc_comp); - return i; + kfree(works); + return h->nr_huge_pages; } /*