All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov@tarantool.org>
To: Balbir Singh <bsingharora@gmail.com>
Cc: mpe@ellerman.id.au, hannes@cmpxchg.org, mhocko@kernel.org,
	linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org,
	Tejun Heo <tj@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [RESEND] [PATCH v1 1/3] Add basic infrastructure for memcg hotplug support
Date: Mon, 21 Nov 2016 11:36:16 +0300	[thread overview]
Message-ID: <20161121083616.GC18431@esperanza> (raw)
In-Reply-To: <3accc533-8dda-a69c-fabc-23eb388cf11b@gmail.com>

On Thu, Nov 17, 2016 at 11:28:12AM +1100, Balbir Singh wrote:
> >> @@ -5773,6 +5771,59 @@ static int __init cgroup_memory(char *s)
> >>  }
> >>  __setup("cgroup.memory=", cgroup_memory);
> >>  
> >> +static void memcg_node_offline(int node)
> >> +{
> >> +	struct mem_cgroup *memcg;
> >> +
> >> +	if (node < 0)
> >> +		return;
> > 
> > Is this possible?
> 
> Yes, please see node_states_check_changes_online/offline

OK, I see.

> 
> > 
> >> +
> >> +	for_each_mem_cgroup(memcg) {
> >> +		free_mem_cgroup_per_node_info(memcg, node);
> >> +		mem_cgroup_may_update_nodemask(memcg);
> > 
> > If memcg->numainfo_events is 0, mem_cgroup_may_update_nodemask() won't
> > update memcg->scan_nodes. Is it OK?
> > 
> >> +	}
> > 
> > What if a memory cgroup is created or destroyed while you're walking the
> > tree? Should we probably use get_online_mems() in mem_cgroup_alloc() to
> > avoid that?
> > 
> 
> The iterator internally takes rcu_read_lock() to avoid any side-effects
> of cgroups added/removed. I suspect you are also suggesting using get_online_mems()
> around each call to for_each_online_node
> 
> My understanding so far is
> 
> 1. invalidate_reclaim_iterators should be safe (no bad side-effects)
> 2. mem_cgroup_free - should be safe as well
> 3. mem_cgroup_alloc - needs protection
> 4. mem_cgroup_init - needs protection
> 5. mem_cgroup_remove_from_tress - should be safe

I'm not into the memory hotplug code, but my understanding is that if
memcg offline happens to race with node unplug, it's possible that

 - mem_cgroup_free() doesn't free the node's data, because it sees the
   node as already offline
 - memcg hotplug code doesn't free the node's data either, because it
   sees the cgroup as offline

May be, we should surround all the loops over online nodes with
get/put_online_mems() to be sure that nothing wrong can happen.
They are slow path, anyway.

Thanks,
Vladimir

WARNING: multiple messages have this Message-ID (diff)
From: Vladimir Davydov <vdavydov@tarantool.org>
To: Balbir Singh <bsingharora@gmail.com>
Cc: mpe@ellerman.id.au, hannes@cmpxchg.org, mhocko@kernel.org,
	linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org,
	Tejun Heo <tj@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [RESEND] [PATCH v1 1/3] Add basic infrastructure for memcg hotplug support
Date: Mon, 21 Nov 2016 11:36:16 +0300	[thread overview]
Message-ID: <20161121083616.GC18431@esperanza> (raw)
In-Reply-To: <3accc533-8dda-a69c-fabc-23eb388cf11b@gmail.com>

On Thu, Nov 17, 2016 at 11:28:12AM +1100, Balbir Singh wrote:
> >> @@ -5773,6 +5771,59 @@ static int __init cgroup_memory(char *s)
> >>  }
> >>  __setup("cgroup.memory=", cgroup_memory);
> >>  
> >> +static void memcg_node_offline(int node)
> >> +{
> >> +	struct mem_cgroup *memcg;
> >> +
> >> +	if (node < 0)
> >> +		return;
> > 
> > Is this possible?
> 
> Yes, please see node_states_check_changes_online/offline

OK, I see.

> 
> > 
> >> +
> >> +	for_each_mem_cgroup(memcg) {
> >> +		free_mem_cgroup_per_node_info(memcg, node);
> >> +		mem_cgroup_may_update_nodemask(memcg);
> > 
> > If memcg->numainfo_events is 0, mem_cgroup_may_update_nodemask() won't
> > update memcg->scan_nodes. Is it OK?
> > 
> >> +	}
> > 
> > What if a memory cgroup is created or destroyed while you're walking the
> > tree? Should we probably use get_online_mems() in mem_cgroup_alloc() to
> > avoid that?
> > 
> 
> The iterator internally takes rcu_read_lock() to avoid any side-effects
> of cgroups added/removed. I suspect you are also suggesting using get_online_mems()
> around each call to for_each_online_node
> 
> My understanding so far is
> 
> 1. invalidate_reclaim_iterators should be safe (no bad side-effects)
> 2. mem_cgroup_free - should be safe as well
> 3. mem_cgroup_alloc - needs protection
> 4. mem_cgroup_init - needs protection
> 5. mem_cgroup_remove_from_tress - should be safe

I'm not into the memory hotplug code, but my understanding is that if
memcg offline happens to race with node unplug, it's possible that

 - mem_cgroup_free() doesn't free the node's data, because it sees the
   node as already offline
 - memcg hotplug code doesn't free the node's data either, because it
   sees the cgroup as offline

May be, we should surround all the loops over online nodes with
get/put_online_mems() to be sure that nothing wrong can happen.
They are slow path, anyway.

Thanks,
Vladimir

--
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>

  reply	other threads:[~2016-11-21  9:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-15 23:44 [RESEND][v1 0/3] Support memory cgroup hotplug Balbir Singh
2016-11-15 23:44 ` Balbir Singh
2016-11-15 23:44 ` [RESEND] [PATCH v1 1/3] Add basic infrastructure for memcg hotplug support Balbir Singh
2016-11-15 23:44   ` Balbir Singh
2016-11-16  9:01   ` Vladimir Davydov
2016-11-16  9:01     ` Vladimir Davydov
2016-11-17  0:28     ` Balbir Singh
2016-11-17  0:28       ` Balbir Singh
2016-11-21  8:36       ` Vladimir Davydov [this message]
2016-11-21  8:36         ` Vladimir Davydov
2016-11-22  0:17         ` Balbir Singh
2016-11-22  0:17           ` Balbir Singh
2016-11-15 23:45 ` [RESEND] [PATCH v1 2/3] Move from all possible nodes to online nodes Balbir Singh
2016-11-15 23:45   ` Balbir Singh
2016-11-15 23:45 ` [RESEND] [PATCH v1 3/3] powerpc: fix node_possible_map limitations Balbir Singh
2016-11-15 23:45   ` Balbir Singh
2016-11-16 16:40   ` Reza Arbab
2016-11-16 16:40     ` Reza Arbab
2016-11-16 16:45     ` [PATCH] powerpc/mm: allow memory hotplug into an offline node Reza Arbab
2016-11-16 16:45       ` Reza Arbab
2017-02-01  1:05       ` Michael Ellerman
2017-02-01  1:05         ` Michael Ellerman
2016-11-21 14:03 ` [RESEND][v1 0/3] Support memory cgroup hotplug Michal Hocko
2016-11-21 14:03   ` Michal Hocko
2016-11-22  0:16   ` Balbir Singh
2016-11-22  0:16     ` Balbir Singh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161121083616.GC18431@esperanza \
    --to=vdavydov@tarantool.org \
    --cc=akpm@linux-foundation.org \
    --cc=bsingharora@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mhocko@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.