From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-21.mta1.migadu.com [95.215.58.21]) (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 84863440A07 for ; Fri, 14 Aug 2026 10:37:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.21 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786703847; cv=none; b=de7wwuB1d0YCFqje0QCsUhwlrRLClAaUy8jxWrgFfd2U6ZalRbJjsdiTK3s9CsRK0aPf6ndmLUOzAcnsmsPyOsWPPfEYv9C9KNtvzLnaClA+XNHveGj5JseCK6EUiIgytEl6Ih3GyVglFyGjQ59xt2/V0feIBlyFc7+WU1QZCFI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786703847; c=relaxed/simple; bh=QiLSPI+MPmY1LDSvHHQGw63yDUWEXiMCfHcerMNBDt0=; h=Mime-Version:Content-Type:Date:Message-Id:To:Cc:Subject:From: References:In-Reply-To; b=aFfsPlqkEaQtlQTEzPvR5neZw909onCQAASWiSirw/8JguKpXn7LVUufFSibVp4529MjXvmueBYFuV39uZ8KRes6M0LFj3JO1gRFGdx9YRmXA5O0eTWGDqs9OOUtqwdRWquoKicyfqT6Err64sAljU67uvEz8YZO3tRSJoeeCFs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=A4dofpUH; arc=none smtp.client-ip=95.215.58.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="A4dofpUH" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=QiLSPI+MPmY1LDSvHHQGw63yDUWEXiMCfHcerMNBDt0=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786703833; v=1; x=1787308633; b=A4dofpUHhchwEeUszJTtMKVFgOF0QiZa4aH2obDU7IdY9TPywGR5Ujlari6kW0Wyeuny0oHW DlEP6N+kTEiDVRJ+mHMV6vjiu3fV3I9XF38A2XsaN7HBoIaEINn42nmyMcEdiwfNbM0kb7jWVg5 NBrl71rBvJlYK/i24YpyOodk= X-Envelope-To: linux-kernel@vger.kernel.org Received: from localhost (77.97.51.77) by smtp.migadu.com with ESMTPS id 61f550f3f67deb7c; Fri, 14 Aug 2026 10:37:13 +0000 X-Migadu-Flow: FLOW_OUT Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Fri, 14 Aug 2026 11:37:11 +0100 Message-Id: To: "Yosry Ahmed" , "Brendan Jackman" Cc: "Borislav Petkov" , "Dave Hansen" , "Peter Zijlstra" , "Andrew Morton" , "David Hildenbrand" , "Vlastimil Babka" , "Mike Rapoport" , "Wei Xu" , "Johannes Weiner" , "Zi Yan" , "Lorenzo Stoakes" , , , , "Sumit Garg" , "Will Deacon" , , "Kalyazin, Nikita" , , "Itazuri, Takahiro" , "Andy Lutomirski" , "David Kaplan" , "Thomas Gleixner" , "Patrick Bellasi" , "Reiji Watanabe" , "Sean Christopherson" Subject: Re: [PATCH v3 13/26] mm: introduce freetype_t From: "Brendan Jackman" X-Mailer: aerc 0.21.0 References: <20260726-page_alloc-unmapped-v3-0-6f5729aa9832@google.com> <20260726-page_alloc-unmapped-v3-13-6f5729aa9832@google.com> In-Reply-To: On Tue Aug 4, 2026 at 11:23 PM BST, Yosry Ahmed wrote: >> @@ -179,24 +180,62 @@ static inline bool migratetype_is_mergeable(int mt= ) >> =20 >> #define for_each_free_list(list, zone, order) \ >> for (order =3D 0; order < NR_PAGE_ORDERS; order++) \ >> - for (unsigned int __type =3D 0; \ >> - __type < MIGRATE_TYPES && \ >> - (list =3D &(zone)->free_area[order].free_list[__type], 1); \ >> - __type++) >> + for (unsigned int __idx =3D 0; \ >> + __idx < NR_FREETYPE_IDXS && \ >> + (list =3D &(zone)->free_area[order].free_list[__idx], 1); \ >> + __idx++) >> + >> +static inline freetype_t migrate_to_freetype(enum migratetype mt, >> + unsigned int flags) >> +{ >> + freetype_t freetype; >> + >> + /* No flags supported yet. */ >> + VM_WARN_ON_ONCE(flags); >> + >> + freetype.migratetype =3D mt; >> + return freetype; >> +} >> + >> +static inline enum migratetype free_to_migratetype(freetype_t freetype) >> +{ >> + return freetype.migratetype; >> +} >> + >> +/* Convenience helper, return the freetype modified to have the migrate= type. */ >> +static inline freetype_t freetype_with_migrate(freetype_t freetype, >> + enum migratetype migratetype) >> +{ >> + return migrate_to_freetype(migratetype, freetype_flags(freetype)); >> +} >> =20 >> extern int page_group_by_mobility_disabled; >> =20 >> +freetype_t get_pfnblock_freetype(const struct page *page, unsigned long= pfn); >> + >> #define get_pageblock_migratetype(page) \ >> get_pfnblock_migratetype(page, page_to_pfn(page)) >> =20 >> +#define get_pageblock_freetype(page) \ >> + get_pfnblock_freetype(page, page_to_pfn(page)) >> + >> #define folio_migratetype(folio) \ >> get_pageblock_migratetype(&folio->page) >> =20 >> struct free_area { >> - struct list_head free_list[MIGRATE_TYPES]; >> + struct list_head free_list[NR_FREETYPE_IDXS]; >> unsigned long nr_free; >> }; >> =20 >> +static inline >> +struct list_head *free_area_list(struct free_area *area, freetype_t typ= e) >> +{ >> + int idx =3D freetype_idx(type); >> + >> + VM_WARN_ON(idx < 0); >> + return &area->free_list[idx]; > > Should we return NULL here if idx < 0 instead of an out of bounds > access? TBH my descending order of preference is: 1. BUG_ON(idx < 0); return &area->free_list[idx]; 2. if (WARN_ON(idx < 0)) // OR VM_WARN_ON return NULL; return &area->free_list[idx]; 3. VM_WARN_ON(idx < 0); return &area->free_list[idx]; 4.=20 return &area->free_list[idx]; But I suspect[0] Vlastimil (and Linus) would order it the exact opposite way. [0]: https://lore.kernel.org/all/bd36e972-8900-4476-a66b-4dc218b21a4d@kerne= l.org/ And I care more about making Vlastimil (and Linus) happy than this tiny detail of the code, so I'll defer to him. The current style is a compromise, but maybe it's just a compromise that makes nobody happy.