[PATCH 2/9] mm: avoid calling get_page_unless_zero() when charging cgroups

From: Michel Lespinasse
Date: Fri Aug 19 2011 - 03:49:53 EST


In mem_cgroup_move_parent(), we can avoid the get_page_unless_zero()
call by taking a page reference under protection of the zone LRU lock
in mem_cgroup_force_empty_list().

In mc_handle_present_pte(), the page count is already known to be
nonzero as there is a PTE pointing to it and the page table lock is held.

Signed-off-by: Michel Lespinasse <walken@xxxxxxxxxx>
---
mm/memcontrol.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e013b8e..f9439ef 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2649,7 +2649,7 @@ out:
}

/*
- * move charges to its parent.
+ * move charges to its parent. Caller must hold a reference on page.
*/

static int mem_cgroup_move_parent(struct page *page,
@@ -2669,10 +2669,8 @@ static int mem_cgroup_move_parent(struct page *page,
return -EINVAL;

ret = -EBUSY;
- if (!get_page_unless_zero(page))
- goto out;
if (isolate_lru_page(page))
- goto put;
+ goto out;

nr_pages = hpage_nr_pages(page);

@@ -2692,8 +2690,6 @@ static int mem_cgroup_move_parent(struct page *page,
compound_unlock_irqrestore(page, flags);
put_back:
putback_lru_page(page);
-put:
- put_page(page);
out:
return ret;
}
@@ -3732,11 +3728,12 @@ static int mem_cgroup_force_empty_list(struct mem_cgroup *mem,
spin_unlock_irqrestore(&zone->lru_lock, flags);
continue;
}
- spin_unlock_irqrestore(&zone->lru_lock, flags);
-
page = lookup_cgroup_page(pc);
+ get_page(page);
+ spin_unlock_irqrestore(&zone->lru_lock, flags);

ret = mem_cgroup_move_parent(page, pc, mem, GFP_KERNEL);
+ put_page(page);
if (ret == -ENOMEM)
break;

@@ -5133,9 +5130,12 @@ static struct page *mc_handle_present_pte(struct vm_area_struct *vma,
} else if (!move_file())
/* we ignore mapcount for file pages */
return NULL;
- if (!get_page_unless_zero(page))
- return NULL;

+ /*
+ * The page reference count is guaranteed to be nonzero since
+ * ptent points to that page and the page table lock is held.
+ */
+ get_page(page);
return page;
}

--
1.7.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/