linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Lameter <clameter@sgi.com>
To: Lee Schermerhorn <lee.schermerhorn@hp.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org, ak@suse.de,
	eric.whitney@hp.com, mel@skynet.ie
Subject: Re: [PATCH/RFC 4/4] Mem Policy: Fixup Fallback for Default Shmem Policy
Date: Mon, 15 Oct 2007 12:34:09 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.64.0710151226330.26753@schroedinger.engr.sgi.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0710121045380.8891@schroedinger.engr.sgi.com>

On Fri, 12 Oct 2007, Christoph Lameter wrote:

> > Index: Linux/mm/mempolicy.c
> > ===================================================================
> > --- Linux.orig/mm/mempolicy.c	2007-10-12 10:50:05.000000000 -0400
> > +++ Linux/mm/mempolicy.c	2007-10-12 10:52:46.000000000 -0400
> > @@ -1112,19 +1112,25 @@ static struct mempolicy * get_vma_policy
> >  		struct vm_area_struct *vma, unsigned long addr)
> >  {
> >  	struct mempolicy *pol = task->mempolicy;
> > -	int shared_pol = 0;
> > +	int pol_needs_ref = (task != current);
> 
> If get_vma_policy is called from the numa_maps handler then we have taken 
> a refcount on the task struct. 
> 
> So this should be
> 	int pol_needs_ref = 0;

Argh. Refcount is not it. We have taken the mmap_sem lock 
because we are scanning though the pages. This avoids issues for the vma 
policies that can only be set when a writelock was taken on mmap_sem.

However, mmap_sem is not taken when setting task->mempolicy. Taking 
mmap_sem there would solve the issue (we have discussed this before).

You cannot reliably take a refcount on a foreign task structs mempolicy 
since the task may just be in the process of switching policies. You could 
increment the refcount and then the other task frees the structure.

I think we need something like this:

Index: linux-2.6/mm/mempolicy.c
===================================================================
--- linux-2.6.orig/mm/mempolicy.c	2007-10-15 12:32:45.000000000 -0700
+++ linux-2.6/mm/mempolicy.c	2007-10-15 12:33:56.000000000 -0700
@@ -468,11 +468,13 @@ long do_set_mempolicy(int mode, nodemask
 	new = mpol_new(mode, nodes);
 	if (IS_ERR(new))
 		return PTR_ERR(new);
+	down_read(&current->mm->mmap_sem);
 	mpol_free(current->mempolicy);
 	current->mempolicy = new;
 	mpol_set_task_struct_flag();
 	if (new && new->policy == MPOL_INTERLEAVE)
 		current->il_next = first_node(new->v.nodes);
+	up_read(&current->mm->mmap_sem);
 	return 0;
 }
 

--
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:[~2007-10-15 19:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-12 15:48 [PATCH/RFC 0/4] More Mempolicy Reference Counting Fixes Lee Schermerhorn
2007-10-12 15:49 ` [PATCH/RFC 1/4] Mem Policy: fix mempolicy usage in pci driver Lee Schermerhorn
2007-10-12 17:29   ` Christoph Lameter
2007-10-12 15:49 ` [PATCH/RFC 2/4] Mem Policy: Fixup Shm and Interleave Policy Reference Counting Lee Schermerhorn
2007-10-12 17:30   ` Christoph Lameter
2007-10-12 15:49 ` [PATCH/RFC 3/4] Mem Policy: Fixup " Lee Schermerhorn
2007-10-12 17:33   ` Christoph Lameter
2007-10-12 15:49 ` [PATCH/RFC 4/4] Mem Policy: Fixup Fallback for Default Shmem Policy Lee Schermerhorn
2007-10-12 17:57   ` Christoph Lameter
2007-10-15 19:34     ` Christoph Lameter [this message]
2007-10-23 16:15       ` Lee Schermerhorn
2007-10-23 16:23         ` Christoph Lameter
2007-10-23 17:32     ` Lee Schermerhorn
2007-10-24 13:09       ` Christoph Lameter

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=Pine.LNX.4.64.0710151226330.26753@schroedinger.engr.sgi.com \
    --to=clameter@sgi.com \
    --cc=ak@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=eric.whitney@hp.com \
    --cc=lee.schermerhorn@hp.com \
    --cc=linux-mm@kvack.org \
    --cc=mel@skynet.ie \
    /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).