From patchwork Fri Jan 26 15:24:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang Li X-Patchwork-Id: 13532816 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 690EBC47DDF for ; Fri, 26 Jan 2024 15:25:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F35FA6B0087; Fri, 26 Jan 2024 10:25:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EE62B6B008C; Fri, 26 Jan 2024 10:25:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DAE016B0092; Fri, 26 Jan 2024 10:25:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CB51E6B0087 for ; Fri, 26 Jan 2024 10:25:07 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9C20C120FE4 for ; Fri, 26 Jan 2024 15:25:07 +0000 (UTC) X-FDA: 81721835454.06.4B8CF42 Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf15.hostedemail.com (Postfix) with ESMTP id B87A4A0007 for ; Fri, 26 Jan 2024 15:25:05 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=NIN5KgkQ; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf15.hostedemail.com: domain of gang.li@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=gang.li@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706282705; 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=EpmnH1heqxiT9L2xvocYTAQyyeV+M8p6qSwgZH/mouw=; b=OAwx1Rnb9pCl00or6BR9bG8hgFEyt7XFoylTv8l30V7LZTmEwHWfF4a0rp2xknTYceL9xn uF83oZ77lPi5T29Xh7STViHNBA86Mv/qK89SkZ8+3RnveFUk/Mg+qjv29DkVtvJ0Irq6lZ PWggSHgON6ztmqZUZHRCS8NlgdDrn30= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=NIN5KgkQ; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf15.hostedemail.com: domain of gang.li@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=gang.li@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706282705; a=rsa-sha256; cv=none; b=bmCUUZzjWkIJ74E39LsfS+MCDfueUjrcRgOP8wZKjV1dcWUHUmL8kdel2UMP+1l9FAc4pa Pw2d+Wp9zD9oWr4rBkn+BtBFwrqYFkiNjwB3b6HInD/h0OGz+cw73aaU0BMT2QPxxJ9hgV voc9g1xp4QdjxMgh+KkpAlaW0RSfa7o= 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=1706282704; 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=EpmnH1heqxiT9L2xvocYTAQyyeV+M8p6qSwgZH/mouw=; b=NIN5KgkQ6ktwWa4GiDjUdAl7RaNOrgEmptJXjSAwQxyyMDJcoijL2+TDpy7yOmpIZkDhsL OSnefDgiw31H9dPHL9T6oBqYiSboHE9E7/g4GRKZgZb0/NDBZi/sa0bL1SshUOSqTeY3cu /G8p+dcISN/5OT93ypM/kpclSHGR/Kg= 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 2/7] hugetlb: split hugetlb_hstate_alloc_pages Date: Fri, 26 Jan 2024 23:24:06 +0800 Message-Id: <20240126152411.1238072-3-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-Rspamd-Queue-Id: B87A4A0007 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: kknawb561iektipqym9z5s9a8mbp34zr X-HE-Tag: 1706282705-667633 X-HE-Meta: U2FsdGVkX1/rHUIPDf0sjqhMqKtqgnrmJWeMeImzz/hreTc0P4rJwFvvlprHosYWL22T/oPlhx/BtSn0E5qX+TIAdfqwT86b1yYUpl57H8dSQjx35VahJF+6rj3sF1EzBqDCEBAK/V7oCuNUZblbCa7QVIsA4fN15i2UJMfdttb7GRllFRYYHpSjKNZLmpC+rSLnzxqQtjY7G+l/PucGLebNv+TmlshCXaeaLX6rbbWTm+MwrrAZ+ynithQnW9ZKA/Ix7LJK/FhWy02+gsi+NKPV25TJJKn9+ixS5hrBDkb0aiF/LLjjIXDn71W8n7v40pmQLK/yoJKOtHH7MltrcLrIgho8KeYg+UJnoPQu6GRn9pfXDfdW/doC8c5YBISlJ/Jkwe+vsyqlaDEgPsTPPXacMDomy9uYNReD8bvuUIXBKgF95QiO0HZ99NfdY1nJsA26ro59+23uXjLGftby3PtDU1e3ibt9SHTu6oHtah+CcFesE9DOFz4cUsOHAY8OernI0Cn7udqhoA6NDgcFkwq0IhBUBKXFw5MeVU96CNiwMBEeXoZtPNNyh74mabx/6dEJnQzm0LlycnxrQgqJjz+/RIiFlw5Y6Y06Y13SH2MO612EHT8sAPateodqqPXIYSABZX41qsDSCJTkFpfUrThRwDBz7h7U8+BerLyXXquQHxs/9PGOm3STuYlzsC4oEwFt23iEX8RpJ2/WTWEm6JQCYujWMgaeIC3/VqF9uyRz1+krCagEdpW2nPhm2Uzkxf8ArKtVHbeHVwYQkoUNs6EfQCJnkgkSomxHIYh+JfH6wQM9pAbTvdVj30PwhYH1jykygCN09CYdmvIL5OZrHuHrZNDm4rvBiXcdnAJCIP1SuDMcwoh/0i95Ia5JrKgQNuGRQKpu9FkcohkSh+ExIDbAzma4Zhoeh+CsNUv0gYwHPSZdAUHzce3wCUwHucDV5EqC0YzlR1c0RgC5Jwg 9+imsjfR f11ym+/N+S9HCyUENS7DsyZm9hdp5TsKrgNI1m++YiFpMc36tYnyluC63h5p3lL8fX6y1nnxhLe9v4iyv9wlLf9xuva8t7pAQVGYE73bmIKKH+/cKqpuzjY3/QWzI+EndLQrLfklyOgyt/VoDSCbPDifjnWG7HL29WdfhWVLDcTxngzD85bcJ9zTK0mSBJ/gmjSF/qW53lw3Ll2JoRERSggTLwMyF8ilDQC2YqhhBZ2X2bUE= 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: 1G and 2M huge pages have different allocation and initialization logic, which leads to subtle differences in parallelization. Therefore, it is appropriate to split hugetlb_hstate_alloc_pages into gigantic and non-gigantic. This patch has no functional changes. Signed-off-by: Gang Li Tested-by: David Rientjes Reviewed-by: Tim Chen Reviewed-by: Muchun Song --- mm/hugetlb.c | 87 ++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 20d0494424780..00bbf7442eb6c 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3509,6 +3509,43 @@ static void __init hugetlb_hstate_alloc_pages_errcheck(unsigned long allocated, } } +static unsigned long __init hugetlb_gigantic_pages_alloc_boot(struct hstate *h) +{ + unsigned long i; + + for (i = 0; i < h->max_huge_pages; ++i) { + if (!alloc_bootmem_huge_page(h, NUMA_NO_NODE)) + break; + cond_resched(); + } + + return i; +} + +static unsigned long __init hugetlb_pages_alloc_boot(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 +3559,7 @@ static void __init hugetlb_hstate_alloc_pages_errcheck(unsigned long allocated, */ 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) { @@ -3538,47 +3572,12 @@ static void __init hugetlb_hstate_alloc_pages(struct hstate *h) return; /* 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); - } 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(); - } - - /* list will be empty if hstate_is_gigantic */ - prep_and_add_allocated_folios(h, &folio_list); + if (hstate_is_gigantic(h)) + allocated = hugetlb_gigantic_pages_alloc_boot(h); + else + allocated = hugetlb_pages_alloc_boot(h); - hugetlb_hstate_alloc_pages_errcheck(i, h); - kfree(node_alloc_noretry); + hugetlb_hstate_alloc_pages_errcheck(allocated, h); } static void __init hugetlb_init_hstates(void)