Commit 152c9ccb authored by Daisuke Nishimura's avatar Daisuke Nishimura Committed by Linus Torvalds

thp: transhuge-memcg: commit tail pages at charge

By this patch, when a transparent hugepage is charged, not only the head
page but also all the tail pages are committed, IOW pc->mem_cgroup and
pc->flags of tail pages are set.

Without this patch:

- Tail pages are not linked to any memcg's LRU at splitting. This causes many
  problems, for example, the charged memcg's directory can never be rmdir'ed
  because it doesn't have enough pages to scan to make the usage decrease to 0.
- "rss" field in memory.stat would be incorrect. Moreover, usage_in_bytes in
  root cgroup is calculated by the stat not by res_counter(since 2.6.32),
  it would be incorrect too.
Signed-off-by: default avatarDaisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Signed-off-by: default avatarAndrea Arcangeli <aarcange@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ec168510
...@@ -2094,23 +2094,10 @@ struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page) ...@@ -2094,23 +2094,10 @@ struct mem_cgroup *try_get_mem_cgroup_from_page(struct page *page)
* commit a charge got by __mem_cgroup_try_charge() and makes page_cgroup to be * commit a charge got by __mem_cgroup_try_charge() and makes page_cgroup to be
* USED state. If already USED, uncharge and return. * USED state. If already USED, uncharge and return.
*/ */
static void ____mem_cgroup_commit_charge(struct mem_cgroup *mem,
static void __mem_cgroup_commit_charge(struct mem_cgroup *mem, struct page_cgroup *pc,
struct page_cgroup *pc, enum charge_type ctype)
enum charge_type ctype,
int page_size)
{ {
/* try_charge() can return NULL to *memcg, taking care of it. */
if (!mem)
return;
lock_page_cgroup(pc);
if (unlikely(PageCgroupUsed(pc))) {
unlock_page_cgroup(pc);
mem_cgroup_cancel_charge(mem, page_size);
return;
}
pc->mem_cgroup = mem; pc->mem_cgroup = mem;
/* /*
* We access a page_cgroup asynchronously without lock_page_cgroup(). * We access a page_cgroup asynchronously without lock_page_cgroup().
...@@ -2135,6 +2122,33 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *mem, ...@@ -2135,6 +2122,33 @@ static void __mem_cgroup_commit_charge(struct mem_cgroup *mem,
} }
mem_cgroup_charge_statistics(mem, pc, true); mem_cgroup_charge_statistics(mem, pc, true);
}
static void __mem_cgroup_commit_charge(struct mem_cgroup *mem,
struct page_cgroup *pc,
enum charge_type ctype,
int page_size)
{
int i;
int count = page_size >> PAGE_SHIFT;
/* try_charge() can return NULL to *memcg, taking care of it. */
if (!mem)
return;
lock_page_cgroup(pc);
if (unlikely(PageCgroupUsed(pc))) {
unlock_page_cgroup(pc);
mem_cgroup_cancel_charge(mem, page_size);
return;
}
/*
* we don't need page_cgroup_lock about tail pages, becase they are not
* accessed by any other context at this point.
*/
for (i = 0; i < count; i++)
____mem_cgroup_commit_charge(mem, pc + i, ctype);
unlock_page_cgroup(pc); unlock_page_cgroup(pc);
/* /*
...@@ -2532,6 +2546,8 @@ __do_uncharge(struct mem_cgroup *mem, const enum charge_type ctype, ...@@ -2532,6 +2546,8 @@ __do_uncharge(struct mem_cgroup *mem, const enum charge_type ctype,
static struct mem_cgroup * static struct mem_cgroup *
__mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
{ {
int i;
int count;
struct page_cgroup *pc; struct page_cgroup *pc;
struct mem_cgroup *mem = NULL; struct mem_cgroup *mem = NULL;
int page_size = PAGE_SIZE; int page_size = PAGE_SIZE;
...@@ -2545,6 +2561,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) ...@@ -2545,6 +2561,7 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
if (PageTransHuge(page)) if (PageTransHuge(page))
page_size <<= compound_order(page); page_size <<= compound_order(page);
count = page_size >> PAGE_SHIFT;
/* /*
* Check if our page_cgroup is valid * Check if our page_cgroup is valid
*/ */
...@@ -2577,7 +2594,8 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype) ...@@ -2577,7 +2594,8 @@ __mem_cgroup_uncharge_common(struct page *page, enum charge_type ctype)
break; break;
} }
mem_cgroup_charge_statistics(mem, pc, false); for (i = 0; i < count; i++)
mem_cgroup_charge_statistics(mem, pc + i, false);
ClearPageCgroupUsed(pc); ClearPageCgroupUsed(pc);
/* /*
......
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