All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm, memcg: don't protect pages if memcg is not populated
@ 2019-11-23  5:56 Yafang Shao
  2019-11-25  8:14 ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: Yafang Shao @ 2019-11-23  5:56 UTC (permalink / raw)
  To: mhocko, hannes, vdavydov.dev, akpm; +Cc: linux-mm, Yafang Shao

memory.{min, low} keeps protecting pages in a memcg even if there're no
process running in this memcg. That makes nonsense, because if there're
no processes running in this memcg there may be something wrong happens
and these protected pages are not useful now.

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
---
 mm/memcontrol.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 1c4c08b..c96c282 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -6376,6 +6376,9 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root,
 	if (memcg == root)
 		return MEMCG_PROT_NONE;
 
+	if (!cgroup_is_populated(memcg->css.cgroup))
+		return MEMCG_PROT_NONE;
+
 	usage = page_counter_read(&memcg->memory);
 	if (!usage)
 		return MEMCG_PROT_NONE;
-- 
1.8.3.1



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

* Re: [PATCH] mm, memcg: don't protect pages if memcg is not populated
  2019-11-23  5:56 [PATCH] mm, memcg: don't protect pages if memcg is not populated Yafang Shao
@ 2019-11-25  8:14 ` Michal Hocko
  2019-11-25  9:11   ` Yafang Shao
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Hocko @ 2019-11-25  8:14 UTC (permalink / raw)
  To: Yafang Shao; +Cc: hannes, vdavydov.dev, akpm, linux-mm

On Sat 23-11-19 00:56:42, Yafang Shao wrote:
> memory.{min, low} keeps protecting pages in a memcg even if there're no
> process running in this memcg. That makes nonsense, because if there're
> no processes running in this memcg there may be something wrong happens
> and these protected pages are not useful now.

Well, the min resp. low limits protect charges rather than tasks. And
thre are cases when there is no direct relation between the charged
memory and a specific task - e.g. long living kernel objects or page
cache. So there is nothing really unusual to have charges in an absence
of any tasks. I do not really see any reason why the protection
shouldn't apply to them. Such a be behavior would be quite inconsistent
btw. Just imagine a case when there is _a_ task but that one doesn't
really have any charges in the memcg. Why should we respect reclaim
protection in that case?

Btw. offlined memcgs already have no min/low watermarks protect.

Do you have any specific usecase that suffers from this behavior?
 
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> ---
>  mm/memcontrol.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> index 1c4c08b..c96c282 100644
> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -6376,6 +6376,9 @@ enum mem_cgroup_protection mem_cgroup_protected(struct mem_cgroup *root,
>  	if (memcg == root)
>  		return MEMCG_PROT_NONE;
>  
> +	if (!cgroup_is_populated(memcg->css.cgroup))
> +		return MEMCG_PROT_NONE;
> +
>  	usage = page_counter_read(&memcg->memory);
>  	if (!usage)
>  		return MEMCG_PROT_NONE;
> -- 
> 1.8.3.1

-- 
Michal Hocko
SUSE Labs


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

* Re: [PATCH] mm, memcg: don't protect pages if memcg is not populated
  2019-11-25  8:14 ` Michal Hocko
@ 2019-11-25  9:11   ` Yafang Shao
  2019-11-25  9:38     ` Michal Hocko
  0 siblings, 1 reply; 4+ messages in thread
From: Yafang Shao @ 2019-11-25  9:11 UTC (permalink / raw)
  To: Michal Hocko; +Cc: Johannes Weiner, Vladimir Davydov, Andrew Morton, Linux MM

On Mon, Nov 25, 2019 at 4:14 PM Michal Hocko <mhocko@kernel.org> wrote:
>
> On Sat 23-11-19 00:56:42, Yafang Shao wrote:
> > memory.{min, low} keeps protecting pages in a memcg even if there're no
> > process running in this memcg. That makes nonsense, because if there're
> > no processes running in this memcg there may be something wrong happens
> > and these protected pages are not useful now.
>
> Well, the min resp. low limits protect charges rather than tasks. And
> thre are cases when there is no direct relation between the charged
> memory and a specific task - e.g. long living kernel objects or page
> cache. So there is nothing really unusual to have charges in an absence
> of any tasks. I do not really see any reason why the protection
> shouldn't apply to them. Such a be behavior would be quite inconsistent
> btw. Just imagine a case when there is _a_ task but that one doesn't
> really have any charges in the memcg. Why should we respect reclaim
> protection in that case?
>

Per my understanding, the memory.{min, low} is used to protect the workload.
I don't know in which cases we protect the 'content' only.

If one memcg is used to protect the content only, e.g. some file
caches, then these file caches will be shared by processes in
different memcgs,  that may cause some unexpected issues, for example,
how to handle the writeback throttle ?

I don't know how to use memory.{min, low} to protect long living
kernel objects neither without any processes.

I would appreciate if you could explain my questions in detail.

> Btw. offlined memcgs already have no min/low watermarks protect.
>
> Do you have any specific usecase that suffers from this behavior?
>

For example, if oom happens, the processes in this memcg may be killed
by OOM killer, and if memory.oom.group is set, all processes in it
will be killed. So these protected pages are useless.  In that cases,
we should clear memory.{min, low} protection.

Thanks
Yafang


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

* Re: [PATCH] mm, memcg: don't protect pages if memcg is not populated
  2019-11-25  9:11   ` Yafang Shao
@ 2019-11-25  9:38     ` Michal Hocko
  0 siblings, 0 replies; 4+ messages in thread
From: Michal Hocko @ 2019-11-25  9:38 UTC (permalink / raw)
  To: Yafang Shao; +Cc: Johannes Weiner, Vladimir Davydov, Andrew Morton, Linux MM

On Mon 25-11-19 17:11:14, Yafang Shao wrote:
> On Mon, Nov 25, 2019 at 4:14 PM Michal Hocko <mhocko@kernel.org> wrote:
> >
> > On Sat 23-11-19 00:56:42, Yafang Shao wrote:
> > > memory.{min, low} keeps protecting pages in a memcg even if there're no
> > > process running in this memcg. That makes nonsense, because if there're
> > > no processes running in this memcg there may be something wrong happens
> > > and these protected pages are not useful now.
> >
> > Well, the min resp. low limits protect charges rather than tasks. And
> > thre are cases when there is no direct relation between the charged
> > memory and a specific task - e.g. long living kernel objects or page
> > cache. So there is nothing really unusual to have charges in an absence
> > of any tasks. I do not really see any reason why the protection
> > shouldn't apply to them. Such a be behavior would be quite inconsistent
> > btw. Just imagine a case when there is _a_ task but that one doesn't
> > really have any charges in the memcg. Why should we respect reclaim
> > protection in that case?
> >
> 
> Per my understanding, the memory.{min, low} is used to protect the workload.
> I don't know in which cases we protect the 'content' only.

I didn't say anything about the content. You are right that those limits
are protecting a working set. I do not think it would be hard to imagine
a workload which has a page cache to be the working set and want to
protect it while tasks are only very short lived and so "no tasks" state
wouldn't be all that unusual.

> If one memcg is used to protect the content only, e.g. some file
> caches, then these file caches will be shared by processes in
> different memcgs,  that may cause some unexpected issues, for example,
> how to handle the writeback throttle ?

Yes, sharing might lead to surprising behavior but I do not not
understand how this is really related to the proposed patch.

> I don't know how to use memory.{min, low} to protect long living
> kernel objects neither without any processes.
> 
> I would appreciate if you could explain my questions in detail.

See the example above.

> > Btw. offlined memcgs already have no min/low watermarks protect.
> >
> > Do you have any specific usecase that suffers from this behavior?
> >
> 
> For example, if oom happens, the processes in this memcg may be killed
> by OOM killer, and if memory.oom.group is set, all processes in it
> will be killed. So these protected pages are useless.  In that cases,
> we should clear memory.{min, low} protection.

I do agree that the reclaim protection might lead to an unexpected OOM
handling. Especially when charged objects are not directly bound to the
process life time. But this patch is not going to help here in general.
One has to be really careful when configuring the protection. It is a
hard guarantee after all.
-- 
Michal Hocko
SUSE Labs


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

end of thread, other threads:[~2019-11-25  9:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-23  5:56 [PATCH] mm, memcg: don't protect pages if memcg is not populated Yafang Shao
2019-11-25  8:14 ` Michal Hocko
2019-11-25  9:11   ` Yafang Shao
2019-11-25  9:38     ` Michal Hocko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.