linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matt Helsley <matthltc@us.ibm.com>
To: Linux-Kernel <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Al Viro <viro@ftp.linux.org.uk>,
	Dave Hansen <haveblue@us.ibm.com>
Subject: [RFC][PATCH 2/3] [RFC][PATCH] Add spinlock in mm to protext exe reference
Date: Wed, 31 Oct 2007 20:35:10 -0700	[thread overview]
Message-ID: <20071101044124.550166000@us.ibm.com> (raw)
In-Reply-To: <20071101033508.720885000@us.ibm.com>

[-- Attachment #1: proc_pid_exe_avoid_mmap_sem --]
[-- Type: text/plain, Size: 2945 bytes --]

The new and relatively unused (compared to VM ops) mm_struct exe file reference
uses the mmap semaphore. It may be preferrable to avoid using the mmap
semaphore at some point in the future. This patch demonstrates one way to avoid
using the mmap semaphore for the exe file reference inside /proc/pid/exe ops.

Unfortunately we can't entirely avoid using the mmap semaphore because we need
to drop the exe file reference when the VMA mapping the executable file does --
otherwise we'd pin mounted filesystems until all applications executed from
them exitted.

Signed-off-by: Matt Helsley <matthltc@us.ibm.com>
---
 include/linux/sched.h |    1 +
 mm/mmap.c             |   17 +++++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

Index: linux-2.6.23/include/linux/sched.h
===================================================================
--- linux-2.6.23.orig/include/linux/sched.h
+++ linux-2.6.23/include/linux/sched.h
@@ -432,10 +432,11 @@ struct mm_struct {
 	/* aio bits */
 	rwlock_t		ioctx_list_lock;
 	struct kioctx		*ioctx_list;
 
 	/* store ref to file /proc/<pid>/exe symlink points to */
+	spinlock_t exe_file_lock;
 	struct file *exe_file;
 };
 
 struct sighand_struct {
 	atomic_t		count;
Index: linux-2.6.23/mm/mmap.c
===================================================================
--- linux-2.6.23.orig/mm/mmap.c
+++ linux-2.6.23/mm/mmap.c
@@ -1706,27 +1706,27 @@ find_extend_vma(struct mm_struct * mm, u
  * reference; only puts old ones */
 void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file)
 {
 	struct file *old_exe_file;
 
-	down_write(&mm->mmap_sem);
+	spin_lock(&mm->exe_file_lock);
 	old_exe_file = mm->exe_file;
 	mm->exe_file = new_exe_file;
-	up_write(&mm->mmap_sem);
+	spin_unlock(&mm->exe_file_lock);
 	if (old_exe_file)
 		fput(old_exe_file);
 }
 
 struct file *get_mm_exe_file(struct mm_struct *mm)
 {
 	struct file *exe_file;
 
-	down_read(&mm->mmap_sem);
+	spin_lock(&mm->exe_file_lock);
 	exe_file = mm->exe_file;
 	if (exe_file)
 		get_file(exe_file);
-	up_read(&mm->mmap_sem);
+	spin_unlock(&mm->exe_file_lock);
 	return exe_file;
 }
 #endif
 
 /*
@@ -1744,14 +1744,19 @@ static void remove_vma_list(struct mm_st
 
 		mm->total_vm -= nrpages;
 		if (vma->vm_flags & VM_LOCKED)
 			mm->locked_vm -= nrpages;
 		vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
+		spin_lock(&mm->exe_file_lock);
 		if (mm->exe_file && (vma->vm_file == mm->exe_file)) {
-			fput(mm->exe_file);
+			struct file *old_exe_file = mm->exe_file;
+
 			mm->exe_file = NULL;
-		}
+			spin_unlock(&mm->exe_file_lock);
+			fput(old_exe_file);
+		} else
+			spin_unlock(&mm->exe_file_lock);
 		vma = remove_vma(vma);
 	} while (vma);
 	validate_mm(mm);
 }
 

--

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

  parent reply	other threads:[~2007-11-01  4:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-01  3:35 [RFC][PATCH 0/3] Procfs Task exe Symlinks Matt Helsley
2007-11-01  3:35 ` [RFC][PATCH 1/3] [RFC][PATCH] Fix procfs task exe symlinks Matt Helsley
2007-11-01 19:25   ` Andrew Morton
2007-11-01 19:52     ` Matt Helsley
2007-11-01  3:35 ` Matt Helsley [this message]
2007-11-01  3:35 ` [RFC][PATCH 3/3] [RFC][PATCH] Make /proc/pid/exe symlink changeable Matt Helsley

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=20071101044124.550166000@us.ibm.com \
    --to=matthltc@us.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=haveblue@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=viro@ftp.linux.org.uk \
    /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