linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] memcg: do not call reclaim if !__GFP_WAIT
@ 2015-05-28 17:26 Vladimir Davydov
  2015-05-28 18:13 ` Michal Hocko
  2015-05-28 19:59 ` Andrew Morton
  0 siblings, 2 replies; 5+ messages in thread
From: Vladimir Davydov @ 2015-05-28 17:26 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Johannes Weiner, Michal Hocko

When trimming memcg consumption excess (see memory.high), we call
try_to_free_mem_cgroup_pages without checking if we are allowed to sleep
in the current context, which can result in a deadlock. Fix this.

Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Michal Hocko <mhocko@suse.cz>
---
 mm/memcontrol.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 14c2f2017e37..9da23a7ec4c0 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2323,6 +2323,8 @@ done_restock:
 	css_get_many(&memcg->css, batch);
 	if (batch > nr_pages)
 		refill_stock(memcg, batch - nr_pages);
+	if (!(gfp_mask & __GFP_WAIT))
+		goto done;
 	/*
 	 * If the hierarchy is above the normal consumption range,
 	 * make the charging task trim their excess contribution.
-- 
2.1.4

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] memcg: do not call reclaim if !__GFP_WAIT
  2015-05-28 17:26 [PATCH] memcg: do not call reclaim if !__GFP_WAIT Vladimir Davydov
@ 2015-05-28 18:13 ` Michal Hocko
  2015-05-28 19:59 ` Andrew Morton
  1 sibling, 0 replies; 5+ messages in thread
From: Michal Hocko @ 2015-05-28 18:13 UTC (permalink / raw)
  To: Vladimir Davydov; +Cc: Andrew Morton, linux-mm, linux-kernel, Johannes Weiner

On Thu 28-05-15 20:26:06, Vladimir Davydov wrote:
> When trimming memcg consumption excess (see memory.high), we call
> try_to_free_mem_cgroup_pages without checking if we are allowed to sleep
> in the current context, which can result in a deadlock. Fix this.
> 

Fixes: 241994ed8649 ("mm: memcontrol: default hierarchy interface for memory")

And I would make it for stable 4.0

> Signed-off-by: Vladimir Davydov <vdavydov@parallels.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@suse.cz>

Acked-by: Michal Hocko <mhocko@suse.cz>

Thanks!

> ---
>  mm/memcontrol.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 14c2f2017e37..9da23a7ec4c0 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -2323,6 +2323,8 @@ done_restock:
>  	css_get_many(&memcg->css, batch);
>  	if (batch > nr_pages)
>  		refill_stock(memcg, batch - nr_pages);
> +	if (!(gfp_mask & __GFP_WAIT))
> +		goto done;
>  	/*
>  	 * If the hierarchy is above the normal consumption range,
>  	 * make the charging task trim their excess contribution.
> -- 
> 2.1.4
> 

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] memcg: do not call reclaim if !__GFP_WAIT
  2015-05-28 17:26 [PATCH] memcg: do not call reclaim if !__GFP_WAIT Vladimir Davydov
  2015-05-28 18:13 ` Michal Hocko
@ 2015-05-28 19:59 ` Andrew Morton
  2015-05-29  6:55   ` Michal Hocko
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2015-05-28 19:59 UTC (permalink / raw)
  To: Vladimir Davydov; +Cc: linux-mm, linux-kernel, Johannes Weiner, Michal Hocko

On Thu, 28 May 2015 20:26:06 +0300 Vladimir Davydov <vdavydov@parallels.com> wrote:

> When trimming memcg consumption excess (see memory.high), we call
> try_to_free_mem_cgroup_pages without checking if we are allowed to sleep
> in the current context, which can result in a deadlock. Fix this.

Why does it deadlock?  try_to_free_mem_cgroup_pages() is passed the
gfp_mask and should honour its __GFP_WAIT setting?

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] memcg: do not call reclaim if !__GFP_WAIT
  2015-05-28 19:59 ` Andrew Morton
@ 2015-05-29  6:55   ` Michal Hocko
  2015-06-01 16:42     ` Vlastimil Babka
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Hocko @ 2015-05-29  6:55 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Vladimir Davydov, linux-mm, linux-kernel, Johannes Weiner

On Thu 28-05-15 12:59:34, Andrew Morton wrote:
> On Thu, 28 May 2015 20:26:06 +0300 Vladimir Davydov <vdavydov@parallels.com> wrote:
> 
> > When trimming memcg consumption excess (see memory.high), we call
> > try_to_free_mem_cgroup_pages without checking if we are allowed to sleep
> > in the current context, which can result in a deadlock. Fix this.
> 
> Why does it deadlock?  try_to_free_mem_cgroup_pages() is passed the
> gfp_mask and should honour its __GFP_WAIT setting?

The only instance of __GFP_WAIT check in vmscan code is in zone_reclaim.
Page allocations and memcg reclaim avoids calling reclaim if __GFP_WAIT
is not set. Maybe we can move the check to do_try_to_free_pages?

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] memcg: do not call reclaim if !__GFP_WAIT
  2015-05-29  6:55   ` Michal Hocko
@ 2015-06-01 16:42     ` Vlastimil Babka
  0 siblings, 0 replies; 5+ messages in thread
From: Vlastimil Babka @ 2015-06-01 16:42 UTC (permalink / raw)
  To: Michal Hocko, Andrew Morton
  Cc: Vladimir Davydov, linux-mm, linux-kernel, Johannes Weiner

On 05/29/2015 08:55 AM, Michal Hocko wrote:
> On Thu 28-05-15 12:59:34, Andrew Morton wrote:
>> On Thu, 28 May 2015 20:26:06 +0300 Vladimir Davydov <vdavydov@parallels.com> wrote:
>> 
>> > When trimming memcg consumption excess (see memory.high), we call
>> > try_to_free_mem_cgroup_pages without checking if we are allowed to sleep
>> > in the current context, which can result in a deadlock. Fix this.
>> 
>> Why does it deadlock?  try_to_free_mem_cgroup_pages() is passed the
>> gfp_mask and should honour its __GFP_WAIT setting?
> 
> The only instance of __GFP_WAIT check in vmscan code is in zone_reclaim.
> Page allocations and memcg reclaim avoids calling reclaim if __GFP_WAIT
> is not set. Maybe we can move the check to do_try_to_free_pages?

I think it's conceptually wrong. All other paths check it before calling
into do_try_to_free_pages() and act appropriately. Here it would potentially
mask any atomic-specific fallback strategy.

What would make some sense in do_try_to_free_pages() is VM_WARN_ON_ONCE() which
however I assume doesn't exist? :)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-01 16:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-28 17:26 [PATCH] memcg: do not call reclaim if !__GFP_WAIT Vladimir Davydov
2015-05-28 18:13 ` Michal Hocko
2015-05-28 19:59 ` Andrew Morton
2015-05-29  6:55   ` Michal Hocko
2015-06-01 16:42     ` Vlastimil Babka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).