From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (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 D45BD423A83 for ; Wed, 13 May 2026 12:35:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778675719; cv=none; b=H3+ODaisvsQhyluNCmak/F9En+EUxgThcUe194mDc8Q5ANDG1BG4DeN50BV6uGacto1RGL3hlcfG4kEFrSu1Zfmk7cJBfi7sDf02OGwIRm4y5LBsokAPZe33l7oCwTJafuC34lofBcT5UCupxQ/nQse4KUcxSXt2dehnSvH4hOc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778675719; c=relaxed/simple; bh=wJKc2L/2gOFq+4ciJL13zwsEExRmStV9nRngieSP9CQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=l4UN5sWEvA0c0nk+2/UgohVVSQAWV2z52VC3YDyMcDQ5ndVbEkhD0WUgQ0cqLtLSYD3+2k4PkBT5PwGHj4zKLRnKtW/iV+qBJtRR7OxC0yIXp7eoAx3kylsTSS3MziBRSK9VuQrLWiCeJW3i6+rQHd03LZ7f5eLz2jekKmZELMQ= 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=F301OG4s; arc=none smtp.client-ip=209.85.221.74 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="F301OG4s" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-44ffa15dc73so6425832f8f.1 for ; Wed, 13 May 2026 05:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778675716; x=1779280516; 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=4WWLXd62Tgfh1ZCpYAiYrTX8S2ssjZcjbx8zKPYKSN8=; b=F301OG4scjX+8cpGGiJSFlSFV5zfQqncClKPvFnbZEe8cl9d4WwBtsAg6x51B8Dur5 Wcv2RyH14MmpimSWwfuCC2aB/J50XwVepqlGUfm7my9LUcCN/dyR9Nsd+9yrvRFPqalO r7AHhXgs0JlKiR0+UZJP1Gfq09BpMcq/Ge25vXnhUBrpPkiAxTe8s8pRItpK6tNQPZlH ZeOlVIFI2CqTL/8BoaWFYc7IAWSvNq6+/VPY3Dqsdcd+vdN63CkKM1xC98OfngX/M58J ASZgaR9DteL2AqURtwuPX9R5RGiU+fkN7H5WJrBsnheahQbgXX7htGf7kGviC0w1TUQP iJdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778675716; x=1779280516; 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=4WWLXd62Tgfh1ZCpYAiYrTX8S2ssjZcjbx8zKPYKSN8=; b=dsNH1SVkmMixQNDhMOGQd2o1C3zFsBVYYJmFIf3Sllr/lujTA5lqDanCQswy3SKDLM fMEpcNhX8qLrWH0HKD4rgWnRSkouCQkRFy2+iD3f3CYqxVVDJzM0lIbEaWn4+lEEmeNn Ir/jc2IFW43nwRpD7dCX/IKb6sMQHWxDpGEwGegbOP8o2+SYZXKMskox1VodGVF0LIgL QyU1Ic1+x5TAsBEgIHH/Jjz/4YV9wIpiA6VaB7LCEqFVHM0d+hwrFtVA4RwisTSa78yW uUSqvjXQFOlMQkVNdnqRmTttgRfLcjdrP/RFzlQvx4WR+J6TpDcunsDleX47fVMfqLEn RMdg== X-Forwarded-Encrypted: i=1; AFNElJ9auVgBlhcrMgV4x3F4midW7uXl6TXrTeZMHQAEZu+dmpMk72Lz8Njnmt6M/m2LJhtFMCLStm5R5LhO7/I=@vger.kernel.org X-Gm-Message-State: AOJu0Ywh5oamf9M6b3sA2uHTOiRxyJ/UCa8/AX4TYUsEi0IGQglHWTgK e7Ky6s6MKx4qxXsVQcP8vU7SKCVYZ5ecQJoBWyUKla0fKFbxFyNxyn53LZwNsHDI5EnjFXnACWh 5QWpSBtkiPoKIew== X-Received: from wmpj8.prod.google.com ([2002:a05:600c:4888:b0:48e:914f:1eff]) (user=jackmanb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:8b86:b0:48a:563c:c8c5 with SMTP id 5b1f17b1804b1-48fce9ab28emr38271865e9.8.1778675716013; Wed, 13 May 2026 05:35:16 -0700 (PDT) Date: Wed, 13 May 2026 12:35:13 +0000 In-Reply-To: <20260513-page_alloc-unmapped-prep-v1-0-dacdf5402be8@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260513-page_alloc-unmapped-prep-v1-0-dacdf5402be8@google.com> X-Mailer: b4 0.14.2 Message-ID: <20260513-page_alloc-unmapped-prep-v1-1-dacdf5402be8@google.com> Subject: [PATCH 1/4] mm: introduce for_each_free_list() From: Brendan Jackman To: Andrew Morton , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , "Rafael J. Wysocki" , Pavel Machek , Len Brown , Johannes Weiner , Zi Yan Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Brendan Jackman Content-Type: text/plain; charset="utf-8" There are a couple of places that iterate over the freelists with awareness of the data structures' layout. It seems ideally, code outside of mm should not be aware of the page allocator's freelists at all. But, this patch just doesn't hide them completely, it's just a meek incremental step in that direction: provide a macro to iterate over it without needing to be aware of the actual struct fields. Signed-off-by: Brendan Jackman --- include/linux/mmzone.h | 9 ++++++--- kernel/power/snapshot.c | 8 ++++---- mm/mm_init.c | 11 +++++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 9adb2ad21da599354600b48b4f3f9a4158efa049..1331a7b93f33c67c6e07df1fd8c5e4504dc28e80 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -177,9 +177,12 @@ static inline bool migratetype_is_mergeable(int mt) return mt < MIGRATE_PCPTYPES; } -#define for_each_migratetype_order(order, type) \ - for (order = 0; order < NR_PAGE_ORDERS; order++) \ - for (type = 0; type < MIGRATE_TYPES; type++) +#define for_each_free_list(list, zone, order) \ + for (order = 0; order < NR_PAGE_ORDERS; order++) \ + for (unsigned int __type = 0; \ + __type < MIGRATE_TYPES && \ + (list = &(zone)->free_area[order].free_list[__type], 1); \ + __type++) extern int page_group_by_mobility_disabled; diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c index a564650734dcdceda7193ca3c1bc6b347cc1ec8b..d933b5b2c05d453bbda93c728136fc2a76758fc7 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 bd466a3c10c8e204dddd881c5334364e3d47d612..db5568cf36e12b6fe52854b274fc331d9b36cac3 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1429,11 +1429,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