Skip to content

Commit

Permalink
ramfs-nommu: use generic lru cache
Browse files Browse the repository at this point in the history
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: Johannes Weiner <[email protected]>
Acked-by: David Howells <[email protected]>
Cc: Nick Piggin <[email protected]>
Acked-by: KOSAKI Motohiro <[email protected]>
Cc: Rik van Riel <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: MinChan Kim <[email protected]>
Cc: Lee Schermerhorn <[email protected]>
Cc: Greg Ungerer <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
hnaz authored and torvalds committed Apr 1, 2009
1 parent 88c3bd7 commit 2678958
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions fs/ramfs/file-nommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
GFP_KERNEL);
if (ret < 0)
goto add_error;

if (!pagevec_add(&lru_pvec, page))
__pagevec_lru_add_file(&lru_pvec);

/* prevent the page from being discarded on memory pressure */
SetPageDirty(page);

unlock_page(page);
}

pagevec_lru_add_file(&lru_pvec);
return 0;

fsize_exceeded:
Expand All @@ -128,10 +123,8 @@ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize)
return -EFBIG;

add_error:
pagevec_lru_add_file(&lru_pvec);
page_cache_release(pages + loop);
for (loop++; loop < npages; loop++)
__free_page(pages + loop);
while (loop < npages)
__free_page(pages + loop++);
return ret;
}

Expand Down

0 comments on commit 2678958

Please sign in to comment.