From: Miao Xie <miaox@cn.fujitsu.com>
To: David Rientjes <rientjes@google.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Paul Menage <paul@paulmenage.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [patch for-3.2-rc3] cpusets: stall when updating mems_allowed for mempolicy or disjoint nodemask
Date: Thu, 17 Nov 2011 16:29:55 +0800 [thread overview]
Message-ID: <4EC4C603.8050704@cn.fujitsu.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1111161307020.23629@chino.kir.corp.google.com>
On Wed, 16 Nov 2011 13:08:33 -0800 (pst), David Rientjes wrote:
> c0ff7453bb5c ("cpuset,mm: fix no node to alloc memory when changing
> cpuset's mems") adds get_mems_allowed() to prevent the set of allowed
> nodes from changing for a thread. This causes any update to a set of
> allowed nodes to stall until put_mems_allowed() is called.
>
> This stall is unncessary, however, if at least one node remains unchanged
> in the update to the set of allowed nodes. This was addressed by
> 89e8a244b97e ("cpusets: avoid looping when storing to mems_allowed if one
> node remains set"), but it's still possible that an empty nodemask may be
> read from a mempolicy because the old nodemask may be remapped to the new
> nodemask during rebind. To prevent this, only avoid the stall if there
> is no mempolicy for the thread being changed.
>
> This is a temporary solution until all reads from mempolicy nodemasks can
> be guaranteed to not be empty without the get_mems_allowed()
> synchronization.
>
> Also moves the check for nodemask intersection inside task_lock() so that
> tsk->mems_allowed cannot change.
>
> Reported-by: Miao Xie <miaox@cn.fujitsu.com>
> Signed-off-by: David Rientjes <rientjes@google.com>
Oh~, David
I find these is another problem, please take account of the following case:
2-3 -> 1-2 -> 0-1
the user change mems_allowed twice continuously, the task may see the empty
mems_allowed.
So, it is still dangerous.
Thanks
Miao
> ---
> kernel/cpuset.c | 17 +++++++++++------
> 1 files changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/kernel/cpuset.c b/kernel/cpuset.c
> --- a/kernel/cpuset.c
> +++ b/kernel/cpuset.c
> @@ -949,7 +949,7 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from,
> static void cpuset_change_task_nodemask(struct task_struct *tsk,
> nodemask_t *newmems)
> {
> - bool masks_disjoint = !nodes_intersects(*newmems, tsk->mems_allowed);
> + bool need_loop;
>
> repeat:
> /*
> @@ -962,6 +962,14 @@ repeat:
> return;
>
> task_lock(tsk);
> + /*
> + * Determine if a loop is necessary if another thread is doing
> + * get_mems_allowed(). If at least one node remains unchanged and
> + * tsk does not have a mempolicy, then an empty nodemask will not be
> + * possible when mems_allowed is larger than a word.
> + */
> + need_loop = tsk->mempolicy ||
> + !nodes_intersects(*newmems, tsk->mems_allowed);
> nodes_or(tsk->mems_allowed, tsk->mems_allowed, *newmems);
> mpol_rebind_task(tsk, newmems, MPOL_REBIND_STEP1);
>
> @@ -981,12 +989,9 @@ repeat:
>
> /*
> * Allocation of memory is very fast, we needn't sleep when waiting
> - * for the read-side. No wait is necessary, however, if at least one
> - * node remains unchanged and tsk has a mempolicy that could store an
> - * empty nodemask.
> + * for the read-side.
> */
> - while (masks_disjoint && tsk->mempolicy &&
> - ACCESS_ONCE(tsk->mems_allowed_change_disable)) {
> + while (need_loop && ACCESS_ONCE(tsk->mems_allowed_change_disable)) {
> task_unlock(tsk);
> if (!task_curr(tsk))
> yield();
>
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2011-11-17 8:31 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-16 21:08 [patch for-3.2-rc3] cpusets: stall when updating mems_allowed for mempolicy or disjoint nodemask David Rientjes
2011-11-17 8:29 ` Miao Xie [this message]
2011-11-17 21:33 ` David Rientjes
2011-11-18 9:52 ` Miao Xie
2011-11-18 23:49 ` David Rientjes
2011-11-23 2:51 ` Miao Xie
2011-11-23 3:32 ` David Rientjes
2011-11-23 4:48 ` Miao Xie
2011-11-23 6:25 ` David Rientjes
2011-11-23 7:49 ` Miao Xie
2011-11-23 22:26 ` David Rientjes
2011-11-24 1:26 ` Miao Xie
2011-11-24 1:52 ` David Rientjes
2011-11-24 2:50 ` Miao Xie
2011-11-17 22:22 ` Andrew Morton
2011-11-17 23:08 ` [patch v2 " David Rientjes
2011-11-18 0:00 ` Andrew Morton
2011-11-18 23:53 ` David Rientjes
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=4EC4C603.8050704@cn.fujitsu.com \
--to=miaox@cn.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=paul@paulmenage.org \
--cc=rientjes@google.com \
--cc=torvalds@linux-foundation.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 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).