Commit a3032a2c15c6967f9f0c0c28375b1a5c833a3112
Committed by
Linus Torvalds
1 parent
d8046582d5
Exists in
master
and in
4 other branches
memcg: add mem_cgroup_cancel_charge()
There are some places calling both res_counter_uncharge() and css_put() to cancel the charge and the refcnt we have got by mem_cgroup_tyr_charge(). This patch introduces mem_cgroup_cancel_charge() and call it in those places. Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp> Reviewed-by: Balbir Singh <balbir@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 18 additions and 20 deletions Side-by-side Diff
mm/memcontrol.c
... | ... | @@ -1500,6 +1500,21 @@ |
1500 | 1500 | } |
1501 | 1501 | |
1502 | 1502 | /* |
1503 | + * Somemtimes we have to undo a charge we got by try_charge(). | |
1504 | + * This function is for that and do uncharge, put css's refcnt. | |
1505 | + * gotten by try_charge(). | |
1506 | + */ | |
1507 | +static void mem_cgroup_cancel_charge(struct mem_cgroup *mem) | |
1508 | +{ | |
1509 | + if (!mem_cgroup_is_root(mem)) { | |
1510 | + res_counter_uncharge(&mem->res, PAGE_SIZE); | |
1511 | + if (do_swap_account) | |
1512 | + res_counter_uncharge(&mem->memsw, PAGE_SIZE); | |
1513 | + } | |
1514 | + css_put(&mem->css); | |
1515 | +} | |
1516 | + | |
1517 | +/* | |
1503 | 1518 | * A helper function to get mem_cgroup from ID. must be called under |
1504 | 1519 | * rcu_read_lock(). The caller must check css_is_removed() or some if |
1505 | 1520 | * it's concern. (dropping refcnt from swap can be called against removed |
... | ... | @@ -1565,12 +1580,7 @@ |
1565 | 1580 | lock_page_cgroup(pc); |
1566 | 1581 | if (unlikely(PageCgroupUsed(pc))) { |
1567 | 1582 | unlock_page_cgroup(pc); |
1568 | - if (!mem_cgroup_is_root(mem)) { | |
1569 | - res_counter_uncharge(&mem->res, PAGE_SIZE); | |
1570 | - if (do_swap_account) | |
1571 | - res_counter_uncharge(&mem->memsw, PAGE_SIZE); | |
1572 | - } | |
1573 | - css_put(&mem->css); | |
1583 | + mem_cgroup_cancel_charge(mem); | |
1574 | 1584 | return; |
1575 | 1585 | } |
1576 | 1586 | |
... | ... | @@ -1734,14 +1744,7 @@ |
1734 | 1744 | cancel: |
1735 | 1745 | put_page(page); |
1736 | 1746 | uncharge: |
1737 | - /* drop extra refcnt by try_charge() */ | |
1738 | - css_put(&parent->css); | |
1739 | - /* uncharge if move fails */ | |
1740 | - if (!mem_cgroup_is_root(parent)) { | |
1741 | - res_counter_uncharge(&parent->res, PAGE_SIZE); | |
1742 | - if (do_swap_account) | |
1743 | - res_counter_uncharge(&parent->memsw, PAGE_SIZE); | |
1744 | - } | |
1747 | + mem_cgroup_cancel_charge(parent); | |
1745 | 1748 | return ret; |
1746 | 1749 | } |
1747 | 1750 | |
... | ... | @@ -1958,12 +1961,7 @@ |
1958 | 1961 | return; |
1959 | 1962 | if (!mem) |
1960 | 1963 | return; |
1961 | - if (!mem_cgroup_is_root(mem)) { | |
1962 | - res_counter_uncharge(&mem->res, PAGE_SIZE); | |
1963 | - if (do_swap_account) | |
1964 | - res_counter_uncharge(&mem->memsw, PAGE_SIZE); | |
1965 | - } | |
1966 | - css_put(&mem->css); | |
1964 | + mem_cgroup_cancel_charge(mem); | |
1967 | 1965 | } |
1968 | 1966 | |
1969 | 1967 | static void |