[RFC PATCH 1/5] io_uring: allocate folio in io_mem_alloc_compound() and function rename

Zi Yan posted 5 patches 1 week, 2 days ago
[RFC PATCH 1/5] io_uring: allocate folio in io_mem_alloc_compound() and function rename
Posted by Zi Yan 1 week, 2 days ago
The page allocated in io_mem_alloc_compound() is actually used as a folio
later in io_region_mmap(). So allocate a folio instead of a compound page
and rename io_mem_alloc_compound() to io_mem_alloc_folio().

This prepares for code separation of compound page and folio in a follow-up
commit.

Signed-off-by: Zi Yan <ziy@nvidia.com>
---
 io_uring/memmap.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/io_uring/memmap.c b/io_uring/memmap.c
index 7d3c5eb58480..8ed8a78d71cc 100644
--- a/io_uring/memmap.c
+++ b/io_uring/memmap.c
@@ -15,10 +15,10 @@
 #include "rsrc.h"
 #include "zcrx.h"
 
-static bool io_mem_alloc_compound(struct page **pages, int nr_pages,
+static bool io_mem_alloc_folio(struct page **pages, int nr_pages,
 				  size_t size, gfp_t gfp)
 {
-	struct page *page;
+	struct folio *folio;
 	int i, order;
 
 	order = get_order(size);
@@ -27,12 +27,12 @@ static bool io_mem_alloc_compound(struct page **pages, int nr_pages,
 	else if (order)
 		gfp |= __GFP_COMP;
 
-	page = alloc_pages(gfp, order);
-	if (!page)
+	folio = folio_alloc(gfp, order);
+	if (!folio)
 		return false;
 
 	for (i = 0; i < nr_pages; i++)
-		pages[i] = page + i;
+		pages[i] = folio_page(folio, i);
 
 	return true;
 }
@@ -162,7 +162,7 @@ static int io_region_allocate_pages(struct io_mapped_region *mr,
 	if (!pages)
 		return -ENOMEM;
 
-	if (io_mem_alloc_compound(pages, mr->nr_pages, size, gfp)) {
+	if (io_mem_alloc_folio(pages, mr->nr_pages, size, gfp)) {
 		mr->flags |= IO_REGION_F_SINGLE_REF;
 		goto done;
 	}
-- 
2.51.0
Re: [RFC PATCH 1/5] io_uring: allocate folio in io_mem_alloc_compound() and function rename
Posted by Lance Yang 1 week, 1 day ago

On 2026/1/30 11:48, Zi Yan wrote:
> The page allocated in io_mem_alloc_compound() is actually used as a folio
> later in io_region_mmap(). So allocate a folio instead of a compound page
> and rename io_mem_alloc_compound() to io_mem_alloc_folio().
> 
> This prepares for code separation of compound page and folio in a follow-up
> commit.
> 
> Signed-off-by: Zi Yan <ziy@nvidia.com>
> ---
>   io_uring/memmap.c | 12 ++++++------
>   1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/io_uring/memmap.c b/io_uring/memmap.c
> index 7d3c5eb58480..8ed8a78d71cc 100644
> --- a/io_uring/memmap.c
> +++ b/io_uring/memmap.c
> @@ -15,10 +15,10 @@
>   #include "rsrc.h"
>   #include "zcrx.h"
>   
> -static bool io_mem_alloc_compound(struct page **pages, int nr_pages,
> +static bool io_mem_alloc_folio(struct page **pages, int nr_pages,
>   				  size_t size, gfp_t gfp)
>   {
> -	struct page *page;
> +	struct folio *folio;
>   	int i, order;
>   
>   	order = get_order(size);
> @@ -27,12 +27,12 @@ static bool io_mem_alloc_compound(struct page **pages, int nr_pages,

Nit:

>   	else if (order)
>   		gfp |= __GFP_COMP;

Since we're switching to folio_alloc(), which already adds __GFP_COMP
internally, the "else if (order)" part above can be dropped while at it.

IIUC, for order == 0, __GFP_COMP gets ignored anyway:

  - prep_new_page() won't call prep_compound_page() (since order is zero)
  - page_rmappable_folio() sees a non-compound page and does nothing

So no behavior change there :)

>   
> -	page = alloc_pages(gfp, order);
> -	if (!page)
> +	folio = folio_alloc(gfp, order);
> +	if (!folio)
>   		return false;
>   
>   	for (i = 0; i < nr_pages; i++)
> -		pages[i] = page + i;
> +		pages[i] = folio_page(folio, i);
>   
>   	return true;
>   }
> @@ -162,7 +162,7 @@ static int io_region_allocate_pages(struct io_mapped_region *mr,
>   	if (!pages)
>   		return -ENOMEM;
>   
> -	if (io_mem_alloc_compound(pages, mr->nr_pages, size, gfp)) {
> +	if (io_mem_alloc_folio(pages, mr->nr_pages, size, gfp)) {
>   		mr->flags |= IO_REGION_F_SINGLE_REF;
>   		goto done;
>   	}
Re: [RFC PATCH 1/5] io_uring: allocate folio in io_mem_alloc_compound() and function rename
Posted by Zi Yan 1 week ago
On 31 Jan 2026, at 10:30, Lance Yang wrote:

> On 2026/1/30 11:48, Zi Yan wrote:
>> The page allocated in io_mem_alloc_compound() is actually used as a folio
>> later in io_region_mmap(). So allocate a folio instead of a compound page
>> and rename io_mem_alloc_compound() to io_mem_alloc_folio().
>>
>> This prepares for code separation of compound page and folio in a follow-up
>> commit.
>>
>> Signed-off-by: Zi Yan <ziy@nvidia.com>
>> ---
>>   io_uring/memmap.c | 12 ++++++------
>>   1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/io_uring/memmap.c b/io_uring/memmap.c
>> index 7d3c5eb58480..8ed8a78d71cc 100644
>> --- a/io_uring/memmap.c
>> +++ b/io_uring/memmap.c
>> @@ -15,10 +15,10 @@
>>   #include "rsrc.h"
>>   #include "zcrx.h"
>>  -static bool io_mem_alloc_compound(struct page **pages, int nr_pages,
>> +static bool io_mem_alloc_folio(struct page **pages, int nr_pages,
>>   				  size_t size, gfp_t gfp)
>>   {
>> -	struct page *page;
>> +	struct folio *folio;
>>   	int i, order;
>>    	order = get_order(size);
>> @@ -27,12 +27,12 @@ static bool io_mem_alloc_compound(struct page **pages, int nr_pages,
>
> Nit:
>
>>   	else if (order)
>>   		gfp |= __GFP_COMP;
>
> Since we're switching to folio_alloc(), which already adds __GFP_COMP
> internally, the "else if (order)" part above can be dropped while at it.
>
> IIUC, for order == 0, __GFP_COMP gets ignored anyway:
>
>  - prep_new_page() won't call prep_compound_page() (since order is zero)
>  - page_rmappable_folio() sees a non-compound page and does nothing
>
> So no behavior change there :)
>
Sure. Will update it in the next version. Thanks.

--
Best Regards,
Yan, Zi