PERFORCE change 102838 for review

Chris Jones cdjones at FreeBSD.org
Mon Jul 31 09:22:19 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=102838

Change 102838 by cdjones at cdjones-impulse on 2006/07/31 09:21:43

	Make -m argument denominated in MB.

Affected files ...

.. //depot/projects/soc2006/cdjones_jail/src/sys/kern/kern_jail.c#16 edit
.. //depot/projects/soc2006/cdjones_jail/src/usr.sbin/jail/jail.c#7 edit

Differences ...

==== //depot/projects/soc2006/cdjones_jail/src/sys/kern/kern_jail.c#16 (text+ko) ====

@@ -104,19 +104,19 @@
 {
   struct prison *pr;
   pr = arg;
-
-  printf("Starting jsched_td\n");
-
+  
+/*  printf("Starting jsched_td\n"); */
+  
   for (;;) {
     if (pr->pr_scheduler_flags & J_SCHED_TD_DIE) 
       break;
-
+    
     /* Scheduling stuff goes here. */
-    printf("jsched_td running\n");
+/*    printf("jsched_td running\n"); */
     tsleep(pr, 0, "-", hz);
   }
 
-  printf("Exiting jsched_td\n");
+/*  printf("Exiting jsched_td\n"); */
 
   pr->pr_scheduler_flags = J_SCHED_TD_DEAD;
   kthread_exit(0);
@@ -130,17 +130,16 @@
   struct thread *td;
   vm_pindex_t limit, size, usage;
   int breakout;
-
+  
   pr = arg;
-
-  printf("Starting jpager_td\n");
-
+  
+  printf("Starting jpager/%d with memory limit %ld bytes\n", 
+         pr->pr_id, (long)  prison_memory_limit(pr));
+  
   for (;;) {
-    printf("jpager_td running\n");
-
     if (pr->pr_pager_flags & J_PAGER_TD_DIE)
       break;
-
+    
     /* TODO: consider whether it might be better to start
      * pushing back when we approach the limit, rather than
      * when we hit it.
@@ -148,68 +147,75 @@
     limit = prison_memory_limit(pr);
     usage = prison_memory(pr);
 
-    if ((usage - limit) > 0)
-      continue;
-
     /* The logic from vm_daemon() really needs to go here.
      * Problem: we want to push things below their rlimits.
      *
      * TODO: refactor vm_daemon to optionally act on specific jails?
      */
-    
-    sx_slock(&allproc_lock);
-    LIST_FOREACH(p, &allproc, p_list) {
-      
-      if (pr != p->p_ucred->cr_prison)
-	continue;
-      
-      PROC_LOCK(p);
-      if (p->p_flag & (P_SYSTEM | P_WEXIT)) {
-	PROC_UNLOCK(p);
-	continue;
-      }
-      
-      mtx_lock_spin(&sched_lock);
-      breakout = 0;
-      FOREACH_THREAD_IN_PROC(p, td) {
-	if (!TD_ON_RUNQ(td) &&
-	    !TD_IS_RUNNING(td) &&
-	    !TD_IS_SLEEPING(td)) {
-	  breakout = 1;
-	  break;
-	}
-      }
-      mtx_unlock_spin(&sched_lock);
-      if (breakout) {
-	PROC_UNLOCK(p);
-	continue;
-      }
 
-      /* NOTE: we differ here from vm_daemon b/c we don't 
-       * care about the rlimit; things that are exceeding that will
-       * get caught in due course.  We need, however, to decrease
-       * the pressure on our permitted memory allocation.  Fortunately, 
-       * we only care about eventually hitting the limit, so if we
-       * don't get there right away, it's okay.
-       */      
+    printf("jthread/%d: memory %ld / %ld bytes\n", 
+           pr->pr_id, (long) usage, (long) limit);
 
-      /* TODO: this arbitrarily reduces each process's space by
-       * one page (until it's completely swapped out) while
-       * we're under memory pressure.  A better way would be 
-       * to either hit large processes first, or to hit the
-       * least-active processes first, or .... 
-       */
-      size = vmspace_resident_count(p->p_vmspace) - 1;
-      if (size < 0)
-	size = 0;
-      vm_pageout_map_deactivate_pages(&p->p_vmspace->vm_map, size);
-      
-      sx_sunlock(&allproc_lock);
+    if ((usage - limit) > 0) {
+      printf("jthread/%d: overcommitted by %ld bytes (%d %%)\n",
+             pr->pr_id, (long) (usage - limit), 
+	     (int) (100 * (usage - limit) / limit));
+      sx_slock(&allproc_lock);
+      LIST_FOREACH(p, &allproc, p_list) {
+	
+	if (pr != p->p_ucred->cr_prison)
+	  continue;
+	
+	PROC_LOCK(p);
+	if (p->p_flag & (P_SYSTEM | P_WEXIT)) {
+	  PROC_UNLOCK(p);
+	  continue;
+	}
+	
+	mtx_lock_spin(&sched_lock);
+	breakout = 0;
+	FOREACH_THREAD_IN_PROC(p, td) {
+	  if (!TD_ON_RUNQ(td) &&
+	      !TD_IS_RUNNING(td) &&
+	      !TD_IS_SLEEPING(td)) {
+	    breakout = 1;
+	    break;
+	  }
+	}
+	mtx_unlock_spin(&sched_lock);
+	if (breakout) {
+	  PROC_UNLOCK(p);
+	  continue;
+	}
+	
+	/* NOTE: we differ here from vm_daemon b/c we don't 
+	 * care about the rlimit; things that are exceeding that will
+	 * get caught in due course.  We need, however, to decrease
+	 * the pressure on our permitted memory allocation.  Fortunately, 
+	 * we only care about eventually hitting the limit, so if we
+	 * don't get there right away, it's okay.
+	 */      
+	
+	/* TODO: this arbitrarily reduces each process's space by
+	 * one page (until it's completely swapped out) while
+	 * we're under memory pressure.  A better way would be 
+	 * to either hit large processes first, or to hit the
+	 * least-active processes first, or go proportionally,
+         * .... 
+	 */
+	size = vmspace_resident_count(p->p_vmspace) - 1;
+	if (size < 0)
+	  size = 0;
+	printf("jpager_td: squeezing process %d to %ld\n", p->p_pid, (long) size);
+	vm_pageout_map_deactivate_pages(&p->p_vmspace->vm_map, (long) size);
+	
+	sx_sunlock(&allproc_lock);
+      } /* end LIST_FOREACH procs */
     }
     
-    /* TODO --- make interval into a sysctl? */
+    /* TODO --- make interval into a sysctl. */
     printf("jpager_td sleeping\n");
-    tsleep(pr, 0, "-", hz); 
+    tsleep(pr, 0, "-", 5 * hz); 
   }
 
   printf("Exiting jpager_td\n");
@@ -427,6 +433,7 @@
 
 		/* Tell scheduler to die.  No need to wait for it. */
 		pr->pr_scheduler_flags |= J_SCHED_TD_DIE;
+		pr->pr_pager_flags |= J_PAGER_TD_DIE;
 		wakeup(pr);
 
 		TASK_INIT(&pr->pr_task, 0, prison_complete, pr);
@@ -563,9 +570,9 @@
 
   /* Convert to bytes, cache (maybe unncessary?). */
   mem_used *= PAGE_SIZE;
-  mtx_lock(&pr->pr_mtx);
+  /*  mtx_lock(&pr->pr_mtx);
   pr->pr_mem_usage = mem_used;
-  mtx_unlock(&pr->pr_mtx);
+  mtx_unlock(&pr->pr_mtx); */
   return mem_used;
 }
 

==== //depot/projects/soc2006/cdjones_jail/src/usr.sbin/jail/jail.c#7 (text+ko) ====

@@ -80,7 +80,9 @@
 			Jflag = 1;
 			break;
 		case 'm':
+			/* TODO --- should this be specified in MB? */
 			mem_limit = atoi(optarg);
+			mem_limit *= 1024 * 1024;
 			break;
 		case 'p':
 			priority = atoi(optarg);


More information about the p4-projects mailing list