From: Miao Xie <miaox@cn.fujitsu.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Rientjes <rientjes@google.com>,
Lee Schermerhorn <lee.schermerhorn@hp.com>,
Nick Piggin <npiggin@suse.de>, Paul Menage <menage@google.com>,
Linux-Kernel <linux-kernel@vger.kernel.org>,
Linux-MM <linux-mm@kvack.org>
Subject: Re: [PATCH 4/4] cpuset,mm: use rwlock to protect task->mempolicy and mems_allowed
Date: Thu, 04 Mar 2010 17:03:20 +0800 [thread overview]
Message-ID: <4B8F7758.9020500@cn.fujitsu.com> (raw)
In-Reply-To: <20100303155004.5f9e793e.akpm@linux-foundation.org>
on 2010-3-4 7:50, Andrew Morton wrote:
> On Wed, 03 Mar 2010 18:52:39 +0800
> Miao Xie <miaox@cn.fujitsu.com> wrote:
>
>> if MAX_NUMNODES > BITS_PER_LONG, loading/storing task->mems_allowed or mems_allowed in
>> task->mempolicy are not atomic operations, and the kernel page allocator gets an empty
>> mems_allowed when updating task->mems_allowed or mems_allowed in task->mempolicy. So we
>> use a rwlock to protect them to fix this probelm.
>
> Boy, that is one big ugly patch. Is there no other way of doing this?
Let me consider!
>
>>
>> ...
>>
>> --- a/include/linux/mempolicy.h
>> +++ b/include/linux/mempolicy.h
>> @@ -51,6 +51,7 @@ enum {
>> */
>> #define MPOL_F_SHARED (1 << 0) /* identify shared policies */
>> #define MPOL_F_LOCAL (1 << 1) /* preferred local allocation */
>> +#define MPOL_F_TASK (1 << 2) /* identify tasks' policies */
>
> What's this? It wasn't mentioned in the changelog - I suspect it
> should have been?
I hope task->mempolicy has the same get/put operation just like shared mempolicy,
this new feature is used when the kernel memory allocater accesses
task->mempolicy.
I'll rewrite the changelog in the next version of the patch if I still
use this flag.
>> +int cpuset_mems_allowed_intersects(struct task_struct *tsk1,
>> + struct task_struct *tsk2)
>> {
>> - return nodes_intersects(tsk1->mems_allowed, tsk2->mems_allowed);
>> + unsigned long flags1, flags2;
>> + int retval;
>> +
>> + read_mem_lock_irqsave(tsk1, flags1);
>> + read_mem_lock_irqsave(tsk2, flags2);
>> + retval = nodes_intersects(tsk1->mems_allowed, tsk2->mems_allowed);
>> + read_mem_unlock_irqrestore(tsk2, flags2);
>> + read_mem_unlock_irqrestore(tsk1, flags1);
>
> I suspect this is deadlockable in sufficiently arcane circumstances:
> one task takes the locks in a,b order, another task takes them in b,a
> order and a third task gets in at the right time and does a
> write_lock(). Probably that's not possible for some reason, dunno. The usual
> way of solving this is to always take the locks in
> sorted-by-ascending-virtual-address order.
Don't worry about this problem, because rwlock is read_preference lock.
But your advice is very good, I'll change it in the next version of the patch.
Thanks!
>
>
>
>
>
WARNING: multiple messages have this Message-ID (diff)
From: Miao Xie <miaox@cn.fujitsu.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: David Rientjes <rientjes@google.com>,
Lee Schermerhorn <lee.schermerhorn@hp.com>,
Nick Piggin <npiggin@suse.de>, Paul Menage <menage@google.com>,
Linux-Kernel <linux-kernel@vger.kernel.org>,
Linux-MM <linux-mm@kvack.org>
Subject: Re: [PATCH 4/4] cpuset,mm: use rwlock to protect task->mempolicy and mems_allowed
Date: Thu, 04 Mar 2010 17:03:20 +0800 [thread overview]
Message-ID: <4B8F7758.9020500@cn.fujitsu.com> (raw)
In-Reply-To: <20100303155004.5f9e793e.akpm@linux-foundation.org>
on 2010-3-4 7:50, Andrew Morton wrote:
> On Wed, 03 Mar 2010 18:52:39 +0800
> Miao Xie <miaox@cn.fujitsu.com> wrote:
>
>> if MAX_NUMNODES > BITS_PER_LONG, loading/storing task->mems_allowed or mems_allowed in
>> task->mempolicy are not atomic operations, and the kernel page allocator gets an empty
>> mems_allowed when updating task->mems_allowed or mems_allowed in task->mempolicy. So we
>> use a rwlock to protect them to fix this probelm.
>
> Boy, that is one big ugly patch. Is there no other way of doing this?
Let me consider!
>
>>
>> ...
>>
>> --- a/include/linux/mempolicy.h
>> +++ b/include/linux/mempolicy.h
>> @@ -51,6 +51,7 @@ enum {
>> */
>> #define MPOL_F_SHARED (1 << 0) /* identify shared policies */
>> #define MPOL_F_LOCAL (1 << 1) /* preferred local allocation */
>> +#define MPOL_F_TASK (1 << 2) /* identify tasks' policies */
>
> What's this? It wasn't mentioned in the changelog - I suspect it
> should have been?
I hope task->mempolicy has the same get/put operation just like shared mempolicy,
this new feature is used when the kernel memory allocater accesses
task->mempolicy.
I'll rewrite the changelog in the next version of the patch if I still
use this flag.
>> +int cpuset_mems_allowed_intersects(struct task_struct *tsk1,
>> + struct task_struct *tsk2)
>> {
>> - return nodes_intersects(tsk1->mems_allowed, tsk2->mems_allowed);
>> + unsigned long flags1, flags2;
>> + int retval;
>> +
>> + read_mem_lock_irqsave(tsk1, flags1);
>> + read_mem_lock_irqsave(tsk2, flags2);
>> + retval = nodes_intersects(tsk1->mems_allowed, tsk2->mems_allowed);
>> + read_mem_unlock_irqrestore(tsk2, flags2);
>> + read_mem_unlock_irqrestore(tsk1, flags1);
>
> I suspect this is deadlockable in sufficiently arcane circumstances:
> one task takes the locks in a,b order, another task takes them in b,a
> order and a third task gets in at the right time and does a
> write_lock(). Probably that's not possible for some reason, dunno. The usual
> way of solving this is to always take the locks in
> sorted-by-ascending-virtual-address order.
Don't worry about this problem, because rwlock is read_preference lock.
But your advice is very good, I'll change it in the next version of the patch.
Thanks!
>
>
>
>
>
--
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>
next prev parent reply other threads:[~2010-03-04 9:03 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-03 10:52 [PATCH 4/4] cpuset,mm: use rwlock to protect task->mempolicy and mems_allowed Miao Xie
2010-03-03 10:52 ` Miao Xie
2010-03-03 23:50 ` Andrew Morton
2010-03-03 23:50 ` Andrew Morton
2010-03-04 9:03 ` Miao Xie [this message]
2010-03-04 9:03 ` Miao Xie
2010-03-04 3:30 ` Nick Piggin
2010-03-04 3:30 ` Nick Piggin
2010-03-04 9:36 ` Miao Xie
2010-03-04 9:36 ` Miao Xie
2010-03-04 14:58 ` Peter Zijlstra
2010-03-04 14:58 ` Peter Zijlstra
2010-03-04 16:34 ` Nick Piggin
2010-03-04 16:34 ` Nick Piggin
2010-03-04 4:53 ` Nick Piggin
2010-03-04 4:53 ` Nick Piggin
2010-03-04 14:31 ` Lee Schermerhorn
2010-03-04 14:31 ` Lee Schermerhorn
2010-03-05 13:05 ` Lee Schermerhorn
2010-03-05 13:05 ` Lee Schermerhorn
2010-03-05 12:03 ` Paul Menage
2010-03-05 12:03 ` Paul Menage
2010-03-07 2:33 ` Miao Xie
2010-03-07 2:33 ` Miao Xie
2010-03-09 19:42 ` Paul Menage
2010-03-09 19:42 ` Paul Menage
2010-03-11 5:04 ` Miao Xie
2010-03-11 5:04 ` Miao Xie
2010-03-11 5:30 ` Nick Piggin
2010-03-11 5:30 ` Nick Piggin
2010-03-11 7:57 ` Miao Xie
2010-03-11 7:57 ` Miao Xie
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=4B8F7758.9020500@cn.fujitsu.com \
--to=miaox@cn.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=lee.schermerhorn@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=menage@google.com \
--cc=npiggin@suse.de \
--cc=rientjes@google.com \
/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.