From 88389d6103a728e508f8090b71c0bfef0bc66f8f Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Tue, 4 May 2010 05:14:43 +0000 Subject: 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. --- sys/vm/vm_fault.c | 21 +++++++++++++++------ sys/vm/vm_pageout.c | 4 ++-- 2 files changed, 17 insertions(+), 8 deletions(-) (limited to 'sys/vm') diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index 68057fb4f3fd..a8ff435f443d 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -217,7 +217,7 @@ vm_fault(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, vm_object_t next_object; vm_page_t marray[VM_FAULT_READ]; int hardfault; - int faultcount, ahead, behind; + int faultcount, ahead, behind, alloc_req; struct faultstate fs; struct vnode *vp; int locked, error; @@ -414,9 +414,14 @@ 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)) { #if VM_NRESERVLEVEL > 0 if ((fs.object->flags & OBJ_COLORED) == 0) { fs.object->flags |= OBJ_COLORED; @@ -424,10 +429,13 @@ RetryFault:; fs.pindex; } #endif + alloc_req = P_KILLED(curproc) ? + VM_ALLOC_SYSTEM : VM_ALLOC_NORMAL; + if (fs.object->type != OBJT_VNODE && + fs.object->backing_object == NULL) + alloc_req |= VM_ALLOC_ZERO; fs.m = vm_page_alloc(fs.object, fs.pindex, - (fs.object->type == OBJT_VNODE || - fs.object->backing_object != NULL) ? - VM_ALLOC_NORMAL : VM_ALLOC_ZERO); + alloc_req); } if (fs.m == NULL) { unlock_and_deallocate(&fs); @@ -452,7 +460,8 @@ readrest: int reqpage = 0; 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 { diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c index 723b14d2175a..dc2b3b77d569 100644 --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -1206,10 +1206,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; -- cgit v1.3