From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE3AB396B7F for ; Fri, 12 Jun 2026 04:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781236834; cv=none; b=IvQl0kAbUrfPJVZH05VtvB4NZNd+HwuRYNAtw4FbP4dhkRPak0vv7g46h2wyDCrVR7Byqu+zISOBEq0/zIET7KJ/rrA3tue+L3G9zR1gUlkZ9TXsueHuX5sYFtz6aEfWJRvYGGoRkYe6IeB2ODzifwRyfWOZeLEOyREbXkkk8f4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781236834; c=relaxed/simple; bh=3NPCgiEwkLBDxzBPbFsEw+F5dGGKuyIrsCTTpo+sBkY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pkk8wQxGFJHLJfU4Kngs+eJ0J8l4aNI3U6pbw1/58LzqSCBKrp7XikK7Mn6cVgvwWzOURlMnNdHNYGQLKCO79stX3Q1SvbVuORAAJkGwjqQMHqg7F8akWSxfpwqw/mww539wWzf5mUwoUMXO1whDUAqWhXB7UGROZsmUij79MWw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=ZWIBAV/p; arc=none smtp.client-ip=209.85.210.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="ZWIBAV/p" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-84230ab8857so295539b3a.1 for ; Thu, 11 Jun 2026 21:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1781236832; x=1781841632; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2HtmZnZAkf01rz+eJDlHmM06i2kCJlpB00/bCPPffXw=; b=ZWIBAV/p5/53TxNXk1NT88iBsSwaES/aHiM3eT1KY5Xp7BjJmcPZLaaeJ5SrC29ot3 KITHa3SrX4N967vXKS2ShQXbYt9vzyGRgQ/N0NwlNrGrKOBhmAc1/+Wawetwk3UHDPWD yM64vPML+/rMO8aBTH52ckBxTRdB82+uWlF+ZtCArGsHQ9fLgLUMTj0OeqczXLO+ZhJA eDBYEx2TW7y3WVemtaEsGdsRrFqfMENvVjFmyjWBQ9T8wlUbCJ1Uy8TAyaXc1ysBAe1+ rXYvL+UZChYmsfvy9clfAJ79/k3UiKgnIY/Ftf/d7sIRBGUQxN1jAnDRUooroBH99voe PE1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781236832; x=1781841632; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=2HtmZnZAkf01rz+eJDlHmM06i2kCJlpB00/bCPPffXw=; b=kB8kX75Vu0QMASl13TkuI3Mc472qi5fuJRLKUjQi3pIyBfrey3WdLlI6Zd9YyM2iPE n5dpeHn5h5FbYkEKG7OIVQRtWMT1ZRHg5koi7Vx+ZHnBq0MdHB3r9YyudvAisKr0evRq HPSLRnORBLWP3jc8b9oGNthXcOI257czrvdVgtjG1vm1GPsJ1LZf7PLLI4i2iZ4aRJCK 2VKLrS71Cu6xFp5C+weqkpl7Z52ywFcz4Vif3fQYgaMBAaNIlT5XyYm4wZSSsMAc3tHK O+fB2bddEjd4Qagu1kqtDdF2vK9aojVwoWSGxh1N5pLxghN3BdEUFClV43oIyApT0Uqr l5WQ== X-Forwarded-Encrypted: i=1; AFNElJ+vbWZftQ8mlAETSZxsjBKVNaM46BP94veLz2g4tAPVtaK398liA3yTdyq5muXSm8LXci303gVetAwsOdw=@vger.kernel.org X-Gm-Message-State: AOJu0YxK3l9+/BqDhK/i1dww47AITWtc1P/BPelpn26ZsZ8STIcF+EvX Z3Uf7IstG60wH5tnT0+m5/8OoVA+EOCB6zCruHkLm5oUxu/biPzAQBUP5VnwtqX88w0= X-Gm-Gg: Acq92OGgLQhGtI78QaVEowZYQLz+nHZ9ZMym8Mz4rwrUZI7qaE167b0TAcq2EvbxTbH bMHRauluhJTh80ZPoZHCquJ5LyrATBgKm3j0JDzdXYMq3rdUwAgZbLht39NUVNfkyRvO6oX8Kc3 SwsDLbyv5BKc97sbfpl9tj+aQDL9eWuBHXtMc8QTpd4iE+OaGmCdrgqObwmAZ41opoYTZEqylzd htxDMfPkBR53VqAo/4fU09aus7VRrPHGOfHuQRGeMpKMVudmzmADencdo0UHTtMHs7V97tN03Au IaGOwGkEsGthDEsIwlxWDdvVS/dcXqNNbgIOEpfJkInljkYvM9pXdZ3IYIf+HaewsyuvZ+V96tv evSPlKHdOpXa5xpbO36oDc3psOdUOg9Bu4Yx8uXJfkM2cKWrpUeUdJ85CuHU1AaSSINMi4k5ioL PnT8DVbnRmX61PTCu+ubEMhJYAQzhPKCeeQ9iHQIR7HjGFioGpCn4thA== X-Received: by 2002:a05:6a00:4fcf:b0:842:5711:9a2f with SMTP id d2e1a72fcca58-8434cf4f362mr1184453b3a.36.1781236832074; Thu, 11 Jun 2026 21:00:32 -0700 (PDT) Received: from n232-176-004.byted.org ([36.110.163.99]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8434ad03fdcsm643352b3a.24.2026.06.11.21.00.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2026 21:00:31 -0700 (PDT) From: Muchun Song To: Oscar Salvador , David Hildenbrand , Andrew Morton , Madhavan Srinivasan , Michael Ellerman Cc: Muchun Song , Mike Rapoport , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nicholas Piggin , Christophe Leroy , Ritesh Harjani , "Aneesh Kumar K . V" , linuxppc-dev@lists.ozlabs.org, Mike Kravetz , Muchun Song Subject: [PATCH v4 16/19] mm/hugetlb: Remove obsolete bootmem cross-zone checks Date: Fri, 12 Jun 2026 11:59:00 +0800 Message-ID: <20260612035903.2468601-17-songmuchun@bytedance.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260612035903.2468601-1-songmuchun@bytedance.com> References: <20260612035903.2468601-1-songmuchun@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Bootmem gigantic HugeTLB pages used to be validated again during gather_bootmem_prealloc_node() and any cross-zone pages were discarded there. That validation is no longer needed. Cross-zone bootmem gigantic pages are now detected during allocation and freed before they reach the later bootmem gathering path, so the remaining pages are already zone-valid. Remove the obsolete cross-zone validation, invalid-page freeing, and the associated discarded-page accounting. Signed-off-by: Muchun Song Acked-by: Mike Rapoport (Microsoft) --- v3->v4: - Collect Acked-by from Mike Rapoport --- include/linux/hugetlb.h | 3 -- mm/hugetlb.c | 70 ----------------------------------------- 2 files changed, 73 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 09f28dd773b7..f68a390d43bd 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -678,9 +678,6 @@ struct hstate { #define HUGE_BOOTMEM_ZONES_VALID 0x0002 #define HUGE_BOOTMEM_CMA 0x0004 -struct huge_bootmem_page; -bool hugetlb_bootmem_page_zones_valid(int nid, struct huge_bootmem_page *m); - int isolate_or_dissolve_huge_folio(struct folio *folio, struct list_head *list); int replace_free_hugepage_folios(unsigned long start_pfn, unsigned long end_pfn); void wait_for_freed_hugetlb_folios(void); diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 218fb1ca45f4..47c3d6d11c58 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -58,7 +58,6 @@ struct hstate hstates[HUGE_MAX_HSTATE]; __initdata nodemask_t hugetlb_bootmem_nodes; __initdata struct list_head huge_boot_pages[MAX_NUMNODES]; -static unsigned long hstate_boot_nrinvalid[HUGE_MAX_HSTATE] __initdata; /* * Due to ordering constraints across the init code for various @@ -3221,57 +3220,6 @@ static void __init prep_and_add_bootmem_folios(struct hstate *h, } } -bool __init hugetlb_bootmem_page_zones_valid(int nid, - struct huge_bootmem_page *m) -{ - unsigned long start_pfn; - bool valid; - - if (m->flags & HUGE_BOOTMEM_ZONES_VALID) { - /* - * Already validated, skip check. - */ - return true; - } - - if (hugetlb_bootmem_page_earlycma(m)) { - valid = cma_validate_zones(m->cma); - goto out; - } - - start_pfn = virt_to_phys(m) >> PAGE_SHIFT; - - valid = !pfn_range_intersects_zones(nid, start_pfn, - pages_per_huge_page(m->hstate)); -out: - if (!valid) - hstate_boot_nrinvalid[hstate_index(m->hstate)]++; - - return valid; -} - -/* - * Free a bootmem page that was found to be invalid (intersecting with - * multiple zones). - * - * Since it intersects with multiple zones, we can't just do a free - * operation on all pages at once, but instead have to walk all - * pages, freeing them one by one. - */ -static void __init hugetlb_bootmem_free_invalid_page(int nid, struct page *page, - struct hstate *h) -{ - unsigned long npages = pages_per_huge_page(h); - unsigned long pfn; - - while (npages--) { - pfn = page_to_pfn(page); - __init_page_from_nid(pfn, nid); - free_reserved_page(page); - page++; - } -} - /* * Put bootmem huge pages into the standard lists after mem_map is up. * Note: This only applies to gigantic (order > MAX_PAGE_ORDER) pages. @@ -3287,17 +3235,6 @@ static void __init gather_bootmem_prealloc_node(unsigned long nid) struct folio *folio = (void *)page; h = m->hstate; - if (!hugetlb_bootmem_page_zones_valid(nid, m)) { - /* - * Can't use this page. Initialize the - * page structures if that hasn't already - * been done, and give them to the page - * allocator. - */ - hugetlb_bootmem_free_invalid_page(nid, page, h); - continue; - } - /* * It is possible to have multiple huge page sizes (hstates) * in this list. If so, process each size separately. @@ -3692,20 +3629,13 @@ static void __init hugetlb_init_hstates(void) static void __init report_hugepages(void) { struct hstate *h; - unsigned long nrinvalid; for_each_hstate(h) { char buf[32]; - nrinvalid = hstate_boot_nrinvalid[hstate_index(h)]; - h->max_huge_pages -= nrinvalid; - string_get_size(huge_page_size(h), 1, STRING_UNITS_2, buf, 32); pr_info("HugeTLB: registered %s page size, pre-allocated %ld pages\n", buf, h->nr_huge_pages); - if (nrinvalid) - pr_info("HugeTLB: %s page size: %lu invalid page%s discarded\n", - buf, nrinvalid, str_plural(nrinvalid)); pr_info("HugeTLB: %d KiB vmemmap can be freed for a %s page\n", hugetlb_vmemmap_optimizable_size(h) / SZ_1K, buf); } -- 2.54.0