Commit 2678958e authored by Johannes Weiner's avatar Johannes Weiner Committed by Linus Torvalds
Browse files

ramfs-nommu: use generic lru cache

Instead of open-coding the lru-list-add pagevec batching when expanding a
file mapping from zero, defer to the appropriate page cache function that
also takes care of adding the page to the lru list.

This is cleaner, saves code and reduces the stack footprint by 16 words
worth of pagevec.
Signed-off-by: default avatarJohannes Weiner <>
Acked-by: default avatarDavid Howells <>
Cc: Nick Piggin <>
Acked-by: default avatarKOSAKI Motohiro <>
Cc: Rik van Riel <>
Cc: Peter Zijlstra <>
Cc: MinChan Kim <>
Cc: Lee Schermerhorn <>
Cc: Greg Ungerer <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 88c3bd70
......@@ -59,7 +59,6 @@ const struct inode_operations ramfs_file_inode_operations = {
int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)
struct pagevec lru_pvec;
unsigned long npages, xpages, loop, limit;
struct page *pages;
unsigned order;
......@@ -102,24 +101,20 @@ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)
memset(data, 0, newsize);
/* attach all the pages to the inode's address space */
pagevec_init(&lru_pvec, 0);
for (loop = 0; loop < npages; loop++) {
struct page *page = pages + loop;
ret = add_to_page_cache(page, inode->i_mapping, loop, GFP_KERNEL);
ret = add_to_page_cache_lru(page, inode->i_mapping, loop,
if (ret < 0)
goto add_error;
if (!pagevec_add(&lru_pvec, page))
/* prevent the page from being discarded on memory pressure */
return 0;
......@@ -128,10 +123,8 @@ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)
return -EFBIG;
page_cache_release(pages + loop);
for (loop++; loop < npages; loop++)
__free_page(pages + loop);
while (loop < npages)
__free_page(pages + loop++);
return ret;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment