Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2082584rdb; Thu, 7 Dec 2023 18:53:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKZu18s7bjAZHVCO2zOBB5Cl55H5DyJp5XLuHQnzxtwMKMqkCaLtF8HQgRZATunvQZbiEv X-Received: by 2002:a05:6a20:a2a0:b0:18f:97c:8261 with SMTP id a32-20020a056a20a2a000b0018f097c8261mr2719229pzl.107.1702004017609; Thu, 07 Dec 2023 18:53:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702004017; cv=none; d=google.com; s=arc-20160816; b=Bu8meUNnHm5uOIEMHUwV845limYSv+SriiPSTB8zhRXvYQpRX4FishZ3cSiSENXgX1 KSfpwJx57Q2CDgg/fyULmFselGZ7dC0I6hJkV3lAPTDl9sXAQJp0N53gACRBqMIX9NhI W4reHQ40yJ5LbXkhe6R88wbcDIGnm10UYkn71SkCCkhTZfhYAI1M43vAMKL7amvPJYAs 0qt7yj4zHcNQ4gqfGDvNwMZnOlXVLWwtsRWwbRCvgKYvY+bw8QeI46ANICa9/6yHMnpa TgUp/K4pWAlgIvZY15e+BbZwTFt7U2l1lY9nJUtr4JoezqY3qBXKObBmWJeICU9vZ4e/ IyLw== 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=n5rlcvDOEWSjvMRr90AdsF4YIrGIogPwB5/wbnheBkQ=; fh=ALVB2amNZc7wpwPN7EU8i4C3eL0OH515L0QoCIRQrQE=; b=vC90S32dF3mPq5TahZ7Tj9vjB+YCimFp6ho7IgMBwhMmqIKzCSndKbyLD3qCTSRFrq gusIyHsKoZQaTUhNSTVX3ihHT99yilrEKrjSiTXmTNoGZWqIhq//rLglmm5P8Gzx9hcb FkkiafhXsvd/INKR9/szQYtfvG/oSrKLWjyZuh3LnVoyVpG94rx9Up2e4aPUMoF6GtXe MIXhSygYnVcswUBcb5674BCcm74Vj1tHKKtD1pHsjtrdv52WmRAppoeD7hASrq1ut2iX LVzBehE3XVBd9mRt+TNyvnklxik5rTtsovmhVeSTwFIPJpNHPl3Hi9oFnRttMRi3vdLo fAQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=IHnb3dgP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id jd5-20020a170903260500b001cfb5471961si740486plb.274.2023.12.07.18.53.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 18:53:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=IHnb3dgP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id 86AF780FCCB6; Thu, 7 Dec 2023 18:53:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1573016AbjLHCxH (ORCPT + 99 others); Thu, 7 Dec 2023 21:53:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbjLHCxF (ORCPT ); Thu, 7 Dec 2023 21:53:05 -0500 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [IPv6:2001:41d0:1004:224b::ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 645681715 for ; Thu, 7 Dec 2023 18:53:11 -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=1702003990; 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=n5rlcvDOEWSjvMRr90AdsF4YIrGIogPwB5/wbnheBkQ=; b=IHnb3dgPdv0XvvyaI7QPgxVi6IP+FjK3KVXTcR25SvOJ6PmLr1x9emJ+YfIcImJVapgyzg uJKyXe9nXu/y0CFNFbZWwF2f89s3kEfY8JD/9hR223k4PKPEJhAu3rW0LY4r//U8QAMS8M e2PUBAGxjgBmp5nM2aTp82P5yZ+s6bI= 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 2/5] hugetlb: split hugetlb_hstate_alloc_pages Date: Fri, 8 Dec 2023 10:52:37 +0800 Message-Id: <20231208025240.4744-3-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-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 fry.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 (fry.vger.email [0.0.0.0]); Thu, 07 Dec 2023 18:53:32 -0800 (PST) 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 252d6866a0af8..8de1653fc4c4f 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3502,6 +3502,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. @@ -3515,10 +3556,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) { @@ -3532,46 +3570,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) -- 2.30.2