svn commit: r208319 - in stable/6/sys: kern sys vm

Attilio Rao attilio at FreeBSD.org
Wed May 19 22:36:47 UTC 2010


Author: attilio
Date: Wed May 19 22:36:46 2010
New Revision: 208319
URL: http://svn.freebsd.org/changeset/base/208319

Log:
  MFC: r206264
  When OOM searches for a process to kill, ignore the processes already
  killed by OOM. When killed process waits for a page allocation, try to
  satisfy the request as fast as possible.
  
  Sponsored by:	Sandvine Incorporated

Modified:
  stable/6/sys/kern/kern_sig.c
  stable/6/sys/sys/proc.h
  stable/6/sys/vm/vm_fault.c
  stable/6/sys/vm/vm_pageout.c
Directory Properties:
  stable/6/sys/   (props changed)
  stable/6/sys/contrib/pf/   (props changed)
  stable/6/sys/dev/cxgb/   (props changed)

Modified: stable/6/sys/kern/kern_sig.c
==============================================================================
--- stable/6/sys/kern/kern_sig.c	Wed May 19 22:03:45 2010	(r208318)
+++ stable/6/sys/kern/kern_sig.c	Wed May 19 22:36:46 2010	(r208319)
@@ -2408,6 +2408,7 @@ killproc(p, why)
 		p, p->p_pid, p->p_comm);
 	log(LOG_ERR, "pid %d (%s), uid %d, was killed: %s\n", p->p_pid, p->p_comm,
 		p->p_ucred ? p->p_ucred->cr_uid : -1, why);
+	p->p_flag |= P_WKILLED;
 	psignal(p, SIGKILL);
 }
 

Modified: stable/6/sys/sys/proc.h
==============================================================================
--- stable/6/sys/sys/proc.h	Wed May 19 22:03:45 2010	(r208318)
+++ stable/6/sys/sys/proc.h	Wed May 19 22:36:46 2010	(r208319)
@@ -654,11 +654,13 @@ struct proc {
 #define	P_HWPMC		0x800000 /* Process is using HWPMCs */
 
 #define	P_JAILED	0x1000000 /* Process is in jail. */
+#define	P_WKILLED	0x2000000 /* Killed, go to kernel/user boundary ASAP. */
 #define	P_INEXEC	0x4000000 /* Process is in execve(). */
 #define	P_STATCHILD	0x8000000 /* Child process stopped or exited. */
 
 #define	P_STOPPED	(P_STOPPED_SIG|P_STOPPED_SINGLE|P_STOPPED_TRACE)
 #define	P_SHOULDSTOP(p)	((p)->p_flag & P_STOPPED)
+#define	P_KILLED(p)	((p)->p_flag & P_WKILLED)
 
 /* These flags are kept in p_sflag and are protected with sched_lock. */
 #define	PS_INMEM	0x00001	/* Loaded into memory. */

Modified: stable/6/sys/vm/vm_fault.c
==============================================================================
--- stable/6/sys/vm/vm_fault.c	Wed May 19 22:03:45 2010	(r208318)
+++ stable/6/sys/vm/vm_fault.c	Wed May 19 22:36:46 2010	(r208319)
@@ -218,7 +218,7 @@ vm_fault(vm_map_t map, vm_offset_t vaddr
 	vm_object_t next_object;
 	vm_page_t marray[VM_FAULT_READ];
 	int hardfault;
-	int faultcount;
+	int faultcount, alloc_req;
 	struct faultstate fs;
 
 	hardfault = 0;
@@ -449,11 +449,21 @@ RetryFault:;
 
 			/*
 			 * Allocate a new page for this object/offset pair.
+			 *
+			 * Unlocked read of the p_flag is harmless. At
+			 * worst, the P_KILLED might be not observed
+			 * there, and allocation can fail, causing
+			 * restart and new reading of the p_flag.
 			 */
 			fs.m = NULL;
-			if (!vm_page_count_severe()) {
+			if (!vm_page_count_severe() || P_KILLED(curproc)) {
+				alloc_req = P_KILLED(curproc) ?
+				    VM_ALLOC_SYSTEM : VM_ALLOC_NORMAL;
+				if (fs.vp == NULL &&
+				    fs.object->backing_object == NULL)
+					alloc_req |= VM_ALLOC_ZERO;
 				fs.m = vm_page_alloc(fs.object, fs.pindex,
-				    (fs.vp || fs.object->backing_object)? VM_ALLOC_NORMAL: VM_ALLOC_ZERO);
+				    alloc_req);
 			}
 			if (fs.m == NULL) {
 				unlock_and_deallocate(&fs);
@@ -478,7 +488,8 @@ readrest:
 			int ahead, behind;
 			u_char behavior = vm_map_entry_behavior(fs.entry);
 
-			if (behavior == MAP_ENTRY_BEHAV_RANDOM) {
+			if (behavior == MAP_ENTRY_BEHAV_RANDOM ||
+			    P_KILLED(curproc)) {
 				ahead = 0;
 				behind = 0;
 			} else {

Modified: stable/6/sys/vm/vm_pageout.c
==============================================================================
--- stable/6/sys/vm/vm_pageout.c	Wed May 19 22:03:45 2010	(r208318)
+++ stable/6/sys/vm/vm_pageout.c	Wed May 19 22:36:46 2010	(r208319)
@@ -1276,10 +1276,10 @@ vm_pageout_oom(int shortage)
 		if (PROC_TRYLOCK(p) == 0)
 			continue;
 		/*
-		 * If this is a system or protected process, skip it.
+		 * If this is a system, protected or killed process, skip it.
 		 */
 		if ((p->p_flag & (P_INEXEC | P_PROTECTED | P_SYSTEM)) ||
-		    (p->p_pid == 1) ||
+		    (p->p_pid == 1) || P_KILLED(p) ||
 		    ((p->p_pid < 48) && (swap_pager_avail != 0))) {
 			PROC_UNLOCK(p);
 			continue;


More information about the svn-src-all mailing list