linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Lameter <cl@linux-foundation.org>
To: Andi Kleen <andi@firstfloor.org>
Cc: npiggin@suse.de, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org, Tejun Heo <tj@kernel.org>,
	Ingo Molnar <mingo@elte.hu>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	"hugh.dickins@tiscali.co.uk" <hugh.dickins@tiscali.co.uk>
Subject: [RFC MM] mmap_sem scaling: only scan cpus used by an mm
Date: Fri, 6 Nov 2009 13:53:35 -0500 (EST)	[thread overview]
Message-ID: <alpine.DEB.1.10.0911061352320.22205@V090114053VZO-1> (raw)
In-Reply-To: <20091106073946.GV31511@one.firstfloor.org>

One way to reduce the cost of the writer lock is to track the cpus used
and loop over the processors in that bitmap.

---
 arch/x86/include/asm/mmu_context.h |    1 +
 include/linux/mm_types.h           |    3 ++-
 kernel/fork.c                      |    2 ++
 mm/init-mm.c                       |    1 +
 4 files changed, 6 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/x86/include/asm/mmu_context.h
===================================================================
--- linux-2.6.orig/arch/x86/include/asm/mmu_context.h	2009-11-06 12:26:24.000000000 -0600
+++ linux-2.6/arch/x86/include/asm/mmu_context.h	2009-11-06 12:26:36.000000000 -0600
@@ -43,6 +43,7 @@ static inline void switch_mm(struct mm_s
 		percpu_write(cpu_tlbstate.active_mm, next);
 #endif
 		cpumask_set_cpu(cpu, mm_cpumask(next));
+		cpumask_set_cpu(cpu, &next->cpus_used);

 		/* Re-load page tables */
 		load_cr3(next->pgd);
Index: linux-2.6/include/linux/mm_types.h
===================================================================
--- linux-2.6.orig/include/linux/mm_types.h	2009-11-06 12:26:35.000000000 -0600
+++ linux-2.6/include/linux/mm_types.h	2009-11-06 12:26:36.000000000 -0600
@@ -241,6 +241,7 @@ struct mm_struct {
 	struct linux_binfmt *binfmt;

 	cpumask_t cpu_vm_mask;
+	cpumask_t cpus_used;

 	/* Architecture-specific MM context */
 	mm_context_t context;
@@ -291,7 +292,7 @@ static inline int mm_has_reader(struct m
 {
 	int cpu;

-	for_each_possible_cpu(cpu)
+	for_each_cpu(cpu, &mm->cpus_used)
 		if (per_cpu(mm->rss->readers, cpu))
 			return 1;

Index: linux-2.6/mm/init-mm.c
===================================================================
--- linux-2.6.orig/mm/init-mm.c	2009-11-06 12:26:35.000000000 -0600
+++ linux-2.6/mm/init-mm.c	2009-11-06 12:26:36.000000000 -0600
@@ -19,5 +19,6 @@ struct mm_struct init_mm = {
 	.page_table_lock =  __SPIN_LOCK_UNLOCKED(init_mm.page_table_lock),
 	.mmlist		= LIST_HEAD_INIT(init_mm.mmlist),
 	.cpu_vm_mask	= CPU_MASK_ALL,
+	.cpus_used	= CPU_MASK_ALL,
 	.rss		= &init_mm_counters,
 };
Index: linux-2.6/kernel/fork.c
===================================================================
--- linux-2.6.orig/kernel/fork.c	2009-11-06 12:26:35.000000000 -0600
+++ linux-2.6/kernel/fork.c	2009-11-06 12:26:40.000000000 -0600
@@ -297,6 +297,8 @@ static int dup_mmap(struct mm_struct *mm
 	mm->cached_hole_size = ~0UL;
 	mm->map_count = 0;
 	cpumask_clear(mm_cpumask(mm));
+	cpumask_clear(&mm->cpus_used);
+	cpumask_set_cpu(smp_processor_id(), &mm->cpus_used);
 	mm->mm_rb = RB_ROOT;
 	rb_link = &mm->mm_rb.rb_node;
 	rb_parent = NULL;

--
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:[~2009-11-06 18:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-05 19:19 [RFC MM] Accessors for mm locking Christoph Lameter
2009-11-05 19:20 ` Subject: [RFC MM] mmap_sem scaling: Use mutex and percpu counter instead Christoph Lameter
2009-11-05 20:56   ` Andi Kleen
2009-11-05 21:03     ` Christoph Lameter
2009-11-06  7:39       ` Andi Kleen
2009-11-06 17:08         ` Christoph Lameter
2009-11-06 17:44           ` Andi Kleen
2009-11-06 17:54             ` Christoph Lameter
2009-11-10  6:21               ` KOSAKI Motohiro
2009-11-10  9:19                 ` Andi Kleen
2009-11-06 18:53         ` Christoph Lameter [this message]
2009-11-06 19:14           ` [RFC MM] mmap_sem scaling: only scan cpus used by an mm Andi Kleen
2009-11-06 19:45             ` Christoph Lameter
2009-11-05 22:05   ` [RFC MM] swap counters Christoph Lameter
2009-11-06  2:54     ` KAMEZAWA Hiroyuki
2009-11-06 15:41   ` Subject: [RFC MM] mmap_sem scaling: Use mutex and percpu counter instead Minchan Kim
2009-11-06 17:10     ` Christoph Lameter
2009-11-07  4:19       ` Minchan Kim
2009-11-10 20:20         ` Christoph Lameter
2009-11-05 20:52 ` [RFC MM] Accessors for mm locking Andi Kleen
2009-11-05 20:57   ` Christoph Lameter
2009-11-17  6:42 ` Zhang, Yanmin

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=alpine.DEB.1.10.0911061352320.22205@V090114053VZO-1 \
    --to=cl@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=hugh.dickins@tiscali.co.uk \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@elte.hu \
    --cc=npiggin@suse.de \
    --cc=tj@kernel.org \
    /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