ramfs: convert alloc_pages() to folio_alloc() in ramfs_nommu_expand_for_mapping()
PATCH 1/1 ramfs: convert alloc_pages() to folio_alloc() in ramfs_nommu_expand_for_mapping()
Currently, ramfs_nommu_expand_for_mapping() utilizes the deprecated alloc_pages() API. This patch converts the allocation step to use the modern folio_alloc() API, removing a legacy caller and helping pave the way for the eventual removal of alloc_pages().
Because nommu architectures require physically contiguous memory that often needs to be trimmed to the exact requested size, the allocated folio is immediately shattered using split_page().
Since split_page() destroys the compound folio metadata, using folio iteration helpers (like folio_page) becomes unsafe. Therefore, this patch deliberately drops back to a standard struct page array after the split. This safely isolates the folio conversion to the allocation phase while strictly preserving the existing trimming and page cache insertion behavior.
--- fs/ramfs/file-nommu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/ramfs/file-nommu.c +5 -2
@@ -62,6 +62,7 @@ const struct inode_operations ramfs_file_inode_operations = {int ramfs_nommu_expand_for_mapping (struct inode *inode,size_t newsize) {unsigned long npages, xpages, loop; +struct folio *folio;struct page *pages;unsigned order;void *data;
@@ -81,10 +82,12 @@ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)/* allocate enough contiguous pages to be able to satisfy the * request */ - pages =alloc_pages (gfp, order); -if (!pages) + folio =folio_alloc (gfp, order); +if (!folio)return -ENOMEM ; + pages = &folio->page; +/* split the high-order page into an array of single pages */ xpages =1UL << order; npages = (newsize +PAGE_SIZE -1 ) >>PAGE_SHIFT ;
Signature · 1 line
2.51.0
Quoted 26 lines · AnishMulay
Currently,
ramfs_nommu_expand_for_mapping()utilizes the deprecatedalloc_pages()API. This patch converts the allocation step to use the modernfolio_alloc()API, removing a legacy caller and helping pave the way for the eventual removal ofalloc_pages().Because nommu architectures require physically contiguous memory that often needs to be trimmed to the exact requested size, the allocated folio is immediately shattered using
split_page().Since
split_page()destroys the compound folio metadata, using folio iteration helpers (likefolio_page) becomes unsafe. Therefore, this patch deliberately drops back to a standard struct page array after the split. This safely isolates the folio conversion to the allocation phase while strictly preserving the existing trimming and page cache insertion behavior.Signed-off-by AnishMulay <[email protected]>--- fs/ramfs/file-nommu.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)fs/ramfs/file-nommu.c +0
-0
fs/ramfs/file-nommu.c const struct inode_operations ramfs_file_inode_operations = { · line 62
Quoted 1 line
fs/ramfs/file-nommu.c +0
-0@@ -62,6 +62,7 @@ const struct inode_operations ramfs_file_inode_operations = {int ramfs_nommu_expand_for_mapping (struct inode *inode,size_t newsize)
This method uses old page concept everywhere. If you would like to switch this method for using the folio concept, then I assume this method requires more rework.
Thanks,
Slava.
Quoted 21 lines
fs/ramfs/file-nommu.c +5
-2{unsigned long npages, xpages, loop; +struct folio *folio;struct page *pages;unsigned order;void *data;@@ -81,10 +82,12 @@ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)/* allocate enough contiguous pages to be able to satisfy the * request */ - pages =alloc_pages (gfp, order); -if (!pages) + folio =folio_alloc (gfp, order); +if (!folio)return -ENOMEM ; + pages = &folio->page; +/* split the high-order page into an array of single pages */ xpages =1UL << order; npages = (newsize +PAGE_SIZE -1 ) >>PAGE_SHIFT ;
Quoted 1 line · Viacheslav Dubeyko
Good plan.
Quoted 3 lines · AnishMulay
Quoted 2 lines
Currently,
ramfs_nommu_expand_for_mapping()utilizes the deprecatedalloc_pages()API. This patch converts the allocation step to use
alloc_pages() is not deprecated. There are no plans for its removal.
Quoted 6 lines
Quoted 6 lines
the modern
folio_alloc()API, removing a legacy caller and helping pave the way for the eventual removal ofalloc_pages().Because nommu architectures require physically contiguous memory that often needs to be trimmed to the exact requested size, the allocated folio is immediately shattered using
split_page().
Except that split_page() doesn't work on folios. It says so right there in the documentation:
* split_page takes a non-compound higher-order page, and splits it into
Folios are compound pages. This should have told you that you were going the wrong thing.
Quoted 6 lines
Quoted 6 lines
Since
split_page()destroys the compound folio metadata, using folio iteration helpers (likefolio_page) becomes unsafe. Therefore, this patch deliberately drops back to a standard struct page array after the split. This safely isolates the folio conversion to the allocation phase while strictly preserving the existing trimming and page cache insertion behavior.
Please stop trying to help, particularly for code you can't test.