Re: [PATCH v4 1/3] memcg: clean up existing move charge code

From: Hillf Danton
Date: Wed Mar 14 2012 - 08:31:44 EST


On Wed, Mar 14, 2012 at 6:15 AM, Naoya Horiguchi
<n-horiguchi@xxxxxxxxxxxxx> wrote:
> From c9bdd8f19040f3cea1c7d36e98b03ee13c1b8505 Mon Sep 17 00:00:00 2001
> From: Naoya Horiguchi <n-horiguchi@xxxxxxxxxxxxx>
> Date: Tue, 13 Mar 2012 15:21:47 -0400
> Subject: [PATCH 1/3] memcg: clean up existing move charge code
>
> We'll introduce the thp variant of move charge code in later patches,
> but before doing that let's start with refactoring existing code.
> Here we replace lengthy function name is_target_pte_for_mc() with
> shorter one in order to avoid ugly line breaks.
> And for better readability, we explicitly use MC_TARGET_* instead of
> simply using integers.
>
> Signed-off-by: Naoya Horiguchi <n-horiguchi@xxxxxxxxxxxxx>
> Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@xxxxxxxxxxxxxx>

Acked-by: Hillf Danton <dhillf@xxxxxxxxx>

> ---
> Âmm/memcontrol.c | Â 17 ++++++++---------
> Â1 files changed, 8 insertions(+), 9 deletions(-)
>
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index a288855..508a7ed 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -5069,7 +5069,7 @@ one_by_one:
> Â}
>
> Â/**
> - * is_target_pte_for_mc - check a pte whether it is valid for move charge
> + * get_mctgt_type - get target type of moving charge
> Â* @vma: the vma the pte to be checked belongs
> Â* @addr: the address corresponding to the pte to be checked
> Â* @ptent: the pte to be checked
> @@ -5092,7 +5092,7 @@ union mc_target {
> Â};
>
> Âenum mc_target_type {
> - Â Â Â MC_TARGET_NONE, /* not used */
> + Â Â Â MC_TARGET_NONE = 0,
> Â Â Â ÂMC_TARGET_PAGE,
> Â Â Â ÂMC_TARGET_SWAP,
> Â};
> @@ -5173,12 +5173,12 @@ static struct page *mc_handle_file_pte(struct vm_area_struct *vma,
> Â Â Â Âreturn page;
> Â}
>
> -static int is_target_pte_for_mc(struct vm_area_struct *vma,
> +static enum mc_target_type get_mctgt_type(struct vm_area_struct *vma,
> Â Â Â Â Â Â Â Âunsigned long addr, pte_t ptent, union mc_target *target)
> Â{
> Â Â Â Âstruct page *page = NULL;
> Â Â Â Âstruct page_cgroup *pc;
> - Â Â Â int ret = 0;
> + Â Â Â enum mc_target_type ret = MC_TARGET_NONE;
> Â Â Â Âswp_entry_t ent = { .val = 0 };
>
> Â Â Â Âif (pte_present(ptent))
> @@ -5189,7 +5189,7 @@ static int is_target_pte_for_mc(struct vm_area_struct *vma,
> Â Â Â Â Â Â Â Âpage = mc_handle_file_pte(vma, addr, ptent, &ent);
>
> Â Â Â Âif (!page && !ent.val)
> - Â Â Â Â Â Â Â return 0;
> + Â Â Â Â Â Â Â return ret;
> Â Â Â Âif (page) {
> Â Â Â Â Â Â Â Âpc = lookup_page_cgroup(page);
> Â Â Â Â Â Â Â Â/*
> @@ -5227,7 +5227,7 @@ static int mem_cgroup_count_precharge_pte_range(pmd_t *pmd,
>
> Â Â Â Âpte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
> Â Â Â Âfor (; addr != end; pte++, addr += PAGE_SIZE)
> - Â Â Â Â Â Â Â if (is_target_pte_for_mc(vma, addr, *pte, NULL))
> + Â Â Â Â Â Â Â if (get_mctgt_type(vma, addr, *pte, NULL))
> Â Â Â Â Â Â Â Â Â Â Â Âmc.precharge++; /* increment precharge temporarily */
> Â Â Â Âpte_unmap_unlock(pte - 1, ptl);
> Â Â Â Âcond_resched();
> @@ -5397,8 +5397,7 @@ retry:
> Â Â Â Â Â Â Â Âif (!mc.precharge)
> Â Â Â Â Â Â Â Â Â Â Â Âbreak;
>
> - Â Â Â Â Â Â Â type = is_target_pte_for_mc(vma, addr, ptent, &target);
> - Â Â Â Â Â Â Â switch (type) {
> + Â Â Â Â Â Â Â switch (get_mctgt_type(vma, addr, ptent, &target)) {
> Â Â Â Â Â Â Â Âcase MC_TARGET_PAGE:
> Â Â Â Â Â Â Â Â Â Â Â Âpage = target.page;
> Â Â Â Â Â Â Â Â Â Â Â Âif (isolate_lru_page(page))
> @@ -5411,7 +5410,7 @@ retry:
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âmc.moved_charge++;
> Â Â Â Â Â Â Â Â Â Â Â Â}
> Â Â Â Â Â Â Â Â Â Â Â Âputback_lru_page(page);
> -put: Â Â Â Â Â Â Â Â Â /* is_target_pte_for_mc() gets the page */
> +put: Â Â Â Â Â Â Â Â Â /* get_mctgt_type() gets the page */
> Â Â Â Â Â Â Â Â Â Â Â Âput_page(page);
> Â Â Â Â Â Â Â Â Â Â Â Âbreak;
> Â Â Â Â Â Â Â Âcase MC_TARGET_SWAP:
> --
> 1.7.7.6
>
--
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/