From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (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 EB26F3E49C6 for ; Sun, 26 Jul 2026 22:23:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.71 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104626; cv=none; b=kaVL6NcrkgXnpnKhEfgdoZyJkFchGBa+bREwfDmQCWBXz8v8IfqIGboeqeZr0zDpcNkHahDtGD39iMjD73a7E6BQgboW5NpBpAfAyYj28ItQUzXQ2m/InoJqihQFvlY9b6VXKoqyOiVlb/yPGIGT3tIzzRs3kR5T2RNDxIg25+U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785104626; c=relaxed/simple; bh=j+HCikzLkgS2/tPP4x4sKGR3lUHP9emCI7dQU8ysM0A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MKEMKJGfR+Y29vwWVG4uoVHTpVMN7GyFNSVepw9huUaflGwWiNCNQH+dOuKDrYOe2jfSySmdVPxX3A1QMWqFtTVN+330/uD/uJWqxGcCRdYdjGzErGTYInYhoHWy60HliIf8BnKM+MlitstphCrIha1Zuly0UzjdA/9/2DaMZr8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=koRwLT6S; arc=none smtp.client-ip=209.85.218.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jackmanb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="koRwLT6S" Received: by mail-ej1-f71.google.com with SMTP id a640c23a62f3a-c1c4715cf0eso202130866b.2 for ; Sun, 26 Jul 2026 15:23:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1785104622; x=1785709422; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=ef2S6P5pckpK+OADyKyUvRFbv0ogGYPuukLQrnlpMOg=; b=koRwLT6SrOqfdVGKx+yHQ7JLkGKl3jSSVdOHeECvIxMRUYHBloE7PWJpMRCLJ14Abl OFONXqwlLwCqY3xlNxsTrdtEpKd8UkpG2t6q5sJq8an2RkIECvuoU2EGVvDoVzy6U2sm TE1N23mClk09EeMNS947QznG4e8SmCVrDMZRW8yHGqmYgXuVCcP9DC08t605kgCAyIDD oU2ky8/wB0aUPYTvq2bz63EhebjA1VblO7Dym2mm6mQoTlfBTEXfBGGg8T11Y733s3Qv bK3n02iswRjO6ECbC0alJSKspH4II9nzCx17M19fSWXQfIdSe6iNy5MBtD08IjmCPiFT /Inw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785104622; x=1785709422; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ef2S6P5pckpK+OADyKyUvRFbv0ogGYPuukLQrnlpMOg=; b=PKraZoLnf3TJ5uyroNk9YjYv/6eHOnwS009uhQm0+Y+Y+46SWdeFPGJErPF+20u63x Zb+IjQQcRQWks7cSh2znCP6QSzBJmHAUn2X1uNg6ddeyvHD3sVBtNNFwhl8fth4uj1Xo 6n4sFCIdKu/DkrgnKyiYaVAu2oyeyRHW4qAs4SHzGGmrP1oUm2CDbX7BjJXmzlc41Xzx 5agJdT/IdtN7C/4G5TN2ad6NtaLUwJRLN/bOW/gJrssWCiDQjBiFhjRW/np24pmUll1Q VCrp6konyqTzIIMZHeA2ha5aZYAcE/hHiaUP6lICyMICcknOtSvwZf1/J8RwUOyCJ4iT 4kXA== X-Forwarded-Encrypted: i=1; AHgh+Rp+T4R4t/ejMAhEKl4NimChFP36OtNQEmF1i0PETaitgc2MB99xVGhMVMJ/2MypCHqjgWFknxLkrC7eQk0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/Rp/RVMjtU+rTIvBjICtAl2Ssfv2THkLlf8IwgA/Cj3c5HHQy 5cRy10zPruE1WrlxgdVJEZ6sYMQpHbIf9ZlvEkQwj5j6upe1AxkUvus60CXfKT0/3hNYJqgFDiC eRk+81tIPSzlPWg== X-Received: from edwp25.prod.google.com ([2002:a05:6402:459:b0:69c:5fcd:d551]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:21c1:b0:69e:648e:2582 with SMTP id 4fb4d7f45d1cf-69fc11697f8mr2129720a12.20.1785104621946; Sun, 26 Jul 2026 15:23:41 -0700 (PDT) Date: Sun, 26 Jul 2026 22:22:48 +0000 In-Reply-To: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> X-Mailer: b4 0.16-dev Message-ID: <20260726-page_alloc-unmapped-v3-15-6f5729aa9832@google.com> Subject: [PATCH v3 15/26] mm/page_alloc: add support for freetypes with no freelist From: Brendan Jackman To: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Vlastimil Babka , Mike Rapoport , Wei Xu , Johannes Weiner , Zi Yan , Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, rppt@kernel.org, Sumit Garg , Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Yosry Ahmed , Patrick Bellasi , Reiji Watanabe , Sean Christopherson , Brendan Jackman Content-Type: text/plain; charset="utf-8" Freetypes are currently just a wrapper for migratetypes, but in a later patch they will gain flags. The theoretically possible space of freetypes will thus grow, but many freetypes will not actually be used in practice. To avoid bloating structures that contain arrays of freelists, mark freetype_idx() as possibly returning -1, and add handling of this case to code paths that will look up freelists by freetype (unless those paths "know" that they're operating on a freetype that has a valid freetype_idx). It never actually returns -1 yet, this is just introduced as a separate patch to make review easier. Signed-off-by: Brendan Jackman --- include/linux/freetype.h | 3 ++- mm/page_alloc.c | 13 +++++++++++-- mm/page_isolation.c | 6 ++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/linux/freetype.h b/include/linux/freetype.h index b16dcd58e184c..3b0d44023b6a1 100644 --- a/include/linux/freetype.h +++ b/include/linux/freetype.h @@ -73,7 +73,8 @@ typedef struct { } freetype_t; /* - * Return a dense linear index for freetypes. + * Return a dense linear index for freetypes that have lists in the free area. + * Return -1 for other freetypes. */ static inline int freetype_idx(freetype_t freetype) { diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 60aedd0e78b54..4965019dc2286 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1963,6 +1963,9 @@ struct page *__rmqueue_smallest(struct zone *zone, unsigned int order, struct free_area *area; struct page *page; + if (freetype_idx(freetype) < 0) + return NULL; + /* Find a page of the appropriate size in the preferred list */ for (current_order = order; current_order < NR_PAGE_ORDERS; ++current_order) { enum migratetype migratetype = free_to_migratetype(freetype); @@ -2406,6 +2409,9 @@ find_suitable_fallback(struct free_area *area, unsigned int order, */ freetype_t fallback_ft = freetype_with_migrate(freetype, fallback_mt); + if (freetype_idx(fallback_ft) < 0) + continue; + if (!free_area_empty(area, fallback_ft)) { if (ft_out) *ft_out = fallback_ft; @@ -3642,6 +3648,8 @@ static void reserve_highatomic_pageblock(struct page *page, int order, static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, bool force) { + freetype_t ft_high = freetype_with_migrate(ac->freetype, + MIGRATE_HIGHATOMIC); struct zonelist *zonelist = ac->zonelist; struct zoneref *z; struct zone *zone; @@ -3649,6 +3657,9 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, int order; int ret; + if (freetype_idx(ft_high) < 0) + return false; + for_each_zone_zonelist_nodemask(zone, z, zonelist, ac->highest_zoneidx, ac->nodemask) { /* @@ -3662,8 +3673,6 @@ static bool unreserve_highatomic_pageblock(const struct alloc_context *ac, guard(spinlock_irqsave)(&zone->lock); for (order = 0; order < NR_PAGE_ORDERS; order++) { struct free_area *area = &(zone->free_area[order]); - freetype_t ft_high = freetype_with_migrate(ac->freetype, - MIGRATE_HIGHATOMIC); unsigned long size; page = get_page_from_free_area(area, ft_high); diff --git a/mm/page_isolation.c b/mm/page_isolation.c index f81186431d3c3..e6bd227fbf1db 100644 --- a/mm/page_isolation.c +++ b/mm/page_isolation.c @@ -176,6 +176,7 @@ static int set_migratetype_isolate(struct page *page, enum pb_isolate_mode mode, struct zone *zone = page_zone(page); struct page *unmovable; unsigned long check_unmovable_start, check_unmovable_end; + freetype_t ft_isolate; if (PageUnaccepted(page)) accept_page(page); @@ -189,6 +190,11 @@ static int set_migratetype_isolate(struct page *page, enum pb_isolate_mode mode, if (is_migrate_isolate_page(page)) return -EBUSY; + /* Do not isolate unsupported freetypes. */ + ft_isolate = freetype_with_migrate(get_pageblock_freetype(page), MIGRATE_ISOLATE); + if (freetype_idx(ft_isolate) < 0) + return -EINVAL; + /* * FIXME: Now, memory hotplug doesn't call shrink_slab() by * itself. We just check MOVABLE pages. -- 2.54.0