[Devel,rh7] mm/memcg: add missing kmem charge.

Submitted by Andrey Ryabinin on Aug. 29, 2017, 3:13 p.m.

Details

Message ID 20170829151317.20790-1-aryabinin@virtuozzo.com
State New
Series "mm/memcg: add missing kmem charge."
Headers show

Commit Message

Andrey Ryabinin Aug. 29, 2017, 3:13 p.m.
Since de3a106e28d5 ("mm/memcg: reclaim memory on reaching kmem limit.")
if try_charge() decide to bypass memory limit, mem_cgroup_charge_kmem()
will charge only ->memory/->memsw but not ->kmem. This may lead to
deadlocks during cgroup destruction as condition:
	 (page_counter_read(&memcg->memory) -
	 page_counter_read(&memcg->kmem) > 0)

in mem_cgroup_reparent_charges() won't come true ever.

https://jira.sw.ru/browse/PSBM-70556
Fixes: de3a106e28d5 ("mm/memcg: reclaim memory on reaching kmem limit.")
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)

Patch hide | download patch | download mbox

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 5ab5e82c924e..49d4586c9d21 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3087,6 +3087,8 @@  int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp,
 		page_counter_charge(&memcg->memory, nr_pages);
 		if (do_swap_account)
 			page_counter_charge(&memcg->memsw, nr_pages);
+		page_counter_charge(&memcg->kmem, nr_pages);
+
 		ret = 0;
 	}
 

Comments

Vasily Averin Aug. 30, 2017, 11:40 a.m.
On 2017-08-29 18:13, Andrey Ryabinin wrote:
> Since de3a106e28d5 ("mm/memcg: reclaim memory on reaching kmem limit.")
> if try_charge() decide to bypass memory limit, mem_cgroup_charge_kmem()

memcg_charge_kmem() should be here

> will charge only ->memory/->memsw but not ->kmem. This may lead to
> deadlocks during cgroup destruction as condition:
> 	 (page_counter_read(&memcg->memory) -
> 	 page_counter_read(&memcg->kmem) > 0)
> 
> in mem_cgroup_reparent_charges() won't come true ever.
> 
> https://jira.sw.ru/browse/PSBM-70556
> Fixes: de3a106e28d5 ("mm/memcg: reclaim memory on reaching kmem limit.")
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Reviewed-by:	Vasily Averin <vvs@virtuozzo.com>

> ---
>  mm/memcontrol.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 5ab5e82c924e..49d4586c9d21 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3087,6 +3087,8 @@ int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp,
>  		page_counter_charge(&memcg->memory, nr_pages);
>  		if (do_swap_account)
>  			page_counter_charge(&memcg->memsw, nr_pages);
> +		page_counter_charge(&memcg->kmem, nr_pages);
> +
>  		ret = 0;
>  	}
>  
>
Vasily Averin Aug. 30, 2017, 11:41 a.m.
On 2017-08-29 18:13, Andrey Ryabinin wrote:
> Since de3a106e28d5 ("mm/memcg: reclaim memory on reaching kmem limit.")
> if try_charge() decide to bypass memory limit, mem_cgroup_charge_kmem()

memcg_charge_kmem() should be here

> will charge only ->memory/->memsw but not ->kmem. This may lead to
> deadlocks during cgroup destruction as condition:
> 	 (page_counter_read(&memcg->memory) -
> 	 page_counter_read(&memcg->kmem) > 0)
> 
> in mem_cgroup_reparent_charges() won't come true ever.
> 
> https://jira.sw.ru/browse/PSBM-70556
> Fixes: de3a106e28d5 ("mm/memcg: reclaim memory on reaching kmem limit.")
> Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Reviewed-by:	Vasily Averin <vvs@virtuozzo.com>

> ---
>  mm/memcontrol.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 5ab5e82c924e..49d4586c9d21 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -3087,6 +3087,8 @@ int memcg_charge_kmem(struct mem_cgroup *memcg, gfp_t gfp,
>  		page_counter_charge(&memcg->memory, nr_pages);
>  		if (do_swap_account)
>  			page_counter_charge(&memcg->memsw, nr_pages);
> +		page_counter_charge(&memcg->kmem, nr_pages);
> +
>  		ret = 0;
>  	}
>  
>