From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 1C2DE13B293 for ; Wed, 13 May 2026 13:09:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677743; cv=none; b=UsbOiEGKLKR8MbFMI7uESG1ejjv7vRN05Wr0J8T+UU0yIj0wMZAXmXjMJ2xxePHJlFyAbAVKu3B8CHyqgEoBG78zf3bbn3Yu2eazs6xiSWb4O1JF4yPYTtVk0dOLS4dvZNjwWMEIb48ONtMQpJ97OIIdlA2Vtn6K60L8j7S3yDo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677743; c=relaxed/simple; bh=g7rQonfzuhCnlVHFWKhBWFcSbp4oRyi9hMRW4ZJL1VE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XQDBpWgC6WpwuCehy03TH/1ZSxDyBgU+Yiht1fZD5GezNxFPzjxkAceSv5ZZq+dGgoqJSZAcsh6IxA72O9IBJ9Du1HXdfj6bFLmXfKnO8Hw+yOPVuo+5uQB3m6oLUTPgsb48nhM6a4EaFV+UHYjg/bBSWw0w8oAd1l6hsg9VoJk= 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=UG00h5hS; arc=none smtp.client-ip=209.85.214.175 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="UG00h5hS" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2b9fcf7c91bso67452125ad.0 for ; Wed, 13 May 2026 06:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1778677741; x=1779282541; 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=J6ElOBv7vrKvKF8FNit7K/7AGAfvZCZIjE1YfuNh7wQ=; b=UG00h5hSYVtcGZTVlS5IFzRe6jCjDxhxCPc7eJjMw5/EuodNg22MBg8dtj4IWLM9pl 7TPCx01NG8AfcCPEouBImrB2lozRS5TGn68hEXSUsnAVABrCNXiI1RD9ncWprXwUA4Vv j81vkuocn7NnM7ZSYyktzHwkF0iM4fSpyez55l5eC7CczKV2dnIFDm3Jt4gCDtPIOn4H hNbfJ7INEYDwVULDeKUXm/1y3aRlNk4W/1mun+Zu64pz85mPO3KctfkRgNUDgoPx71ms JoFPmGhOtEiQqeta9KaEwZ9m2U2LMu2T3PC1OuRTdXvAhwceBCltO2ZQqgsg/XSJYNqp RxzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778677741; x=1779282541; 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=J6ElOBv7vrKvKF8FNit7K/7AGAfvZCZIjE1YfuNh7wQ=; b=miixtruw1xcL8wQWWDsK63e8aglczJDW2wYCi7Ex9i4NeXYVyqfuiWEUDo346WXhVT lZTIqiE65r+J8s6Dh/kTGafcyF+n5tg1/yfAqDFJykUKcpyNBPSt3Mn314VNWnofKoIb Gy/my0b+jDtcexuHQqoecCr1gZogiac7xc2gSqsRxXdVIlhWumsCbSxgCvZlmbwyk6xO +AssArYGp4mQwJqkbJI4PrYNtxSkxNlgwJYYo0KgsTIjZny66fB5O76ZoSAwultv965E HvDUlMgE7uCGhUKieMXzUETebT1ZyKWMDv9OlNWhMyyeP5GLGCc6VriVJgSjrodNawXY L/Cw== X-Forwarded-Encrypted: i=1; AFNElJ8IQv5eWrvqSZ1GANk188g05O8BO2glNd+IuwE7hyaCKsDVkPwtsArhzESNcEXU2/LMVHhy2Ue8B9MkBvg=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0LK6qCgJipwnPO/c51kRZimvCHs4GtYHa44klG7FYMqJFl0OM n+Fz0EKMcTDrnM+Gkte8tW8VCRtJDyznZRBopFj2c9LPs8SIR6mZA5L1nUIFER23aG4= X-Gm-Gg: Acq92OGxNmzo5/5sYb6yUrT12XjmX/V+7qG3pdNWwN9wLNCxH6UvAzFcZr5kuGAzH92 yHrXdECB2NinZxzEshaFOonLNe5mga0UbpAT6vzmnF7watxi4GAtj3p9mnCqu6Nu12iJSE8hWIl pxasMGy67gYL4xneM7f99vEp3ab5MwHR53FOGbdS4IN9sistKUWEGJ1bf/S4oEExXNN4RaaWoMA jFqAQfhbjzTgeURYDI5fQ4mpjyjjCkzNM/3B3QnOhzd2AjcSUQY/1obL7z94qJ3OVl+M7S8aEHF ohfM23zTMeoHrVoVViu5bBRpbJhKAVUi2IQm0AVclYYJJ/ehFJgy/sBu5DKIMtdQHf9SRDc/Pa3 D3aozbnv1NJyt9eFTnt8fvf1Snn1Txh1NNlLsz75aumAuosy59tHJDA6f3MHRqN2/5l8xkJVnwg 2errA5WYuCFtkNnvKsoiZpPnd0opKndColgvVRXZay7jHB0rIw0H+XivV+40W7p4wXVTG6sA== X-Received: by 2002:a17:903:46c4:b0:2bd:2de3:51ad with SMTP id d9443c01a7336-2bd3043ca95mr32688825ad.34.1778677740889; Wed, 13 May 2026 06:09:00 -0700 (PDT) Received: from PXLDJ45XCM.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm166641925ad.66.2026.05.13.06.08.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 13 May 2026 06:09:00 -0700 (PDT) From: Muchun Song To: Andrew Morton , David Hildenbrand , Muchun Song , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , Ackerley Tng , Frank van der Linden , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v2 16/69] mm/hugetlb: Remove obsolete bootmem cross-zone checks Date: Wed, 13 May 2026 21:04:44 +0800 Message-ID: <20260513130542.35604-17-songmuchun@bytedance.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260513130542.35604-1-songmuchun@bytedance.com> References: <20260513130542.35604-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 --- include/linux/hugetlb.h | 2 -- mm/hugetlb.c | 70 ----------------------------------------- 2 files changed, 72 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 9a65271d167c..ece4e6a4a4c6 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -701,8 +701,6 @@ struct huge_bootmem_page { #define HUGE_BOOTMEM_ZONES_VALID 0x0002 #define HUGE_BOOTMEM_CMA 0x0004 -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 d5d324f69d7a..dcf8e09ec6be 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 @@ -3238,57 +3237,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. @@ -3304,17 +3252,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. @@ -3703,20 +3640,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