diff options
author | Johannes Weiner <hannes@cmpxchg.org> | 2015-02-11 18:26:09 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-02-11 20:06:02 -0500 |
commit | 1dfab5abcdd404fd04597c063d9f61a5b3247552 (patch) | |
tree | d8b69a2260b839a6db419ee39d520d14eda34f74 /mm | |
parent | 241994ed8649f7300667be8b13a9e04ae04e05a1 (diff) |
mm: memcontrol: fold move_anon() and move_file()
Turn the move type enum into flags and give the flags field a shorter
name. Once that is done, move_anon() and move_file() are simple enough to
just fold them into the callsites.
[akpm@linux-foundation.org: tweak MOVE_MASK definition, per Michal]
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Michal Hocko <mhocko@suse.cz>
Reviewed-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Greg Thelen <gthelen@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm')
-rw-r--r-- | mm/memcontrol.c | 49 |
1 files changed, 18 insertions, 31 deletions
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index ee97c9ac62c0..11c9e6a1dad5 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c | |||
@@ -369,21 +369,18 @@ static bool memcg_kmem_is_active(struct mem_cgroup *memcg) | |||
369 | 369 | ||
370 | /* Stuffs for move charges at task migration. */ | 370 | /* Stuffs for move charges at task migration. */ |
371 | /* | 371 | /* |
372 | * Types of charges to be moved. "move_charge_at_immitgrate" and | 372 | * Types of charges to be moved. |
373 | * "immigrate_flags" are treated as a left-shifted bitmap of these types. | ||
374 | */ | 373 | */ |
375 | enum move_type { | 374 | #define MOVE_ANON 0x1U |
376 | MOVE_CHARGE_TYPE_ANON, /* private anonymous page and swap of it */ | 375 | #define MOVE_FILE 0x2U |
377 | MOVE_CHARGE_TYPE_FILE, /* file page(including tmpfs) and swap of it */ | 376 | #define MOVE_MASK (MOVE_ANON | MOVE_FILE) |
378 | NR_MOVE_TYPE, | ||
379 | }; | ||
380 | 377 | ||
381 | /* "mc" and its members are protected by cgroup_mutex */ | 378 | /* "mc" and its members are protected by cgroup_mutex */ |
382 | static struct move_charge_struct { | 379 | static struct move_charge_struct { |
383 | spinlock_t lock; /* for from, to */ | 380 | spinlock_t lock; /* for from, to */ |
384 | struct mem_cgroup *from; | 381 | struct mem_cgroup *from; |
385 | struct mem_cgroup *to; | 382 | struct mem_cgroup *to; |
386 | unsigned long immigrate_flags; | 383 | unsigned long flags; |
387 | unsigned long precharge; | 384 | unsigned long precharge; |
388 | unsigned long moved_charge; | 385 | unsigned long moved_charge; |
389 | unsigned long moved_swap; | 386 | unsigned long moved_swap; |
@@ -394,16 +391,6 @@ static struct move_charge_struct { | |||
394 | .waitq = __WAIT_QUEUE_HEAD_INITIALIZER(mc.waitq), | 391 | .waitq = __WAIT_QUEUE_HEAD_INITIALIZER(mc.waitq), |
395 | }; | 392 | }; |
396 | 393 | ||
397 | static bool move_anon(void) | ||
398 | { | ||
399 | return test_bit(MOVE_CHARGE_TYPE_ANON, &mc.immigrate_flags); | ||
400 | } | ||
401 | |||
402 | static bool move_file(void) | ||
403 | { | ||
404 | return test_bit(MOVE_CHARGE_TYPE_FILE, &mc.immigrate_flags); | ||
405 | } | ||
406 | |||
407 | /* | 394 | /* |
408 | * Maximum loops in mem_cgroup_hierarchical_reclaim(), used for soft | 395 | * Maximum loops in mem_cgroup_hierarchical_reclaim(), used for soft |
409 | * limit reclaim to prevent infinite loops, if they ever occur. | 396 | * limit reclaim to prevent infinite loops, if they ever occur. |
@@ -3500,7 +3487,7 @@ static int mem_cgroup_move_charge_write(struct cgroup_subsys_state *css, | |||
3500 | { | 3487 | { |
3501 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); | 3488 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); |
3502 | 3489 | ||
3503 | if (val >= (1 << NR_MOVE_TYPE)) | 3490 | if (val & ~MOVE_MASK) |
3504 | return -EINVAL; | 3491 | return -EINVAL; |
3505 | 3492 | ||
3506 | /* | 3493 | /* |
@@ -4773,12 +4760,12 @@ static struct page *mc_handle_present_pte(struct vm_area_struct *vma, | |||
4773 | if (!page || !page_mapped(page)) | 4760 | if (!page || !page_mapped(page)) |
4774 | return NULL; | 4761 | return NULL; |
4775 | if (PageAnon(page)) { | 4762 | if (PageAnon(page)) { |
4776 | /* we don't move shared anon */ | 4763 | if (!(mc.flags & MOVE_ANON)) |
4777 | if (!move_anon()) | ||
4778 | return NULL; | 4764 | return NULL; |
4779 | } else if (!move_file()) | 4765 | } else { |
4780 | /* we ignore mapcount for file pages */ | 4766 | if (!(mc.flags & MOVE_FILE)) |
4781 | return NULL; | 4767 | return NULL; |
4768 | } | ||
4782 | if (!get_page_unless_zero(page)) | 4769 | if (!get_page_unless_zero(page)) |
4783 | return NULL; | 4770 | return NULL; |
4784 | 4771 | ||
@@ -4792,7 +4779,7 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma, | |||
4792 | struct page *page = NULL; | 4779 | struct page *page = NULL; |
4793 | swp_entry_t ent = pte_to_swp_entry(ptent); | 4780 | swp_entry_t ent = pte_to_swp_entry(ptent); |
4794 | 4781 | ||
4795 | if (!move_anon() || non_swap_entry(ent)) | 4782 | if (!(mc.flags & MOVE_ANON) || non_swap_entry(ent)) |
4796 | return NULL; | 4783 | return NULL; |
4797 | /* | 4784 | /* |
4798 | * Because lookup_swap_cache() updates some statistics counter, | 4785 | * Because lookup_swap_cache() updates some statistics counter, |
@@ -4821,7 +4808,7 @@ static struct page *mc_handle_file_pte(struct vm_area_struct *vma, | |||
4821 | 4808 | ||
4822 | if (!vma->vm_file) /* anonymous vma */ | 4809 | if (!vma->vm_file) /* anonymous vma */ |
4823 | return NULL; | 4810 | return NULL; |
4824 | if (!move_file()) | 4811 | if (!(mc.flags & MOVE_FILE)) |
4825 | return NULL; | 4812 | return NULL; |
4826 | 4813 | ||
4827 | mapping = vma->vm_file->f_mapping; | 4814 | mapping = vma->vm_file->f_mapping; |
@@ -4900,7 +4887,7 @@ static enum mc_target_type get_mctgt_type_thp(struct vm_area_struct *vma, | |||
4900 | 4887 | ||
4901 | page = pmd_page(pmd); | 4888 | page = pmd_page(pmd); |
4902 | VM_BUG_ON_PAGE(!page || !PageHead(page), page); | 4889 | VM_BUG_ON_PAGE(!page || !PageHead(page), page); |
4903 | if (!move_anon()) | 4890 | if (!(mc.flags & MOVE_ANON)) |
4904 | return ret; | 4891 | return ret; |
4905 | if (page->mem_cgroup == mc.from) { | 4892 | if (page->mem_cgroup == mc.from) { |
4906 | ret = MC_TARGET_PAGE; | 4893 | ret = MC_TARGET_PAGE; |
@@ -5042,15 +5029,15 @@ static int mem_cgroup_can_attach(struct cgroup_subsys_state *css, | |||
5042 | struct task_struct *p = cgroup_taskset_first(tset); | 5029 | struct task_struct *p = cgroup_taskset_first(tset); |
5043 | int ret = 0; | 5030 | int ret = 0; |
5044 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); | 5031 | struct mem_cgroup *memcg = mem_cgroup_from_css(css); |
5045 | unsigned long move_charge_at_immigrate; | 5032 | unsigned long move_flags; |
5046 | 5033 | ||
5047 | /* | 5034 | /* |
5048 | * We are now commited to this value whatever it is. Changes in this | 5035 | * We are now commited to this value whatever it is. Changes in this |
5049 | * tunable will only affect upcoming migrations, not the current one. | 5036 | * tunable will only affect upcoming migrations, not the current one. |
5050 | * So we need to save it, and keep it going. | 5037 | * So we need to save it, and keep it going. |
5051 | */ | 5038 | */ |
5052 | move_charge_at_immigrate = memcg->move_charge_at_immigrate; | 5039 | move_flags = ACCESS_ONCE(memcg->move_charge_at_immigrate); |
5053 | if (move_charge_at_immigrate) { | 5040 | if (move_flags) { |
5054 | struct mm_struct *mm; | 5041 | struct mm_struct *mm; |
5055 | struct mem_cgroup *from = mem_cgroup_from_task(p); | 5042 | struct mem_cgroup *from = mem_cgroup_from_task(p); |
5056 | 5043 | ||
@@ -5070,7 +5057,7 @@ static int mem_cgroup_can_attach(struct cgroup_subsys_state *css, | |||
5070 | spin_lock(&mc.lock); | 5057 | spin_lock(&mc.lock); |
5071 | mc.from = from; | 5058 | mc.from = from; |
5072 | mc.to = memcg; | 5059 | mc.to = memcg; |
5073 | mc.immigrate_flags = move_charge_at_immigrate; | 5060 | mc.flags = move_flags; |
5074 | spin_unlock(&mc.lock); | 5061 | spin_unlock(&mc.lock); |
5075 | /* We set mc.moving_task later */ | 5062 | /* We set mc.moving_task later */ |
5076 | 5063 | ||