[SSI] openssi/kernel/cluster/ssi/mosixll balance.c, 1.20, 1.21 freemem.c, 1.14, 1.15 info.c, 1.14, 1.15 kernel.c, 1.13, 1.14 load.c, 1.14, 1.15

Roger Tsang <[email protected]> Tue, 09 Nov 2010 02:46:05 +0000
Newsgroups gmane.linux.cluster.ssic.cvs
Message-ID <[email protected]>
Update of /cvsroot/ssic-linux/openssi/kernel/cluster/ssi/mosixll
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv12803/cluster/ssi/mosixll

Modified Files:
      Tag: OPENSSI-FC
	balance.c freemem.c info.c kernel.c load.c 
Log Message:
MOSIX:
- Move last_consider, last_mconsider, pages_i_bring, and load fields in mosix_task structure to memory descriptor since these fields apply to the thread group, not individual threads. Reduce duplication in process descriptor for threads. Reduce related overhead maintaining these fields.
- Remove volatile keyword in dflags and stay fields in mosix_task structure. No reason for volatile.
- When traversing tasklist use get_task_mm(). Skip PF_BORROWED_MM.
- mosix_mem_daemon: remove neutralize_my_load() call. In OpenSSI it not needed for kernel threads.

 cluster/ssi/mosixll/balance.c           |   72 ++++++++++++++----------
 cluster/ssi/mosixll/freemem.c           |   18 +++---
 cluster/ssi/mosixll/info.c              |   17 +----
 cluster/ssi/mosixll/kernel.c            |   14 +---
 cluster/ssi/mosixll/load.c              |   57 ++++++++-----------
 include/cluster/ssi/mosixll/mosixtask.h |   17 +----


Index: kernel.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/kernel/cluster/ssi/mosixll/kernel.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- kernel.c	9 Nov 2010 02:31:01 -0000	1.13
+++ kernel.c	9 Nov 2010 02:46:03 -0000	1.14
@@ -633,6 +633,7 @@
 	struct mosix_task *m = &p->mosix;
 	struct task_struct *parent = current;
 
+#ifndef CONFIG_SSI
 #ifdef CONFIG_MOSIX_DFSA
 	tell_process(parent, DREQ_NOTUPTODATE);
 	tell_process(p, DREQ_NOTUPTODATE);
@@ -640,7 +641,6 @@
 		dfsa_tinit();
 	m->ttab = NULL;
 #endif /* CONFIG_MOSIX_DFSA */
-#ifndef CONFIG_SSI
 	if(!(parent->mosix.dflags & DDEPUTY))
 		tell_process(p, DREQ_CHECKSTAY);
 #endif /* !CONFIG_SSI */
@@ -701,23 +701,19 @@
 	m->copyinbytes = 0;
 	m->iocounter = 0;
 	m->cutime = 0;
-#endif /* !CONFIG_SSI */
 	m->last_consider = 0;
 	m->last_mconsider = 0;
-#ifndef CONFIG_SSI
 	m->decsecs = 0;
 	memset((caddr_t)&m->asig, 0, sizeof(m->asig));
 	m->forced_sigs = 0;
 	m->nforced_sigs = 0;
-#endif /* !CONFIG_SSI */
 	m->pages_i_bring = 0;
-#ifndef CONFIG_SSI
 	m->page_allocs = 0;
-#endif
+#endif /* !CONFIG_SSI */
 	m->ran = 0;
 	m->runstart = 0;
-	m->load = 0;
 #ifndef CONFIG_SSI
+	m->load = 0;
 	m->inexec = NULL;
 	m->nmigs = 0;
 	m->pass_regs = 0;
@@ -744,6 +740,8 @@
 #endif /* !CONFIG_SSI */
 }
 
+#ifndef CONFIG_SSI
+#if 0
 void
 mosix_exit(void)
 {
@@ -796,8 +794,6 @@
 #endif /* !CONFIG_SSI */
 }
 
-#ifndef CONFIG_SSI
-#if 0
 void
 mosix_very_exit(void)
 {

Index: load.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/kernel/cluster/ssi/mosixll/load.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- load.c	9 Nov 2010 02:31:01 -0000	1.14
+++ load.c	9 Nov 2010 02:46:03 -0000	1.15
@@ -89,14 +89,12 @@
 mosix_calc_process_loads(unsigned long u_ticks)
 {
 	struct task_struct *p, *t;
-	struct mosix_task *m;
 	struct runqueue *rq = NULL;
 	unsigned long flags;
-	unsigned long load = 0;
 	clock_t ran = 0;
 	cputime_t time;
 
-	/* Based on original mosix_calc_load() but also account for threads.
+	/* Based on original mosix_calc_load() but account for thread group.
 	 * Unlike Mosix this is no longer in top half.
 	 */
 	read_lock(&tasklist_lock);
@@ -105,43 +103,36 @@
 			continue;
 		if (p->execnode || !is_loadlevelable(p, NULL))
 			continue;
-		/* Add thread group's mosix_task->ran cputime */
-		time = cputime_zero, t = p;
+		if (!get_task_mm(p))
+			continue;
+
+		time = cputime_zero;
+		t = p;
 		do {
-			t = next_thread(t);
-			m = &t->mosix;
-			if (!m->ran && t != p)
+			if (!t->mosix.ran)
 				continue;
-
 			rq = task_rq_lock(t, &flags);
-			if (m->ran) {
-				time = cputime_add(time, m->ran);
-				m->ran = cputime_zero;
+			if (t->mosix.ran) {
+				time = cputime_add(time, t->mosix.ran);
+				t->mosix.ran = cputime_zero;
 			}
 			task_rq_unlock(rq, &flags);
+		} while_each_thread(p, t);
 
-			/* Update leader's mosix_task->load */
-			if (t == p) {
-				if (time) {
-					ran = min_t(clock_t,
-						cputime_to_clock_t(time),
-						u_ticks * num_online_cpus());
-				}
-
-				task_lock(t);
-				m->load *= DECAY;
-				if (time) {
-					m->load += ran * stable_export *
-							4*NEWDATA / u_ticks;
-				}
-				load = m->load;
-				task_unlock(t);
-			}
-		} while (t != p);
+		if (time) {
+			ran = min_t(clock_t,
+				cputime_to_clock_t(time),
+				u_ticks * num_online_cpus());
+		}
 
-		/* Update group's mosix_task->load */
-		while_each_thread(p, t)
-			t->mosix.load = load;
+		task_lock(p);
+		p->mm->load *= DECAY;
+		if (time) {
+			p->mm->load += ran * stable_export *
+					4*NEWDATA / u_ticks;
+		}
+		task_unlock(p);
+		mmput(p->mm);
 	}
 	read_unlock(&tasklist_lock);
 }

Index: balance.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/kernel/cluster/ssi/mosixll/balance.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- balance.c	9 Nov 2010 02:31:01 -0000	1.20
+++ balance.c	9 Nov 2010 02:46:03 -0000	1.21
@@ -475,7 +475,6 @@
 void
 choose(void *dummy)
 {
-	struct mosix_task *m;
 	struct task_struct *p, *sel = NULL;
         unsigned long minload, load, bestload = -1;
         unsigned int priority, lastpri = 0; /* ms */
@@ -498,13 +497,14 @@
 	for_each_process(p) {
 		if (p->mosix.stay || p == chosen_for_mdp)
 			continue;
-		/* Process already migrating */
-		if (p->execnode)
+		if (p->execnode) /* Process already migrating */
 			continue;
 		if (p->mm == NULL || !thread_group_leader(p))
 			continue;
 		if (!is_loadlevelable(p, NULL))
 			continue;
+		if (!get_task_mm(p))
+			continue;
 
 		time = cputime_zero;
 		/* This block from 2.6.11 fs/proc/array.c:do_task_stat() */
@@ -526,11 +526,12 @@
 		}
 		priority = cputime_to_msecs(time);
 
-		m = &p->mosix;
-		priority -= m->last_consider;
+		priority -= p->mm->last_consider;
 		pri = priority < 4000 ? priority : 4000; /* 4000ms */
 
-                load = m->load;
+		task_lock(p);
+                load = p->mm->load;
+		task_unlock(p);
 #ifdef DEBUG
 if(Tload)
 	printk(KERN_DEBUG "%s: process=%d, load=%lu pri=%u bestpri=%u "
@@ -541,23 +542,27 @@
                 if(pri < bestpri)
                 {
                         if(bestpri == mintime &&
+			   load > minload && pri >= very_mintime) {
 				/* (thrashing, or (m->load <= minload)) */
-			   load > minload && pri >= very_mintime)
                                 pri = mintime;
-                        else
+                        } else {
+				mmput(p->mm);
                                 continue;
+			}
                 }
 
-                if(pri > bestpri || load > bestload)
-                {
-                        bestload = load;
-                        bestpri = pri;
-			lastpri = priority;
+                if (pri > bestpri || load > bestload) {
 			get_task_struct(p);
-			if(sel)
+			if (sel) {
+				mmput(sel->mm);
 				put_task_struct(sel);
+			}
                         sel = p;
-                }
+                        bestload = load;
+                        bestpri = pri;
+			lastpri = priority;
+                } else
+			mmput(p->mm);
         }
 	read_unlock(&tasklist_lock);
 
@@ -576,11 +581,14 @@
 	if(chosen_for_balance)
 	{
 		spin_unlock(&whereto_lock);
+		mmput(sel->mm);
 		put_task_struct(sel);
 		return;
 	}
 	chosen_for_balance = sel;
-        sel->mosix.last_consider += lastpri;
+        sel->mm->last_consider += lastpri;
+	mmput(sel->mm);
+
 	load_balancing_counter = BALANCING_TIMEOUT;
 	mosix_do_add_to_whereto(sel, BALANCE);
 	/* whereto_lock unlocked */
@@ -763,45 +771,53 @@
 	for_each_process(p) {
 		if (p->mosix.stay || p == chosen_for_balance)
 			continue;
-		/* Process already migrating */
-		if (p->execnode)
+		if (p->execnode) /* Process already migrating */
 			continue;
 		if (p->mm == NULL || !thread_group_leader(p))
 			continue;
 		if (!is_loadlevelable(p, NULL))
 			continue;
 
-		dff = get_jiffies_64() - p->mosix.last_mconsider;
+		if (!get_task_mm(p))
+			continue;
+		dff = get_jiffies_64() - p->mm->last_mconsider;
 		if (dff)
 			dff /= HZ;
 
 		df = min_t(typeof(dff), dff, MAX_MCHOOSE_AGAIN / 1000);
-		if(df < diff)
+		if(df < diff) {
+			mmput(p->mm);
 			continue;
+		}
 
 		quality = memory_relief_quality(p, need);
-		if(quality > bestquality || (quality > 0 && df > diff))
-                {
+		if (quality > bestquality || (quality > 0 && df > diff)) {
 			get_task_struct(p);
-			if(sel)
+			if(sel) {
+				mmput(sel->mm);
 				put_task_struct(sel);
+			}
                         sel = p;
                         bestquality = quality;
 			diff = df;
-                }
+                } else
+			mmput(p->mm);
         }
 	read_unlock(&tasklist_lock);
         if(!sel)
 		return;
+
 	spin_lock(&whereto_lock);
-	if(chosen_for_mdp)
-	{
-		put_task_struct(sel);
+	if (chosen_for_mdp) {
 		spin_unlock(&whereto_lock);
+		mmput(sel->mm);
+		put_task_struct(sel);
 		return;
 	}
 	chosen_for_mdp = sel;
-	sel->mosix.last_mconsider = get_jiffies_64();
+	sel->mm->last_mconsider = get_jiffies_64();
+	mmput(sel->mm);
+
 	memory_balancing_counter = BALANCING_TIMEOUT;
 	mosix_do_add_to_whereto(sel, MEMBALANCE);
 	/* whereto_lock unlocked */

Index: freemem.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/kernel/cluster/ssi/mosixll/freemem.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- freemem.c	9 Nov 2010 02:31:01 -0000	1.14
+++ freemem.c	9 Nov 2010 02:46:03 -0000	1.15
@@ -104,8 +104,11 @@
 			continue;
 		if (!p->mm || !thread_group_leader(p))
 			continue;
+		if (!get_task_mm(p))
+			continue;
 		/* SSI: mosix.pages_i_bring is +ve. See release_migrations() */
-		b += p->mosix.pages_i_bring;
+		b += p->mm->pages_i_bring;
+		mmput(p->mm);
 	}
 	read_unlock(&tasklist_lock);
 
@@ -166,7 +169,7 @@
 
 /* "memory_relief_quality" is called with tasklist_lock read-locked */
 #ifdef SSI_BALANCE_MEMORY
-/* Acquires spinlock(&mm->memsort_lock) */
+/* Caller holds p->mm reference */
 unsigned long
 memory_relief_quality(struct task_struct *p, unsigned long need)
 #else
@@ -184,22 +187,17 @@
 	struct mm_struct *mm;
 
 #ifdef SSI_BALANCE_MEMORY
-	mm = get_task_mm(p);
-	if (!mm)
-		return 0;
+	mm = p->mm;
 
 	spin_lock(&mm->memsort_lock);
 	if (!mm->last_memsort) {
 		spin_unlock(&mm->memsort_lock);
-		mmput(mm);
 		return 0;
 	}
 	used = mm->used;
 	swapped = mm->swapped;
 	spin_unlock(&mm->memsort_lock);
 
-	mmput(mm);
-
 	if (used >= need) {
 		if (used < 2 * need)
 			q = MDP_HIGHEST_QUALITY * (150 - used * 50 / need) / 100;
@@ -603,7 +601,9 @@
 	int interval;
 
 	common_daemon_setup("memsorter", 0);
+#ifndef CONFIG_SSI
 	neutralize_my_load(1);
+#endif
 	if(!(mms = (struct mm_struct **)kmalloc(mmno * sizeof(mms[0]),
 								GFP_KERNEL)))
 		panic("no mem for mms");
@@ -647,7 +647,7 @@
 			continue;
 #else
 			wait_for_mosix_configuration(NULL);
-#endif
+#endif /* !CONFIG_SSI */
 		if(mosadmin_mode_quiet)
 			continue;
 		compute_freemem();

Index: info.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/kernel/cluster/ssi/mosixll/info.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- info.c	9 Nov 2010 02:31:01 -0000	1.14
+++ info.c	9 Nov 2010 02:46:03 -0000	1.15
@@ -972,26 +972,22 @@
 #ifdef CONFIG_SSI
 /* Locking: will acquire...
  * read_lock(&tasklist_lock);
- * task_rq_lock()
+ * task_lock()
  * spin_lock(&load_left_lock)
  * spin_lock(&loadinfo_lock)
- * task_lock()
  */
 void
 release_migrations(int i, unsigned long pages)
 {
 	struct task_struct *p = current;
-#ifdef SSI_BALANCE_MEMORY
-	struct task_struct *t = p;
-#endif
 	unsigned long load, mig_load;
 
 	/* Decrease the local load by the load caused by this process,
 	 * to avoid over-migration.
 	 */
 	read_lock(&tasklist_lock);
-	task_lock(p->group_leader);
-	load = p->group_leader->mosix.load;
+	task_lock(p->group_leader); /* avoid mosix_calc_process_loads() race */
+	load = p->group_leader->mm->load;
 	task_unlock(p->group_leader);
 	read_unlock(&tasklist_lock);
 
@@ -1053,12 +1049,7 @@
 	spin_unlock(&loadinfo_lock);
 
 #ifdef SSI_BALANCE_MEMORY
-	/* discourage 'memory_badly_required' */
-	read_lock(&tasklist_lock);
-	do {
-		t->mosix.pages_i_bring = pages;
-	} while_each_thread(p, t);
-	read_unlock(&tasklist_lock);
+	p->mm->pages_i_bring = pages; /* discourage 'memory_badly_required' */
 #else
 	p->mosix.pages_i_bring = -pages; /* discourage 'memory_badly_required' */
 #endif


------------------------------------------------------------------------------
The Next 800 Companies to Lead America's Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book "Blueprint to a 
Billion" shares his insights and actions to help propel your 
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev