Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 284387
b: refs/heads/master
c: 4e5f01c
h: refs/heads/master
i:
  284385: 7e3569e
  284383: 1b86b57
v: v3
  • Loading branch information
KAMEZAWA Hiroyuki authored and Linus Torvalds committed Jan 13, 2012
1 parent 48a05cd commit a93ef5a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 36b62ad539498d00c2d280a151abad5f7630fa73
refs/heads/master: 4e5f01c2b9b94321992acb09c35d34f5ee5bb274
5 changes: 5 additions & 0 deletions trunk/include/linux/memcontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ extern void mem_cgroup_print_oom_info(struct mem_cgroup *memcg,
extern void mem_cgroup_replace_page_cache(struct page *oldpage,
struct page *newpage);

extern void mem_cgroup_reset_owner(struct page *page);
#ifdef CONFIG_CGROUP_MEM_RES_CTLR_SWAP
extern int do_swap_account;
#endif
Expand Down Expand Up @@ -391,6 +392,10 @@ static inline void mem_cgroup_replace_page_cache(struct page *oldpage,
struct page *newpage)
{
}

static inline void mem_cgroup_reset_owner(struct page *page)
{
}
#endif /* CONFIG_CGROUP_MEM_CONT */

#if !defined(CONFIG_CGROUP_MEM_RES_CTLR) || !defined(CONFIG_DEBUG_VM)
Expand Down
11 changes: 11 additions & 0 deletions trunk/mm/ksm.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <linux/kthread.h>
#include <linux/wait.h>
#include <linux/slab.h>
#include <linux/memcontrol.h>
#include <linux/rbtree.h>
#include <linux/memory.h>
#include <linux/mmu_notifier.h>
Expand Down Expand Up @@ -1571,6 +1572,16 @@ struct page *ksm_does_need_to_copy(struct page *page,

new_page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address);
if (new_page) {
/*
* The memcg-specific accounting when moving
* pages around the LRU lists relies on the
* page's owner (memcg) to be valid. Usually,
* pages are assigned to a new owner before
* being put on the LRU list, but since this
* is not the case here, the stale owner from
* a previous allocation cycle must be reset.
*/
mem_cgroup_reset_owner(new_page);
copy_user_highpage(new_page, page, address, vma);

SetPageDirty(new_page);
Expand Down
17 changes: 17 additions & 0 deletions trunk/mm/memcontrol.c
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,23 @@ void mem_cgroup_uncharge_end(void)
batch->memcg = NULL;
}

/*
* A function for resetting pc->mem_cgroup for newly allocated pages.
* This function should be called if the newpage will be added to LRU
* before start accounting.
*/
void mem_cgroup_reset_owner(struct page *newpage)
{
struct page_cgroup *pc;

if (mem_cgroup_disabled())
return;

pc = lookup_page_cgroup(newpage);
VM_BUG_ON(PageCgroupUsed(pc));
pc->mem_cgroup = root_mem_cgroup;
}

#ifdef CONFIG_SWAP
/*
* called after __delete_from_swap_cache() and drop "page" account.
Expand Down
2 changes: 2 additions & 0 deletions trunk/mm/migrate.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ static int unmap_and_move(new_page_t get_new_page, unsigned long private,
if (!newpage)
return -ENOMEM;

mem_cgroup_reset_owner(newpage);

if (page_count(page) == 1) {
/* page was freed from under us. So we are done. */
goto out;
Expand Down
10 changes: 10 additions & 0 deletions trunk/mm/swap_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,16 @@ struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
new_page = alloc_page_vma(gfp_mask, vma, addr);
if (!new_page)
break; /* Out of memory */
/*
* The memcg-specific accounting when moving
* pages around the LRU lists relies on the
* page's owner (memcg) to be valid. Usually,
* pages are assigned to a new owner before
* being put on the LRU list, but since this
* is not the case here, the stale owner from
* a previous allocation cycle must be reset.
*/
mem_cgroup_reset_owner(new_page);
}

/*
Expand Down

0 comments on commit a93ef5a

Please sign in to comment.