All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] mmotm: cpusetmm-update-tasks-mems_allowed-in-time-fix
@ 2009-04-28 18:14 Lee Schermerhorn
  2009-04-28 18:14 ` [PATCH 2/2] mmotm: cpusetmm-update-tasks-mems_allowed-in-time-cleanup Lee Schermerhorn
  0 siblings, 1 reply; 3+ messages in thread
From: Lee Schermerhorn @ 2009-04-28 18:14 UTC (permalink / raw)
  To: linux-mm; +Cc: linux-numa, eric.whitney, Andrew Morton, Miao Xie

PATCH 1/2 cpusetmm-update-tasks-mems_allowed-in-time-fix

[forgot linux-mm in previous send.  sorry for repeat.  at least
it's only two patches...]

Against: 2.6.30-rc3-mmotm-090424-1814

The rework of mpol_new() to extract the adjusting of the node mask
to apply cpuset and mpol flags "context" breaks set_mempolicy() and
mbind() with MPOL_PREFERRED and a NULL nodemask--i.e., explicit local
allocation.  Fix this by adding the check for MPOL_PREFERRED and
empty node mask to mpol_new_mpolicy().

Remove the now unneeded 'nodes = NULL' from mpol_new().

Note that mpol_new_mempolicy() is always called with a non-NULL
'nodes' parameter now that it has been removed from mpol_new().
Therefore, we don't need to test nodes for NULL before testing
it for 'empty'.  However, just to be extra paranoid, add a 
VM_BUG_ON() to verify this assumption.

Tested on x86_64 with numactl-2.0.3-rc2+ regression test.

Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com>

 mm/mempolicy.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Index: linux-2.6.30-rc3-mmotm-090424-1814/mm/mempolicy.c
===================================================================
--- linux-2.6.30-rc3-mmotm-090424-1814.orig/mm/mempolicy.c	2009-04-27 13:42:53.000000000 -0400
+++ linux-2.6.30-rc3-mmotm-090424-1814/mm/mempolicy.c	2009-04-28 13:32:32.000000000 -0400
@@ -182,8 +182,9 @@ static int mpol_new_bind(struct mempolic
 	return 0;
 }
 /*
- * This function is called after mpol_new(). The parameter -- nodes needn't
- * been check because mpol_new() has done it. Maybe this implement is ugly.
+ * This function is called after mpol_new().  mpol_new() has already validated
+ * the nodes parameter with respect to the policy mode and flags.  But, we
+ * need to handle an empty nodemaks with MPOL_PREFERRED here.
  *
  * We use task's alloc_lock to protect task's mems_allowed and mempolicy.
  * so this function should be called with task's alloc_lock held.
@@ -197,7 +198,10 @@ static int mpol_new_mempolicy(struct mem
 	if (pol == NULL)
 		return 0;
 
-	if (nodes) {
+	VM_BUG_ON(!nodes);
+	if (pol->mode == MPOL_PREFERRED && nodes_empty(*nodes))
+		nodes = NULL;	/* explicit local allocation */
+	else {
 		if (pol->flags & MPOL_F_RELATIVE_NODES)
 			mpol_relative_nodemask(&cpuset_context_nmask, nodes,
 					       &cpuset_current_mems_allowed);
@@ -243,7 +247,6 @@ static struct mempolicy *mpol_new(unsign
 			if (((flags & MPOL_F_STATIC_NODES) ||
 			     (flags & MPOL_F_RELATIVE_NODES)))
 				return ERR_PTR(-EINVAL);
-			nodes = NULL;	/* flag local alloc */
 		}
 	} else if (nodes_empty(*nodes))
 		return ERR_PTR(-EINVAL);

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

* [PATCH 2/2] mmotm: cpusetmm-update-tasks-mems_allowed-in-time-cleanup
  2009-04-28 18:14 [PATCH 1/2] mmotm: cpusetmm-update-tasks-mems_allowed-in-time-fix Lee Schermerhorn
@ 2009-04-28 18:14 ` Lee Schermerhorn
  0 siblings, 0 replies; 3+ messages in thread
From: Lee Schermerhorn @ 2009-04-28 18:14 UTC (permalink / raw)
  To: linux-mm; +Cc: linux-numa, eric.whitney, Andrew Morton, Miao Xie

PATCH 2/2  cpusetmm-update-tasks-mems_allowed-in-time-cleanup

Against: 2.6.30-rc3-mmotm-090424-1814

I don't think the function name 'mpol_new_mempolicy' is
descriptive enough to differentiate it from mpol_new().

This function applies cpuset set context, usually constraining
nodes to those allowed by the cpuset.  However, when the
'RELATIVE_NODES flag is set, it also translates the nodes.
So I settled on 'mpol_set_nodemask()', because the comment block
for mpol_new() mentions that we need to call this function to
"set nodes".

Some additional minor line length, whitespace and typo cleanup.

Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com>

 mm/mempolicy.c |   28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

Index: linux-2.6.30-rc3-mmotm-090424-1814/mm/mempolicy.c
===================================================================
--- linux-2.6.30-rc3-mmotm-090424-1814.orig/mm/mempolicy.c	2009-04-28 13:32:32.000000000 -0400
+++ linux-2.6.30-rc3-mmotm-090424-1814/mm/mempolicy.c	2009-04-28 13:35:33.000000000 -0400
@@ -181,15 +181,17 @@ static int mpol_new_bind(struct mempolic
 	pol->v.nodes = *nodes;
 	return 0;
 }
+
 /*
- * This function is called after mpol_new().  mpol_new() has already validated
- * the nodes parameter with respect to the policy mode and flags.  But, we
- * need to handle an empty nodemaks with MPOL_PREFERRED here.
+ * mpol_set_nodemask is called after mpol_new() to set up the nodemask, if
+ * any, for the new policy.  mpol_new() has already validated the nodes
+ * parameter with respect to the policy mode and flags.  But, we need to
+ * handle an empty nodemask with MPOL_PREFERRED here.
  *
- * We use task's alloc_lock to protect task's mems_allowed and mempolicy.
- * so this function should be called with task's alloc_lock held.
+ * Must be called holding task's alloc_lock to protect task's mems_allowed
+ * and mempolicy.  May also be called holding the mmap_semaphore for write.
  */
-static int mpol_new_mempolicy(struct mempolicy *pol, const nodemask_t *nodes)
+static int mpol_set_nodemask(struct mempolicy *pol, const nodemask_t *nodes)
 {
 	nodemask_t cpuset_context_nmask;
 	int ret;
@@ -220,8 +222,10 @@ static int mpol_new_mempolicy(struct mem
 	return ret;
 }
 
-/* This function just creates a new policy, does some check and simple
- * initializtion. You must invoke mpol_new_mempolicy to set nodes */
+/*
+ * This function just creates a new policy, does some check and simple
+ * initialization. You must invoke mpol_set_nodemask() to set nodes.
+ */
 static struct mempolicy *mpol_new(unsigned short mode, unsigned short flags,
 				  nodemask_t *nodes)
 {
@@ -631,7 +635,7 @@ static long do_set_mempolicy(unsigned sh
 	if (mm)
 		down_write(&mm->mmap_sem);
 	task_lock(current);
-	ret = mpol_new_mempolicy(new, nodes);
+	ret = mpol_set_nodemask(new, nodes);
 	if (ret) {
 		task_unlock(current);
 		if (mm)
@@ -1012,7 +1016,7 @@ static long do_mbind(unsigned long start
 	}
 	down_write(&mm->mmap_sem);
 	task_lock(current);
-	err = mpol_new_mempolicy(new, nmask);
+	err = mpol_set_nodemask(new, nmask);
 	task_unlock(current);
 	if (err) {
 		up_write(&mm->mmap_sem);
@@ -1907,7 +1911,7 @@ void mpol_shared_policy_init(struct shar
 		}
 
 		task_lock(current);
-		ret = mpol_new_mempolicy(new, &mpol->w.user_nodemask);
+		ret = mpol_set_nodemask(new, &mpol->w.user_nodemask);
 		task_unlock(current);
 		mpol_put(mpol);	/* drop our ref on sb mpol */
 		if (ret) {
@@ -2138,7 +2142,7 @@ int mpol_parse_str(char *str, struct mem
 		int ret;
 
 		task_lock(current);
-		ret = mpol_new_mempolicy(new, &nodes);
+		ret = mpol_set_nodemask(new, &nodes);
 		task_unlock(current);
 		if (ret)
 			err = 1;

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

* [PATCH 2/2] mmotm: cpusetmm-update-tasks-mems_allowed-in-time-cleanup
  2009-04-28 18:02 [PATCH 1/2] mmotm: cpusetmm-update-tasks-mems_allowed-in-time-fix Lee Schermerhorn
@ 2009-04-28 18:02 ` Lee Schermerhorn
  0 siblings, 0 replies; 3+ messages in thread
From: Lee Schermerhorn @ 2009-04-28 18:02 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-numa, eric.whitney, Miao Xie

PATCH 2/2  cpusetmm-update-tasks-mems_allowed-in-time-cleanup

Against: 2.6.30-rc3-mmotm-090424-1814

I don't think the function name 'mpol_new_mempolicy' is
descriptive enough to differentiate it from mpol_new().

This function applies cpuset set context, usually constraining
nodes to those allowed by the cpuset.  However, when the
'RELATIVE_NODES flag is set, it also translates the nodes.
So I settled on 'mpol_set_nodemask()', because the comment block
for mpol_new() mentions that we need to call this function to
"set nodes".

Some additional minor line length, whitespace and typo cleanup.

Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com>

 mm/mempolicy.c |   28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

Index: linux-2.6.30-rc3-mmotm-090424-1814/mm/mempolicy.c
===================================================================
--- linux-2.6.30-rc3-mmotm-090424-1814.orig/mm/mempolicy.c	2009-04-28 13:32:32.000000000 -0400
+++ linux-2.6.30-rc3-mmotm-090424-1814/mm/mempolicy.c	2009-04-28 13:35:33.000000000 -0400
@@ -181,15 +181,17 @@ static int mpol_new_bind(struct mempolic
 	pol->v.nodes = *nodes;
 	return 0;
 }
+
 /*
- * This function is called after mpol_new().  mpol_new() has already validated
- * the nodes parameter with respect to the policy mode and flags.  But, we
- * need to handle an empty nodemaks with MPOL_PREFERRED here.
+ * mpol_set_nodemask is called after mpol_new() to set up the nodemask, if
+ * any, for the new policy.  mpol_new() has already validated the nodes
+ * parameter with respect to the policy mode and flags.  But, we need to
+ * handle an empty nodemask with MPOL_PREFERRED here.
  *
- * We use task's alloc_lock to protect task's mems_allowed and mempolicy.
- * so this function should be called with task's alloc_lock held.
+ * Must be called holding task's alloc_lock to protect task's mems_allowed
+ * and mempolicy.  May also be called holding the mmap_semaphore for write.
  */
-static int mpol_new_mempolicy(struct mempolicy *pol, const nodemask_t *nodes)
+static int mpol_set_nodemask(struct mempolicy *pol, const nodemask_t *nodes)
 {
 	nodemask_t cpuset_context_nmask;
 	int ret;
@@ -220,8 +222,10 @@ static int mpol_new_mempolicy(struct mem
 	return ret;
 }
 
-/* This function just creates a new policy, does some check and simple
- * initializtion. You must invoke mpol_new_mempolicy to set nodes */
+/*
+ * This function just creates a new policy, does some check and simple
+ * initialization. You must invoke mpol_set_nodemask() to set nodes.
+ */
 static struct mempolicy *mpol_new(unsigned short mode, unsigned short flags,
 				  nodemask_t *nodes)
 {
@@ -631,7 +635,7 @@ static long do_set_mempolicy(unsigned sh
 	if (mm)
 		down_write(&mm->mmap_sem);
 	task_lock(current);
-	ret = mpol_new_mempolicy(new, nodes);
+	ret = mpol_set_nodemask(new, nodes);
 	if (ret) {
 		task_unlock(current);
 		if (mm)
@@ -1012,7 +1016,7 @@ static long do_mbind(unsigned long start
 	}
 	down_write(&mm->mmap_sem);
 	task_lock(current);
-	err = mpol_new_mempolicy(new, nmask);
+	err = mpol_set_nodemask(new, nmask);
 	task_unlock(current);
 	if (err) {
 		up_write(&mm->mmap_sem);
@@ -1907,7 +1911,7 @@ void mpol_shared_policy_init(struct shar
 		}
 
 		task_lock(current);
-		ret = mpol_new_mempolicy(new, &mpol->w.user_nodemask);
+		ret = mpol_set_nodemask(new, &mpol->w.user_nodemask);
 		task_unlock(current);
 		mpol_put(mpol);	/* drop our ref on sb mpol */
 		if (ret) {
@@ -2138,7 +2142,7 @@ int mpol_parse_str(char *str, struct mem
 		int ret;
 
 		task_lock(current);
-		ret = mpol_new_mempolicy(new, &nodes);
+		ret = mpol_set_nodemask(new, &nodes);
 		task_unlock(current);
 		if (ret)
 			err = 1;

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

end of thread, other threads:[~2009-04-28 18:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-28 18:14 [PATCH 1/2] mmotm: cpusetmm-update-tasks-mems_allowed-in-time-fix Lee Schermerhorn
2009-04-28 18:14 ` [PATCH 2/2] mmotm: cpusetmm-update-tasks-mems_allowed-in-time-cleanup Lee Schermerhorn
  -- strict thread matches above, loose matches on Subject: below --
2009-04-28 18:02 [PATCH 1/2] mmotm: cpusetmm-update-tasks-mems_allowed-in-time-fix Lee Schermerhorn
2009-04-28 18:02 ` [PATCH 2/2] mmotm: cpusetmm-update-tasks-mems_allowed-in-time-cleanup Lee Schermerhorn

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.