linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mempolicy: reduce stack size of migrate_pages()
@ 2010-06-16  4:36 KOSAKI Motohiro
  2010-06-16  4:56 ` KAMEZAWA Hiroyuki
  2010-06-18 21:38 ` Andrew Morton
  0 siblings, 2 replies; 5+ messages in thread
From: KOSAKI Motohiro @ 2010-06-16  4:36 UTC (permalink / raw)
  To: Christoph Lameter, linux-mm, LKML, Andrew Morton; +Cc: kosaki.motohiro


Now, migrate_pages() are using >500 bytes stack. This patch reduce it.

   mm/mempolicy.c: In function 'sys_migrate_pages':
   mm/mempolicy.c:1344: warning: the frame size of 528 bytes is larger than
   512 bytes

Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
---
 mm/mempolicy.c |   35 ++++++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 13b09bd..1116427 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -1275,33 +1275,39 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
 		const unsigned long __user *, new_nodes)
 {
 	const struct cred *cred = current_cred(), *tcred;
-	struct mm_struct *mm;
+	struct mm_struct *mm = NULL;
 	struct task_struct *task;
-	nodemask_t old;
-	nodemask_t new;
 	nodemask_t task_nodes;
 	int err;
+	NODEMASK_SCRATCH(scratch);
+	nodemask_t *old = &scratch->mask1;
+	nodemask_t *new = &scratch->mask2;
+
+	if (!scratch)
+		return -ENOMEM;
 
-	err = get_nodes(&old, old_nodes, maxnode);
+	err = get_nodes(old, old_nodes, maxnode);
 	if (err)
-		return err;
+		goto out;
 
-	err = get_nodes(&new, new_nodes, maxnode);
+	err = get_nodes(new, new_nodes, maxnode);
 	if (err)
-		return err;
+		goto out;
 
 	/* Find the mm_struct */
 	read_lock(&tasklist_lock);
 	task = pid ? find_task_by_vpid(pid) : current;
 	if (!task) {
 		read_unlock(&tasklist_lock);
-		return -ESRCH;
+		err = -ESRCH;
+		goto out;
 	}
 	mm = get_task_mm(task);
 	read_unlock(&tasklist_lock);
 
+	err = -EINVAL;
 	if (!mm)
-		return -EINVAL;
+		goto out;
 
 	/*
 	 * Check if this process has the right to modify the specified
@@ -1322,12 +1328,12 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
 
 	task_nodes = cpuset_mems_allowed(task);
 	/* Is the user allowed to access the target nodes? */
-	if (!nodes_subset(new, task_nodes) && !capable(CAP_SYS_NICE)) {
+	if (!nodes_subset(*new, task_nodes) && !capable(CAP_SYS_NICE)) {
 		err = -EPERM;
 		goto out;
 	}
 
-	if (!nodes_subset(new, node_states[N_HIGH_MEMORY])) {
+	if (!nodes_subset(*new, node_states[N_HIGH_MEMORY])) {
 		err = -EINVAL;
 		goto out;
 	}
@@ -1336,10 +1342,13 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
 	if (err)
 		goto out;
 
-	err = do_migrate_pages(mm, &old, &new,
+	err = do_migrate_pages(mm, old, new,
 		capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
 out:
-	mmput(mm);
+	if (mm)
+		mmput(mm);
+	NODEMASK_SCRATCH_FREE(scratch);
+
 	return err;
 }
 
-- 
1.6.5.2



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

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

* Re: [PATCH] mempolicy: reduce stack size of migrate_pages()
  2010-06-16  4:36 [PATCH] mempolicy: reduce stack size of migrate_pages() KOSAKI Motohiro
@ 2010-06-16  4:56 ` KAMEZAWA Hiroyuki
  2010-06-16 16:31   ` Christoph Lameter
  2010-06-18 21:38 ` Andrew Morton
  1 sibling, 1 reply; 5+ messages in thread
From: KAMEZAWA Hiroyuki @ 2010-06-16  4:56 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: Christoph Lameter, linux-mm, LKML, Andrew Morton

On Wed, 16 Jun 2010 13:36:57 +0900 (JST)
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:

> 
> Now, migrate_pages() are using >500 bytes stack. This patch reduce it.
> 
>    mm/mempolicy.c: In function 'sys_migrate_pages':
>    mm/mempolicy.c:1344: warning: the frame size of 528 bytes is larger than
>    512 bytes
> 
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Cc: Christoph Lameter <cl@linux-foundation.org>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>

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

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

* Re: [PATCH] mempolicy: reduce stack size of migrate_pages()
  2010-06-16  4:56 ` KAMEZAWA Hiroyuki
@ 2010-06-16 16:31   ` Christoph Lameter
  0 siblings, 0 replies; 5+ messages in thread
From: Christoph Lameter @ 2010-06-16 16:31 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki; +Cc: KOSAKI Motohiro, linux-mm, LKML, Andrew Morton


Reviewed-by: Christoph Lameter <cl@linux-foundation.org>


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

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

* Re: [PATCH] mempolicy: reduce stack size of migrate_pages()
  2010-06-16  4:36 [PATCH] mempolicy: reduce stack size of migrate_pages() KOSAKI Motohiro
  2010-06-16  4:56 ` KAMEZAWA Hiroyuki
@ 2010-06-18 21:38 ` Andrew Morton
  2010-06-21 11:45   ` KOSAKI Motohiro
  1 sibling, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2010-06-18 21:38 UTC (permalink / raw)
  To: KOSAKI Motohiro; +Cc: Christoph Lameter, linux-mm, LKML

On Wed, 16 Jun 2010 13:36:57 +0900 (JST)
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> wrote:

> 
> Now, migrate_pages() are using >500 bytes stack. This patch reduce it.
> 
>    mm/mempolicy.c: In function 'sys_migrate_pages':
>    mm/mempolicy.c:1344: warning: the frame size of 528 bytes is larger than
>    512 bytes
> 
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
> Cc: Christoph Lameter <cl@linux-foundation.org>
> ---
>  mm/mempolicy.c |   35 ++++++++++++++++++++++-------------
>  1 files changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 13b09bd..1116427 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -1275,33 +1275,39 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
>  		const unsigned long __user *, new_nodes)
>  {
>  	const struct cred *cred = current_cred(), *tcred;
> -	struct mm_struct *mm;
> +	struct mm_struct *mm = NULL;
>  	struct task_struct *task;
> -	nodemask_t old;
> -	nodemask_t new;
>  	nodemask_t task_nodes;
>  	int err;
> +	NODEMASK_SCRATCH(scratch);
> +	nodemask_t *old = &scratch->mask1;
> +	nodemask_t *new = &scratch->mask2;
>
> +	if (!scratch)
> +		return -ENOMEM;

It doesn't matter in practice, but it makes me all queazy to see code
which plays with pointers which might be NULL.

--- a/mm/mempolicy.c~mempolicy-reduce-stack-size-of-migrate_pages-fix
+++ a/mm/mempolicy.c
@@ -1279,13 +1279,16 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
 	struct task_struct *task;
 	nodemask_t task_nodes;
 	int err;
+	nodemask_t *old;
+	nodemask_t *new;
 	NODEMASK_SCRATCH(scratch);
-	nodemask_t *old = &scratch->mask1;
-	nodemask_t *new = &scratch->mask2;
 
 	if (!scratch)
 		return -ENOMEM;
 
+	old = &scratch->mask1;
+	new = &scratch->mask2;
+
 	err = get_nodes(old, old_nodes, maxnode);
 	if (err)
 		goto out;
_

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

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

* Re: [PATCH] mempolicy: reduce stack size of migrate_pages()
  2010-06-18 21:38 ` Andrew Morton
@ 2010-06-21 11:45   ` KOSAKI Motohiro
  0 siblings, 0 replies; 5+ messages in thread
From: KOSAKI Motohiro @ 2010-06-21 11:45 UTC (permalink / raw)
  To: Andrew Morton; +Cc: kosaki.motohiro, Christoph Lameter, linux-mm, LKML

> >  	const struct cred *cred = current_cred(), *tcred;
> > -	struct mm_struct *mm;
> > +	struct mm_struct *mm = NULL;
> >  	struct task_struct *task;
> > -	nodemask_t old;
> > -	nodemask_t new;
> >  	nodemask_t task_nodes;
> >  	int err;
> > +	NODEMASK_SCRATCH(scratch);
> > +	nodemask_t *old = &scratch->mask1;
> > +	nodemask_t *new = &scratch->mask2;
> >
> > +	if (!scratch)
> > +		return -ENOMEM;
> 
> It doesn't matter in practice, but it makes me all queazy to see code
> which plays with pointers which might be NULL.

I see. thanks.
Do we need to send you updated patch?


> 
> --- a/mm/mempolicy.c~mempolicy-reduce-stack-size-of-migrate_pages-fix
> +++ a/mm/mempolicy.c
> @@ -1279,13 +1279,16 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pi
>  	struct task_struct *task;
>  	nodemask_t task_nodes;
>  	int err;
> +	nodemask_t *old;
> +	nodemask_t *new;
>  	NODEMASK_SCRATCH(scratch);
> -	nodemask_t *old = &scratch->mask1;
> -	nodemask_t *new = &scratch->mask2;
>  
>  	if (!scratch)
>  		return -ENOMEM;
>  
> +	old = &scratch->mask1;
> +	new = &scratch->mask2;
> +
>  	err = get_nodes(old, old_nodes, maxnode);
>  	if (err)
>  		goto out;
> _
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/



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

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

end of thread, other threads:[~2010-06-21 11:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-16  4:36 [PATCH] mempolicy: reduce stack size of migrate_pages() KOSAKI Motohiro
2010-06-16  4:56 ` KAMEZAWA Hiroyuki
2010-06-16 16:31   ` Christoph Lameter
2010-06-18 21:38 ` Andrew Morton
2010-06-21 11:45   ` KOSAKI Motohiro

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