From patchwork Tue Jan 2 13:12:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gang Li X-Patchwork-Id: 13509013 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 2847BC46CD2 for ; Tue, 2 Jan 2024 13:13:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B37028D000A; Tue, 2 Jan 2024 08:13:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ABDEA8D0006; Tue, 2 Jan 2024 08:13:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 967EB8D000A; Tue, 2 Jan 2024 08:13:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 83A898D0006 for ; Tue, 2 Jan 2024 08:13:27 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5F63E1407AE for ; Tue, 2 Jan 2024 13:13:27 +0000 (UTC) X-FDA: 81634412454.12.C573030 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by imf16.hostedemail.com (Postfix) with ESMTP id 9C01D18002A for ; Tue, 2 Jan 2024 13:13:25 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=B9yLyBVp; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of gang.li@linux.dev designates 95.215.58.188 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=1704201205; 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=ETU4P5ZGwiSCKQ/C0kQ3RzHFu60VRj1ek3R3KqiB2x4=; b=vC+OduyMiUW7TP78RhqlAWIAtdh0ZxjJnlUPIE5HzWXHhafe92XDA4CsuhQqv5O9T2Ae7A NnOS/5LjZ9x2NWh/C0lJUd4Hlg4pFlDav4OTnjm83bOidDAkx4iK1HykgHKqSSSm3Flh6v sqDvcleSJBismUJeQmNHEasV4slD/50= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=B9yLyBVp; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf16.hostedemail.com: domain of gang.li@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=gang.li@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704201205; a=rsa-sha256; cv=none; b=wP725i0bz76KJtS9I47soULFSAgkIXMJs9DltW6XkbFys38DbQteUkOx0tx2QdZgiuFzAB XIIg7Sp+gldpLFF8RBFS3hXWKz1Id38e+dChDPJmC5WG8s2XOKo7xRshZOQhT19cG07RcY KBeJ7cX3QxSHF2erGTJDbjHVeGRyNWo= 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=1704201204; 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=ETU4P5ZGwiSCKQ/C0kQ3RzHFu60VRj1ek3R3KqiB2x4=; b=B9yLyBVpFwjem6cRBg02/FU+9CM9GKbsl9V80HrvKR7Xo4obGT9RZP65pcS01nZHOo+QLL BoVk6IqxBdZxgvPUdD0cIMvaqetNp8gkUYHpG9SIv8mtTQz6dO7kMQJ+yIvKDYa1e8VSDa 7Rb5Vl4PpfwdO3JiDeI+0+ONiRDKJa8= 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 v3 2/7] hugetlb: split hugetlb_hstate_alloc_pages Date: Tue, 2 Jan 2024 21:12:44 +0800 Message-Id: <20240102131249.76622-3-gang.li@linux.dev> In-Reply-To: <20240102131249.76622-1-gang.li@linux.dev> References: <20240102131249.76622-1-gang.li@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 9C01D18002A X-Stat-Signature: tht819onrzkc8azt86h5kbrgc16sdtwo X-HE-Tag: 1704201205-713561 X-HE-Meta: U2FsdGVkX1/bgJfaQ9//jYlfzLMW/MPvaiJzY//sdkD8AxY7bz+OWRc7dwCe6dqVzDeK+qY6EJEQo2IjL6jARupH0fuKbVDKsShczkCgjVg1O2DIfedVB5b3KwLceTfjI/UH0UQoqcucgFKTHxrzzTggcCXES5Of+U9UnvkV5sfJim4VJ4PMgmgDRNQSKASeVq6Q+/aCCDWfwOV64TASnzA8iVPrQzRXly1nBvz2iPwB77aSlFWZDgmqm1wTbJbN9xe4LNZuROHqONbO1G/MCDlMpoUL5mGRKtbU9mO5/YhTRUyoh1WW0pPnnQWFA14kNvIutPC195PY2H3PaAeps9DCc8NmacU3lT4NCI3jOVfP+PvFiKrxQJrm493WXXKK06p0EdNJnYt9oWUGq/w97PIIO221z7SKzE7lDBG80D0eOBwXhvJ9RDBM0HfYdrbu8HLH64VslwrplhoHPzIW13VJFPICjdHJHS2rER3C/j6lfDdidEHgU4NAWoTijL0Rw6HiccX8B7sAkz40TFapCfu7nqUgBoo2UaaoLASEiUZBrx9mrj04AkJufphU3XHcvNN+ZE+zrQoohC2Mfp7M5Amau0XI9cKzRAHSSs5QBISWewRM3+GsY2fjfNTAEO96vEU03F76EXGFnTwSp8jrg4KWEV8tKn1oQ5CF4nzl+4UUdJ9k149gZZjnovKdXlBUDlrH3QOkA56FmsbM6F9zOtquCEXX7X33eOiWxS2lpVl8ceCIoJC2pvGXlkzOgxAppAn4rULdyauUujAzEadbFRz/GXaulCluvGvLqPhtS91tK+sb//H0xQc8a8taDwP2qm9uHBD70xEoifEQDXZ8pj9q0bgGoJvjb3mrUNY+gcSE+BzHXdd2sSBRmG/XBu9+ifQ62RiWx1VjJlaVhm83kpvAfkm5dPNLGgOUl1/mLl2rNYACO1mWxy/HOrROxjFBFNZ3A3mbGvX/aXjxK9Q pwVzQnaf kDCa8GzVEKExCBIzJ6c1h9OVrgqTni90F60NwUS6t+EOdfYyPUncS77DHddYZA6pedyDEfBNoEh2YSyK7ylBf5wvIT3KTrH90O96+Ifvlnb2yrPHZrFdGdAB2/zlSa/H3ft3I 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 --- mm/hugetlb.c | 86 +++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 2606135ec55e6..92448e747991d 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)