Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 207231
b: refs/heads/master
c: ff36b80
h: refs/heads/master
i:
  207229: f74ba0b
  207227: ea76ec1
  207223: f56ed73
  207215: f2a7a3f
  207199: b8e849a
  207167: 627dc00
  207103: 0160380
v: v3
  • Loading branch information
Shaohua Li authored and Linus Torvalds committed Aug 10, 2010
1 parent f2ea8f1 commit 4d730c3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 22 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7e496299d4d2ad8083effed6c5a18313a919edc6
refs/heads/master: ff36b801624d02a876bb7deded6ab860ea3503f2
70 changes: 49 additions & 21 deletions trunk/mm/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
struct shmem_sb_info *sbinfo;
struct page *filepage = *pagep;
struct page *swappage;
struct page *prealloc_page = NULL;
swp_entry_t *entry;
swp_entry_t swap;
gfp_t gfp;
Expand All @@ -1246,7 +1247,6 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
filepage = find_lock_page(mapping, idx);
if (filepage && PageUptodate(filepage))
goto done;
error = 0;
gfp = mapping_gfp_mask(mapping);
if (!filepage) {
/*
Expand All @@ -1257,7 +1257,19 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
if (error)
goto failed;
radix_tree_preload_end();
if (sgp != SGP_READ && !prealloc_page) {
/* We don't care if this fails */
prealloc_page = shmem_alloc_page(gfp, info, idx);
if (prealloc_page) {
if (mem_cgroup_cache_charge(prealloc_page,
current->mm, GFP_KERNEL)) {
page_cache_release(prealloc_page);
prealloc_page = NULL;
}
}
}
}
error = 0;

spin_lock(&info->lock);
shmem_recalc_inode(inode);
Expand Down Expand Up @@ -1405,28 +1417,38 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
if (!filepage) {
int ret;

spin_unlock(&info->lock);
filepage = shmem_alloc_page(gfp, info, idx);
if (!filepage) {
shmem_unacct_blocks(info->flags, 1);
shmem_free_blocks(inode, 1);
error = -ENOMEM;
goto failed;
}
SetPageSwapBacked(filepage);
if (!prealloc_page) {
spin_unlock(&info->lock);
filepage = shmem_alloc_page(gfp, info, idx);
if (!filepage) {
shmem_unacct_blocks(info->flags, 1);
shmem_free_blocks(inode, 1);
error = -ENOMEM;
goto failed;
}
SetPageSwapBacked(filepage);

/* Precharge page while we can wait, compensate after */
error = mem_cgroup_cache_charge(filepage, current->mm,
GFP_KERNEL);
if (error) {
page_cache_release(filepage);
shmem_unacct_blocks(info->flags, 1);
shmem_free_blocks(inode, 1);
filepage = NULL;
goto failed;
/*
* Precharge page while we can wait, compensate
* after
*/
error = mem_cgroup_cache_charge(filepage,
current->mm, GFP_KERNEL);
if (error) {
page_cache_release(filepage);
shmem_unacct_blocks(info->flags, 1);
shmem_free_blocks(inode, 1);
filepage = NULL;
goto failed;
}

spin_lock(&info->lock);
} else {
filepage = prealloc_page;
prealloc_page = NULL;
SetPageSwapBacked(filepage);
}

spin_lock(&info->lock);
entry = shmem_swp_alloc(info, idx, sgp);
if (IS_ERR(entry))
error = PTR_ERR(entry);
Expand Down Expand Up @@ -1467,13 +1489,19 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
}
done:
*pagep = filepage;
return 0;
error = 0;
goto out;

failed:
if (*pagep != filepage) {
unlock_page(filepage);
page_cache_release(filepage);
}
out:
if (prealloc_page) {
mem_cgroup_uncharge_cache_page(prealloc_page);
page_cache_release(prealloc_page);
}
return error;
}

Expand Down

0 comments on commit 4d730c3

Please sign in to comment.