From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) (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 D2BFB3DA7FC for ; Wed, 25 Feb 2026 16:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037286; cv=none; b=dE9WaMwyX/izpmjUHtgk2hSZ+h+pzCxZYHj1ubwInpxC/jOvYKDmuRhph4qLIfDnbPIWam1sX+nzjcbQdruARHatsivi0R8uaCIr8mppOY/EbVaMj0Q37uJjHmngmtIkmyTfCUtNSQ/4L/Qbns6QtDU97fKEHizhF5CRFeeTw4M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037286; c=relaxed/simple; bh=uYm3jX0vY0z2aM7tPEpVTWYxMh+1rEvEzWnmhapx1uU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l2OD5ECBNERUxptydQtRssFBBQ3gMVj5hGqvGOHcCmII2IWs5HilWvv7deCWJQCmGs9iYepNrqXtnxGeXmOYVchruVdUyvw3c8ErOJ99JVirAeS4wusvUSMTP2s1wswEOVvNsv+sHww0VPaikgdXNoE1QNinY66bRrUzk8JYgb8= 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=yceZhNj2; arc=none smtp.client-ip=209.85.218.73 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="yceZhNj2" Received: by mail-ej1-f73.google.com with SMTP id a640c23a62f3a-b8704795d25so549016566b.2 for ; Wed, 25 Feb 2026 08:34:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772037283; x=1772642083; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=F5PV0mRurjScdHoadFixO8I03dLLk9ZHLW+ci+eIdSk=; b=yceZhNj20UDt3Mh7cmZ6daEqQlKflEDvpCjowUY2hC1Xd7KlUDbboCZXj3RSNGAnxz Vwpez4MqVfcBkmYrzIYJXYDYl5qkZwabYEBMz8k/nOU00Hun9N/+lfbe5j9RAA8kcH8e HxHFm0j5xhH0Bb3m7DfceENwvEf+C0dg9Cm64t8xSDwyhwDQdAu3LgpmFHQ2aMPixz4/ iWimzog7x6ZfKWOM6j9BYgyCXGA/arqSisupPpd/aDxBigbKCuCaRNbQ5heVRuar0bFA STFFmfD5n6nKCyclFIC56N8Z1E6Ni6/RCbXQ3PESXLYFtldGL9Vm1soIaCZw4U27ljAm qPFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772037283; x=1772642083; h=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; bh=F5PV0mRurjScdHoadFixO8I03dLLk9ZHLW+ci+eIdSk=; b=Ukp/oasHWU/IRKc3voVPTTWtMI3VPiBxUPdX9Nhd60cZPHyw9vHlPC8n1YGy4g0USs cFiqhZGfKETxYvcLra+AlkmTmaSNVzta6K2RV5hAJMGX8PO802n8VsemW1AdHSXr+XJy x/8og+U5fw91fTBrWilIVc4kf5esihMN7wUSYNyv9V3CCEPuxlHxJPJkv/ooMUr0YwMb xCA91dV/Y3D9Bfcy31IN8jO98LgkiIY9NeEaV62mcA90C2w9Wb2+y2RwZtLP3qTT4usZ nj68lDh89NEAUtKUAyrm0z8qVGp4woi7JtkI3i+xVuVcEjY9Okjw4K00iRWxOW2VVHRl Udsw== X-Forwarded-Encrypted: i=1; AJvYcCXuDnlgQlOjkDzn9Hoich81M33Uy9V0JiI7VbDxwOPogHlUPmxU3n/ohGruo5wygRsYL4k/cqaDynZpWZk=@vger.kernel.org X-Gm-Message-State: AOJu0YwDY538iwlZ/G+/ogaHbazHLDErQtMCsO6axAKcT8AEiQ/JMNRl joP1w8mgm94EsS0b6W6zaN1iGJn262i/BIc9jdkaj/ZZvHA+JKPydU28nfLeR2geukheVgTGto2 ZH4yNt9SvIOwgtg== X-Received: from ejbha21.prod.google.com ([2002:a17:906:a895:b0:b88:4922:9e97]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a17:907:1c23:b0:b83:1326:7d45 with SMTP id a640c23a62f3a-b9351736393mr62821066b.32.1772037283008; Wed, 25 Feb 2026 08:34:43 -0800 (PST) Date: Wed, 25 Feb 2026 16:34:31 +0000 In-Reply-To: <20260225-page_alloc-unmapped-v1-0-e8808a03cd66@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260225-page_alloc-unmapped-v1-0-e8808a03cd66@google.com> X-Mailer: b4 0.14.3 Message-ID: <20260225-page_alloc-unmapped-v1-6-e8808a03cd66@google.com> Subject: [PATCH RFC 06/19] mm: introduce for_each_free_list() From: Brendan Jackman To: Borislav Petkov , Dave Hansen , Peter Zijlstra , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Vlastimil Babka , Wei Xu , Johannes Weiner , Zi Yan Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, x86@kernel.org, rppt@kernel.org, Sumit Garg , derkling@google.com, reijiw@google.com, Will Deacon , rientjes@google.com, "Kalyazin, Nikita" , patrick.roy@linux.dev, "Itazuri, Takahiro" , Andy Lutomirski , David Kaplan , Thomas Gleixner , Brendan Jackman , Yosry Ahmed Content-Type: text/plain; charset="utf-8" Later patches will rearrange the free areas, but there are a couple of places that iterate over them with the assumption that they have the current structure. It seems ideally, code outside of mm should not be directly aware of struct free_area in the first place, but that awareness seems relatively harmless so just make the minimal change. Now instead of letting users manually iterate over the free lists, just provide a macro to do that. Then adopt that macro in a couple of places. Signed-off-by: Brendan Jackman --- include/linux/mmzone.h | 7 +++++-- kernel/power/snapshot.c | 8 ++++---- mm/mm_init.c | 11 +++++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 3e51190a55e4c..fc4d499fbbd2b 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -123,9 +123,12 @@ static inline bool migratetype_is_mergeable(int mt) return mt < MIGRATE_PCPTYPES; } -#define for_each_migratetype_order(order, type) \ +#define for_each_free_list(list, zone, order) \ for (order = 0; order < NR_PAGE_ORDERS; order++) \ - for (type = 0; type < MIGRATE_TYPES; type++) + for (unsigned int type = 0; \ + list = &zone->free_area[order].free_list[type], \ + type < MIGRATE_TYPES; \ + type++) \ extern int page_group_by_mobility_disabled; diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index 0a946932d5c17..29a053d447c31 100644 --- a/kernel/power/snapshot.c +++ b/kernel/power/snapshot.c @@ -1244,8 +1244,9 @@ unsigned int snapshot_additional_pages(struct zone *zone) static void mark_free_pages(struct zone *zone) { unsigned long pfn, max_zone_pfn, page_count = WD_PAGE_COUNT; + struct list_head *free_list; unsigned long flags; - unsigned int order, t; + unsigned int order; struct page *page; if (zone_is_empty(zone)) @@ -1269,9 +1270,8 @@ static void mark_free_pages(struct zone *zone) swsusp_unset_page_free(page); } - for_each_migratetype_order(order, t) { - list_for_each_entry(page, - &zone->free_area[order].free_list[t], buddy_list) { + for_each_free_list(free_list, zone, order) { + list_for_each_entry(page, free_list, buddy_list) { unsigned long i; pfn = page_to_pfn(page); diff --git a/mm/mm_init.c b/mm/mm_init.c index 61d983d23f553..a748fb6d6555d 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1432,11 +1432,14 @@ static void __meminit zone_init_internals(struct zone *zone, enum zone_type idx, static void __meminit zone_init_free_lists(struct zone *zone) { - unsigned int order, t; - for_each_migratetype_order(order, t) { - INIT_LIST_HEAD(&zone->free_area[order].free_list[t]); + struct list_head *list; + unsigned int order; + + for_each_free_list(list, zone, order) + INIT_LIST_HEAD(list); + + for (order = 0; order < NR_PAGE_ORDERS; order++) zone->free_area[order].nr_free = 0; - } #ifdef CONFIG_UNACCEPTED_MEMORY INIT_LIST_HEAD(&zone->unaccepted_pages); -- 2.51.2