Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 83786
b: refs/heads/master
c: 8236955
h: refs/heads/master
v: v3
  • Loading branch information
Hugh Dickins authored and Linus Torvalds committed Feb 7, 2008
1 parent 06b2279 commit ba89be7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 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: 3be91277e754c7db04eae145ba622b3a3e3ad96d
refs/heads/master: 82369553d6d3bc67c54129a02e0bc0b5b88f3045
37 changes: 21 additions & 16 deletions trunk/mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,23 +329,26 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
* with it
*/
retry:
lock_page_cgroup(page);
pc = page_get_page_cgroup(page);
/*
* The page_cgroup exists and the page has already been accounted
*/
if (pc) {
if (unlikely(!atomic_inc_not_zero(&pc->ref_cnt))) {
/* this page is under being uncharged ? */
unlock_page_cgroup(page);
cpu_relax();
goto retry;
} else {
unlock_page_cgroup(page);
goto done;
if (page) {
lock_page_cgroup(page);
pc = page_get_page_cgroup(page);
/*
* The page_cgroup exists and
* the page has already been accounted.
*/
if (pc) {
if (unlikely(!atomic_inc_not_zero(&pc->ref_cnt))) {
/* this page is under being uncharged ? */
unlock_page_cgroup(page);
cpu_relax();
goto retry;
} else {
unlock_page_cgroup(page);
goto done;
}
}
unlock_page_cgroup(page);
}
unlock_page_cgroup(page);

pc = kzalloc(sizeof(struct page_cgroup), gfp_mask);
if (pc == NULL)
Expand Down Expand Up @@ -404,7 +407,7 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
if (ctype == MEM_CGROUP_CHARGE_TYPE_CACHE)
pc->flags |= PAGE_CGROUP_FLAG_CACHE;

if (page_cgroup_assign_new_page_cgroup(page, pc)) {
if (!page || page_cgroup_assign_new_page_cgroup(page, pc)) {
/*
* Another charge has been added to this page already.
* We take lock_page_cgroup(page) again and read
Expand All @@ -413,6 +416,8 @@ static int mem_cgroup_charge_common(struct page *page, struct mm_struct *mm,
res_counter_uncharge(&mem->res, PAGE_SIZE);
css_put(&mem->css);
kfree(pc);
if (!page)
goto done;
goto retry;
}

Expand Down
28 changes: 27 additions & 1 deletion trunk/mm/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,9 +912,13 @@ static int shmem_unuse_inode(struct shmem_inode_info *info, swp_entry_t entry, s
error = 1;
if (!inode)
goto out;
error = radix_tree_preload(GFP_KERNEL);
/* Precharge page while we can wait, compensate afterwards */
error = mem_cgroup_cache_charge(page, current->mm, GFP_KERNEL);
if (error)
goto out;
error = radix_tree_preload(GFP_KERNEL);
if (error)
goto uncharge;
error = 1;

spin_lock(&info->lock);
Expand Down Expand Up @@ -947,6 +951,8 @@ static int shmem_unuse_inode(struct shmem_inode_info *info, swp_entry_t entry, s
shmem_swp_unmap(ptr);
spin_unlock(&info->lock);
radix_tree_preload_end();
uncharge:
mem_cgroup_uncharge_page(page);
out:
unlock_page(page);
page_cache_release(page);
Expand Down Expand Up @@ -1308,6 +1314,13 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
spin_unlock(&info->lock);
unlock_page(swappage);
page_cache_release(swappage);
if (error == -ENOMEM) {
/* allow reclaim from this memory cgroup */
error = mem_cgroup_cache_charge(NULL,
current->mm, gfp & ~__GFP_HIGHMEM);
if (error)
goto failed;
}
goto repeat;
}
} else if (sgp == SGP_READ && !filepage) {
Expand Down Expand Up @@ -1353,6 +1366,17 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
goto failed;
}

/* Precharge page while we can wait, compensate after */
error = mem_cgroup_cache_charge(filepage, current->mm,
gfp & ~__GFP_HIGHMEM);
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);
entry = shmem_swp_alloc(info, idx, sgp);
if (IS_ERR(entry))
Expand All @@ -1364,6 +1388,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
if (error || swap.val || 0 != add_to_page_cache_lru(
filepage, mapping, idx, GFP_NOWAIT)) {
spin_unlock(&info->lock);
mem_cgroup_uncharge_page(filepage);
page_cache_release(filepage);
shmem_unacct_blocks(info->flags, 1);
shmem_free_blocks(inode, 1);
Expand All @@ -1372,6 +1397,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx,
goto failed;
goto repeat;
}
mem_cgroup_uncharge_page(filepage);
info->flags |= SHMEM_PAGEIN;
}

Expand Down

0 comments on commit ba89be7

Please sign in to comment.