From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BE289CD4851 for ; Wed, 13 May 2026 12:39:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D0E76B009B; Wed, 13 May 2026 08:39:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A80E6B009D; Wed, 13 May 2026 08:39:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BE886B009E; Wed, 13 May 2026 08:39:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F1AA16B009B for ; Wed, 13 May 2026 08:39:30 -0400 (EDT) Received: from smtpin27.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A40BD1A07BD for ; Wed, 13 May 2026 12:39:30 +0000 (UTC) X-FDA: 84762352500.27.2F7638E Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by imf24.hostedemail.com (Postfix) with ESMTP id 2F81D18000E for ; Wed, 13 May 2026 12:39:27 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; spf=pass (imf24.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1778675968; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RLybxyUxLbs25awtUohOOv7JkeH7VdKQdRohXXZLAmY=; b=Y0J/NR+eSSXGZZ5NUiVAxpwWJULAEv0WgevfZ1mXTM1DJGlVUhzo5l0wD/SmJgDPdDriig FmAJ4VOE4K7IIBADMOfStHUSrsWGWN8kAkJSS5mnfCl59rWFyAQIg2lCg4vKH+ASN9p8i3 3QmMtwj1cssYgk5L/tGf9Rz9yjLb2NQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf24.hostedemail.com: domain of byungchul@sk.com designates 166.125.252.92 as permitted sender) smtp.mailfrom=byungchul@sk.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1778675968; a=rsa-sha256; cv=none; b=YHMhtFfH60Zo5Uk0V0XFZPN+N+9VJbrXyDREohgzNPx97vam7gi9qWQTYOIHW91tamo0zM DaxrGPtw+icfplDjAPQCTp1Zy6y2NJjXyc3m/mscHjyX6M0rIw1uj6C+ZkfqihVAgy3DAM JDO7P+YRf0Twe68clTMgTLt0KHDtxoI= X-AuditID: a67dfc5b-c2dff70000001609-49-6a0470fda551 Date: Wed, 13 May 2026 21:39:20 +0900 From: Byungchul Park To: "David Hildenbrand (Arm)" Cc: Dragos Tatulea , linux-mm@kvack.org, akpm@linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel_team@skhynix.com, harry.yoo@oracle.com, ast@kernel.org, daniel@iogearbox.net, davem@davemloft.net, kuba@kernel.org, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, saeedm@nvidia.com, leon@kernel.org, tariqt@nvidia.com, mbloch@nvidia.com, andrew+netdev@lunn.ch, edumazet@google.com, pabeni@redhat.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, horms@kernel.org, jackmanb@google.com, hannes@cmpxchg.org, ziy@nvidia.com, ilias.apalodimas@linaro.org, willy@infradead.org, brauner@kernel.org, kas@kernel.org, yuzhao@google.com, usamaarif642@gmail.com, baolin.wang@linux.alibaba.com, almasrymina@google.com, toke@redhat.com, asml.silence@gmail.com, bpf@vger.kernel.org, linux-rdma@vger.kernel.org, sfr@canb.auug.org.au, dw@davidwei.uk, ap420073@gmail.com Subject: Re: [PATCH v4] mm: introduce a new page type for page pool in page type Message-ID: <20260513123920.GA51788@system.software.com> References: <20260224051347.19621-1-byungchul@sk.com> <982b9bc1-0a0a-4fc5-8e3a-3672db2b29a1@nvidia.com> <20260513121805.GA22430@system.software.com> <8348d867-f8a1-432c-be2d-699ad96b2e93@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8348d867-f8a1-432c-be2d-699ad96b2e93@kernel.org> User-Agent: Mutt/1.9.4 (2018-02-28) X-Brightmail-Tracker: H4sIAAAAAAAAA02SW0xTWRSGs3v22edQqTlWxa0ko+loRrwgig/LS5THM0NMdNTE4IM2ciJF qNgqUBMNSI1apYoDBktV1BlAZEIs1xJqpGCFggExkHrhIohEETRgKhQCUoiRtz/r/9f/rYfF M8p37DJeoz0p6bTqOBWRY/lg4L31kwk4NqzkXxasxUUEHo4mQ353JQtjRf0ysBaWI/g29oaD KYcLwUjdMwIDtcMI7t/1MmBtNmLoL/MhsFf1I/iU/T+BPlcPBw9tu6Ar7wOG6gsVDPRcrSeQ bhxnwDE2xMG5yoLp4pIUDlrKzSxk+v5joCKlm4OXVVYCnUVTLHxwpmNosDzA8DWrjoEucwS4 coPA2/gZQV1xhQy8V24RaLtZJYMyRxsH/7TmEug1diFore3BkDVxkUBOqhnB+Oh05dC1byzk PO3kIkLFVI+HiLWfvzBi6YNXMrE9OwOLnsdumWi3dHBiru2UWFKwRjR5WhnRVniJiLbh65z4 tr2aiPXZ41i0v9si2itHZGJ62hDZvThKvj1aitMkSroNOw7LY15m2NiEgT+TfRkOnIK+hplQ AE+FzdSX8Z01IX5GG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64KLHdYCbV33emTRlsRAYaidQjhuHYGE43 EO+XBLuae9qQoEcBDMWu5dxuH+7XQWwk523KxPRIxODsDM1NttoIf7CE3cu1GEvmS2IWuA6n HfeXJOwbxNXaTeTfYDHXfPPL/AHOrucsNd2U/xnOhnIPZpi/9kouq8bPYZgANo7Lr4r220vZ MO5F7SssDy0yLgAZF4CM/0HGBaBSRJSjIIUqNVmuUG7aoD2TmK5SpG04cTbZjOamdf/iL0M9 Gm/fYUcsg6SB4heniSQJKU/VpifbEcfg0iBxrhMlScQn5ekXBM3ZY5pzSkFrR6EMIV0m3nVA OC5hT8tThDOCoBY0/1KMCQjJQLHBUY2XpS0HPQb1wL6eZ98Mp1rDut7t73zedUP5ybNtdEVb xd4TISnRrpfXf1q2J6xPKDja1eJmz+9ZfqgtZtVm4ejByrTHeY7qZnWgTLasbMXuNr24Ol+W XaBq/fFlTZRBd7io6LM3MGidzhfx7VRTbNGR4cx+q/r2xrF8V1fs4nApoU2UR4XjGq38D+Vw AQZWAwAA X-CFilter-Loop: Reflected X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 2F81D18000E X-Rspam-User: X-Stat-Signature: aj7i1c7ijyu5fxbxe6x83nfp1nrah94b X-HE-Tag: 1778675967-975358 X-HE-Meta: U2FsdGVkX19pJFT9veTy226M+AI0HyPDDQQwGuxJMn0RkiImNEPa7CIs2IeQC617CDWQIOv2pVta841wLCJ8UaI8dZlk5TiqY1XWwV5EHQFdsEArnYnG+qIyCDkiw7Bmm2KMhcvkrKQFSdf5yLfELZGV2gYTdy8iEkoy8ANtCXSwPoMF8JA/Xv12+7Vr320sHEAVQaUzvNIi/Vlgn025N2ptZ7NglItC+xBpXO2gpNVs7zehZ0srkdN+wzYN7yR64u3z06ppLTkwIrisklmIVBa3npyg3XY2MUP61tRbxsGl2HHI/ZU61HTdLa600fItCc0+7slRyBfZGZQXoTrfVJNFEV794sKJJ05V/DR2nWHV/OSVbZVe8HuH2qixPUeXUWDrQN5ELdcF3bSHfJROL8/o6WMNelu0mgyWme+FRju0qlmWDQzzw+OpMNFeCmeLIOFOut5oP8AihBg7fNsq+c8XGF5SJQnxFd09seG5/Ek1RNdN+lquPyMtEl2Gz+tCkwWz82BlK5CnVl03WAaxRVlEtJdBrTiZYWELcgdycmctLe/yR0BFWab4wViXu9a2OzSl1kcOFEPzs4vQGglosYCflF6cjxNF7C2+LaMjflPbGxcvCHcl5v+ohVUkCY2S65SqnxEwQQlxFtIN5uhhnL/l/lHkWm+5lp6+YAOkUAQjzbMa4w5T7MdtT4/ntMrhst/gB7snYhzjFsNylgCHKHPfppVA/8JTHnkV608od2C+vHMA+VMO8YUp5Mwwl5iCB9UsRUNCW6405dDsS/2zG4m15mdFLU/7JRBujIIFAYkd+D11KeEwnsrKCIDv+SZl/F+loAvC7Mikv8emyPjNXAQwjSkfcs9wwAzsDhLgyeAh8BDh1zxjooRvWXiZFZi7/MpX0XjVUe0auoOvCSeFoz11ipszA2i89bxch4slkDzr92WdO/QFzUIPH2f/YUfVygcm3vOt8pkFYZ1ylon 3nety9Jh mxZM+anRSzWIGwVZLOG8RmKaFCRZu9QE5ep3gPaA1z0hTttD8EcgddPJOl7BBaJYaSH/apk+8u51YEPcNpQ6kDy2WkwMuFbh6DJLkE+RA3SKsO56uvtmB587wxWp8CIw4yIiUCpJR2rEURfbCB+DwT/jTIeEVbxXLYEsdyR4PdLN0RNDe1tBZfKniM/wcQ/+56NZUZ49/60jX8is= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, May 13, 2026 at 02:29:46PM +0200, David Hildenbrand (Arm) wrote: On 5/13/26 14:18, Byungchul Park wrote: > > On Wed, May 13, 2026 at 11:00:51AM +0200, Dragos Tatulea wrote: > >> On 24.02.26 06:13, Byungchul Park wrote: > >>> Currently, the condition 'page->pp_magic == PP_SIGNATURE' is used to > >>> determine if a page belongs to a page pool. However, with the planned > >>> removal of @pp_magic, we should instead leverage the page_type in struct > >>> page, such as PGTY_netpp, for this purpose. > >>> > >>> Introduce and use the page type APIs e.g. PageNetpp(), __SetPageNetpp(), > >>> and __ClearPageNetpp() instead, and remove the existing APIs accessing > >>> @pp_magic e.g. page_pool_page_is_pp(), netmem_or_pp_magic(), and > >>> netmem_clear_pp_magic(). > >>> > >>> Plus, add @page_type to struct net_iov at the same offset as struct page > >>> so as to use the page_type APIs for struct net_iov as well. While at it, > >>> reorder @type and @owner in struct net_iov to avoid a hole and > >>> increasing the struct size. > >>> > >>> This work was inspired by the following link: > >>> > >>> https://lore.kernel.org/all/582f41c0-2742-4400-9c81-0d46bf4e8314@gmail.com/ > >>> > >>> While at it, move the sanity check for page pool to on the free path. > >>> > >>> Suggested-by: David Hildenbrand > >>> Co-developed-by: Pavel Begunkov > >>> Signed-off-by: Pavel Begunkov > >>> Signed-off-by: Byungchul Park > >>> Acked-by: David Hildenbrand > >>> Acked-by: Zi Yan > >>> Acked-by: Vlastimil Babka > >>> Reviewed-by: Toke Høiland-Jørgensen > >>> --- > >> > >> Seems like this patch broke tcp_mmap because > >> validate_page_before_insert() returns -EINVAL due > >> to a page having a type. Here's the full flow: > >> > >> getsockopt(TCP_ZEROCOPY_RECEIVE) returns -EINVAL because of the > >> below flow in the kernel: > >> > >> tcp_zerocopy_receive() > >> -> tcp_zerocopy_vm_insert_batch() > >> -> vm_insert_pages() > >> -> insert_pages() > >> -> insert_page_in_batch_locked() > >> -> validate_page_before_insert() returns -EINVAL > >> because page_has_type(page) is now true. > >> > >> The patch below fixes the issue. But is this a valid fix? > > > > Hi, > > > > The problem comes from the fact that page_type and _mapcount are > > union'ed but there is a case where these two information should be kept > > at the same time. > > > > Why don't we allow these two information can be kept in the 4 bytes at > > the same time until Zi Yan's work on _mapcount and page_type will be > > done, instead of taking a step back? > > > > It can be more optimized but I suggest the approach I just mentioned: > > --- > > diff --git a/fs/proc/internal.h b/fs/proc/internal.h > > index 64dc44832808..e5ec204866dc 100644 > > --- a/fs/proc/internal.h > > +++ b/fs/proc/internal.h > > @@ -185,8 +185,7 @@ static inline int folio_precise_page_mapcount(struct folio *folio, > > { > > int mapcount = atomic_read(&page->_mapcount) + 1; > > > > - if (page_mapcount_is_type(mapcount)) > > - mapcount = 0; > > + mapcount = page_mapcount_clear_type(mapcount); > > if (folio_test_large(folio)) > > mapcount += folio_entire_mapcount(folio); > > > > diff --git a/include/linux/mm.h b/include/linux/mm.h > > index 8260e28205e9..f45064796313 100644 > > --- a/include/linux/mm.h > > +++ b/include/linux/mm.h > > @@ -1865,8 +1865,7 @@ static inline int folio_mapcount(const struct folio *folio) > > > > if (likely(!folio_test_large(folio))) { > > mapcount = atomic_read(&folio->_mapcount) + 1; > > - if (page_mapcount_is_type(mapcount)) > > - mapcount = 0; > > + mapcount = page_mapcount_clear_type(mapcount); > > return mapcount; > > } > > return folio_large_mapcount(folio); > > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h > > index 0e03d816e8b9..f3b0d1fa262d 100644 > > --- a/include/linux/page-flags.h > > +++ b/include/linux/page-flags.h > > @@ -934,9 +934,9 @@ static inline bool page_type_has_type(int page_type) > > } > > > > /* This takes a mapcount which is one more than page->_mapcount */ > > -static inline bool page_mapcount_is_type(unsigned int mapcount) > > +static inline unsigned int page_mapcount_clear_type(unsigned int mapcount) > > { > > - return page_type_has_type(mapcount - 1); > > + return (unsigned int)(((int)(mapcount << 8)) >> 8); > > } > > > > static inline bool page_has_type(const struct page *page) > > @@ -953,16 +953,20 @@ static __always_inline void __folio_set_##fname(struct folio *folio) \ > > { \ > > if (folio_test_##fname(folio)) \ > > return; \ > > - VM_BUG_ON_FOLIO(data_race(folio->page.page_type) != UINT_MAX, \ > > + VM_BUG_ON_FOLIO(page_type_has_type(data_race(folio->page.page_type)), \ > > folio); \ > > - folio->page.page_type = (unsigned int)PGTY_##lname << 24; \ > > + folio->page.page_type &= ~(PGTY_mapcount_underflow << 24); \ > > + folio->page.page_type |= (unsigned int)PGTY_##lname << 24; \ > > } \ > > static __always_inline void __folio_clear_##fname(struct folio *folio) \ > > { \ > > - if (folio->page.page_type == UINT_MAX) \ > > + int mapcount; \ > > + \ > > + if (!page_type_has_type(folio->page.page_type)) \ > > return; \ > > VM_BUG_ON_FOLIO(!folio_test_##fname(folio), folio); \ > > - folio->page.page_type = UINT_MAX; \ > > + mapcount = atomic_read(&folio->page._mapcount); \ > > + folio->page.page_type = page_mapcount_clear_type(mapcount); \ > > } > > > > #define PAGE_TYPE_OPS(uname, lname, fname) \ > > @@ -975,15 +979,20 @@ static __always_inline void __SetPage##uname(struct page *page) \ > > { \ > > if (Page##uname(page)) \ > > return; \ > > - VM_BUG_ON_PAGE(data_race(page->page_type) != UINT_MAX, page); \ > > - page->page_type = (unsigned int)PGTY_##lname << 24; \ > > + VM_BUG_ON_PAGE(page_type_has_type(data_race(page->page_type)), \ > > + page); \ > > + page->page_type &= ~(PGTY_mapcount_underflow << 24); \ > > + page->page_type |= (unsigned int)PGTY_##lname << 24; \ > > } \ > > static __always_inline void __ClearPage##uname(struct page *page) \ > > { \ > > - if (page->page_type == UINT_MAX) \ > > + int mapcount; \ > > + \ > > + if (!page_type_has_type(page->page_type)) \ > > return; \ > > VM_BUG_ON_PAGE(!Page##uname(page), page); \ > > - page->page_type = UINT_MAX; \ > > + mapcount = atomic_read(&page->_mapcount); \ > > + page->page_type = page_mapcount_clear_type(mapcount); \ > > } > > > > /* > > diff --git a/mm/debug.c b/mm/debug.c > > index 77fa8fe1d641..9a932ded09d4 100644 > > --- a/mm/debug.c > > +++ b/mm/debug.c > > @@ -74,8 +74,7 @@ static void __dump_folio(const struct folio *folio, const struct page *page, > > int mapcount = atomic_read(&page->_mapcount) + 1; > > char *type = ""; > > > > - if (page_mapcount_is_type(mapcount)) > > - mapcount = 0; > > + mapcount = page_mapcount_clear_type(mapcount); > > > > pr_warn("page: refcount:%d mapcount:%d mapping:%p index:%#lx pfn:%#lx\n", > > folio_ref_count(folio), mapcount, mapping, > > --- > > > > Thoughts? > > God no. This is not final patch, but for sharing the rough idea *with code* - maybe there are more points in code that should be adjusted by the change. I just typed the draft patch quick just for sharing idea. If we should allow pp type pages to be used in mapping as well, then we should allow a page to keep both its type and mapcount at the same time. Am I missing something? Byungchul > -- > Cheers, > > David