NetBSD Problem Report #38828

From  Mon Jun  2 09:14:35 2008
Return-Path: <>
Received: from ( [])
	by (Postfix) with ESMTP id 2546B63BA89
	for <>; Mon,  2 Jun 2008 09:14:35 +0000 (UTC)
Message-Id: <>
Date: Mon,  2 Jun 2008 01:13:04 +0000 (UTC)
Subject: uvm_swapout_threads seems broken
X-Send-Pr-Version: www-1.0

>Number:         38828
>Category:       kern
>Synopsis:       uvm_swapout_threads seems broken
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jun 02 09:15:00 +0000 2008
>Closed-Date:    Wed Oct 21 22:20:31 +0000 2009
>Last-Modified:  Wed Oct 21 22:20:31 +0000 2009
>Originator:     Andrew Doran
>Release:        4.99.62
The NetBSD Project
uvm_swapout_threads() scans the global lwp list, releases proc_lock and
then tries to swap out a chosen thread. There is nothing to stop the
chosen thread from disappearing after proc_lock is released.

Code inspection.
- Add some complicated code to handle it.


- Kill the idea of swapping out kernel stacks. There are many other data 
  structures that could be swapped, and it seems that in the year 2008 KVA 
  space shortage on 32 bit platforms is a bigger problem. Additionally, we 
  regularly run into kernel bugs where it's expected that the stack won't 
  be swapped out, but it can be.


From: Mindaugas Rasiukevicius <>
Subject: PR/38828 CVS commit: src
Date: Wed, 21 Oct 2009 21:12:10 +0000

 Module Name:	src
 Committed By:	rmind
 Date:		Wed Oct 21 21:12:07 UTC 2009

 Modified Files:
 	src/bin/ps: keyword.c print.c ps.1
 	src/external/bsd/top/dist/machine: m_netbsd.c
 	src/lib/libkvm: kvm_proc.c
 	src/share/man/man9: uvm.9
 	src/sys/arch/acorn26/acorn26: pmap.c vm_machdep.c
 	src/sys/arch/alpha/alpha: db_trace.c pmap.c vm_machdep.c
 	src/sys/arch/amd64/amd64: db_trace.c
 	src/sys/arch/amiga/amiga: pmap.c
 	src/sys/arch/amiga/include: cpu.h
 	src/sys/arch/arc: TODO
 	src/sys/arch/arm/arm: db_trace.c syscall.c
 	src/sys/arch/arm/arm32: pmap.c vm_machdep.c
 	src/sys/arch/atari/atari: pmap.c
 	src/sys/arch/atari/include: cpu.h
 	src/sys/arch/cesfic/include: cpu.h
 	src/sys/arch/evbmips/conf: std.gdium
 	src/sys/arch/hp300/include: cpu.h
 	src/sys/arch/hppa/hppa: db_trace.c pmap.c vm_machdep.c
 	src/sys/arch/i386/i386: db_trace.c process_machdep.c
 	src/sys/arch/ia64/ia64: pmap.c vm_machdep.c
 	src/sys/arch/luna68k/include: cpu.h
 	src/sys/arch/m68k/m68k: db_trace.c pmap_motorola.c
 	src/sys/arch/mac68k/include: cpu.h
 	src/sys/arch/mips/include: cpu.h types.h
 	src/sys/arch/mips/mips: db_trace.c mipsX_subr.S pmap.c vm_machdep.c
 	src/sys/arch/mvme68k/include: cpu.h
 	src/sys/arch/news68k/include: cpu.h
 	src/sys/arch/next68k/include: cpu.h
 	src/sys/arch/powerpc/ibm4xx: pmap.c trap.c
 	src/sys/arch/powerpc/include: cpu.h
 	src/sys/arch/powerpc/include/oea: pmap.h
 	src/sys/arch/powerpc/oea: pmap.c
 	src/sys/arch/powerpc/powerpc: db_trace.c process_machdep.c
 	src/sys/arch/sh3/include: cpu.h pmap.h types.h
 	src/sys/arch/sh3/sh3: process_machdep.c
 	src/sys/arch/sparc/include: cpu.h pmap.h
 	src/sys/arch/sparc/sparc: db_trace.c pmap.c
 	src/sys/arch/sparc64/conf: NONPLUS64
 	src/sys/arch/sparc64/include: cpu.h
 	src/sys/arch/sparc64/sparc64: db_trace.c machdep.c pmap.c
 	src/sys/arch/sun2/sun2: pmap.c
 	src/sys/arch/sun3/sun3: pmap.c
 	src/sys/arch/sun3/sun3x: pmap.c
 	src/sys/arch/sun68k/include: cpu.h
 	src/sys/arch/usermode/include: cpu.h
 	src/sys/arch/usermode/usermode: pmap.c
 	src/sys/arch/vax/include: pmap.h
 	src/sys/arch/vax/vax: machdep.c pmap.c
 	src/sys/arch/x68k/include: cpu.h
 	src/sys/arch/x86/x86: pmap.c syscall.c vm_machdep.c
 	src/sys/compat/linux/arch/i386: linux_ptrace.c
 	src/sys/compat/linux/arch/powerpc: linux_ptrace.c
 	src/sys/compat/mach: mach_thread.c
 	src/sys/compat/sa: compat_sa.c
 	src/sys/conf: std
 	src/sys/dev/i2o: iop.c
 	src/sys/dev/ic: dpt.c rrunner.c
 	src/sys/dev/scsipi: cd.c ch.c if_se.c scsiconf.c scsipi_base.c
 	    scsipiconf.h sd.c ss_mustek.c ss_scanjet.c st.c st_atapi.c
 	src/sys/dev/usb: umass_scsipi.c
 	src/sys/kern: core_elf32.c init_sysctl.c kern_condvar.c kern_fork.c
 	    kern_kthread.c kern_lwp.c kern_proc.c kern_runq.c kern_sleepq.c
 	    kern_synch.c kern_turnstile.c subr_percpu.c subr_workqueue.c
 	    sys_aio.c sys_lwp.c sys_process.c sys_select.c
 	src/sys/miscfs/genfs: genfs_io.c
 	src/sys/miscfs/procfs: procfs_ctl.c procfs_status.c
 	src/sys/nfs: nfs_syscalls.c nfs_vnops.c
 	src/sys/rump/librump/rumpkern: vm.c
 	src/sys/sys: lwp.h sleepq.h syncobj.h vmmeter.h
 	src/sys/uvm: files.uvm uvm.h uvm_amap.c uvm_aobj.c uvm_extern.h
 	    uvm_glue.c uvm_init.c uvm_meter.c uvm_pdaemon.c uvm_pmap.h
 	    uvm_stat.c uvm_swap.c
 	src/usr.bin/systat: pigs.c ps.c systat.1 vmstat.c
 	src/usr.bin/vmstat: vmstat.1 vmstat.c

 Log Message:
 Remove uarea swap-out functionality:

 - Addresses the issue described in PR/38828.
 - Some simplification in threading and sleepq subsystems.
 - Eliminates pmap_collect() and, as a side note, allows pmap optimisations.
 - Eliminates XS_CTL_DATA_ONSTACK in scsipi code.
 - Avoids few scans on LWP list and thus potentially long holds of proc_lock.
 - Cuts ~1.5k lines of code.  Reduces amd64 kernel size by ~4k.
 - Removes __SWAP_BROKEN cases.

 Tested on x86, mips, acorn32 (thanks <mpumford>) and partly tested on
 acorn26 (thanks to <bjh21>).

 Discussed on <tech-kern>, reviewed by <ad>.

 To generate a diff of this commit:
 cvs rdiff -u -r1.52 -r1.53 src/bin/ps/keyword.c
 cvs rdiff -u -r1.111 -r1.112 src/bin/ps/print.c
 cvs rdiff -u -r1.89 -r1.90 src/bin/ps/ps.1
 cvs rdiff -u -r1.10 -r1.11 src/external/bsd/top/dist/machine/m_netbsd.c
 cvs rdiff -u -r1.83 -r1.84 src/lib/libkvm/kvm_proc.c
 cvs rdiff -u -r1.98 -r1.99 src/share/man/man9/uvm.9
 cvs rdiff -u -r1.28 -r1.29 src/sys/arch/acorn26/acorn26/pmap.c
 cvs rdiff -u -r1.21 -r1.22 src/sys/arch/acorn26/acorn26/vm_machdep.c
 cvs rdiff -u -r1.24 -r1.25 src/sys/arch/alpha/alpha/db_trace.c
 cvs rdiff -u -r1.243 -r1.244 src/sys/arch/alpha/alpha/pmap.c
 cvs rdiff -u -r1.100 -r1.101 src/sys/arch/alpha/alpha/vm_machdep.c
 cvs rdiff -u -r1.15 -r1.16 src/sys/arch/amd64/amd64/db_trace.c
 cvs rdiff -u -r1.154 -r1.155 src/sys/arch/amiga/amiga/pmap.c
 cvs rdiff -u -r1.72 -r1.73 src/sys/arch/amiga/include/cpu.h
 cvs rdiff -u -r1.27 -r1.28 src/sys/arch/arc/TODO
 cvs rdiff -u -r1.19 -r1.20 src/sys/arch/arm/arm/db_trace.c
 cvs rdiff -u -r1.48 -r1.49 src/sys/arch/arm/arm/syscall.c
 cvs rdiff -u -r1.198 -r1.199 src/sys/arch/arm/arm32/pmap.c
 cvs rdiff -u -r1.49 -r1.50 src/sys/arch/arm/arm32/vm_machdep.c
 cvs rdiff -u -r1.120 -r1.121 src/sys/arch/atari/atari/pmap.c
 cvs rdiff -u -r1.62 -r1.63 src/sys/arch/atari/include/cpu.h
 cvs rdiff -u -r1.22 -r1.23 src/sys/arch/cesfic/include/cpu.h
 cvs rdiff -u -r1.3 -r1.4 src/sys/arch/evbmips/conf/std.gdium
 cvs rdiff -u -r1.60 -r1.61 src/sys/arch/hp300/include/cpu.h
 cvs rdiff -u -r1.3 -r1.4 src/sys/arch/hppa/hppa/db_trace.c
 cvs rdiff -u -r1.52 -r1.53 src/sys/arch/hppa/hppa/pmap.c
 cvs rdiff -u -r1.36 -r1.37 src/sys/arch/hppa/hppa/vm_machdep.c
 cvs rdiff -u -r1.62 -r1.63 src/sys/arch/i386/i386/db_trace.c
 cvs rdiff -u -r1.70 -r1.71 src/sys/arch/i386/i386/process_machdep.c
 cvs rdiff -u -r1.21 -r1.22 src/sys/arch/ia64/ia64/pmap.c
 cvs rdiff -u -r1.6 -r1.7 src/sys/arch/ia64/ia64/vm_machdep.c
 cvs rdiff -u -r1.26 -r1.27 src/sys/arch/luna68k/include/cpu.h
 cvs rdiff -u -r1.53 -r1.54 src/sys/arch/m68k/m68k/db_trace.c
 cvs rdiff -u -r1.47 -r1.48 src/sys/arch/m68k/m68k/pmap_motorola.c
 cvs rdiff -u -r1.92 -r1.93 src/sys/arch/mac68k/include/cpu.h
 cvs rdiff -u -r1.90 -r1.91 src/sys/arch/mips/include/cpu.h
 cvs rdiff -u -r1.43 -r1.44 src/sys/arch/mips/include/types.h
 cvs rdiff -u -r1.35 -r1.36 src/sys/arch/mips/mips/db_trace.c
 cvs rdiff -u -r1.31 -r1.32 src/sys/arch/mips/mips/mipsX_subr.S
 cvs rdiff -u -r1.184 -r1.185 src/sys/arch/mips/mips/pmap.c
 cvs rdiff -u -r1.125 -r1.126 src/sys/arch/mips/mips/vm_machdep.c
 cvs rdiff -u -r1.42 -r1.43 src/sys/arch/mvme68k/include/cpu.h
 cvs rdiff -u -r1.34 -r1.35 src/sys/arch/news68k/include/cpu.h
 cvs rdiff -u -r1.40 -r1.41 src/sys/arch/next68k/include/cpu.h
 cvs rdiff -u -r1.57 -r1.58 src/sys/arch/powerpc/ibm4xx/pmap.c
 cvs rdiff -u -r1.51 -r1.52 src/sys/arch/powerpc/ibm4xx/trap.c
 cvs rdiff -u -r1.65 -r1.66 src/sys/arch/powerpc/include/cpu.h
 cvs rdiff -u -r1.16 -r1.17 src/sys/arch/powerpc/include/oea/pmap.h
 cvs rdiff -u -r1.66 -r1.67 src/sys/arch/powerpc/oea/pmap.c
 cvs rdiff -u -r1.48 -r1.49 src/sys/arch/powerpc/powerpc/db_trace.c
 cvs rdiff -u -r1.26 -r1.27 src/sys/arch/powerpc/powerpc/process_machdep.c
 cvs rdiff -u -r1.53 -r1.54 src/sys/arch/sh3/include/cpu.h
 cvs rdiff -u -r1.33 -r1.34 src/sys/arch/sh3/include/pmap.h
 cvs rdiff -u -r1.27 -r1.28 src/sys/arch/sh3/include/types.h
 cvs rdiff -u -r1.16 -r1.17 src/sys/arch/sh3/sh3/process_machdep.c
 cvs rdiff -u -r1.86 -r1.87 src/sys/arch/sparc/include/cpu.h
 cvs rdiff -u -r1.85 -r1.86 src/sys/arch/sparc/include/pmap.h
 cvs rdiff -u -r1.30 -r1.31 src/sys/arch/sparc/sparc/db_trace.c
 cvs rdiff -u -r1.334 -r1.335 src/sys/arch/sparc/sparc/pmap.c
 cvs rdiff -u -r1.28 -r1.29 src/sys/arch/sparc64/conf/NONPLUS64
 cvs rdiff -u -r1.86 -r1.87 src/sys/arch/sparc64/include/cpu.h
 cvs rdiff -u -r1.41 -r1.42 src/sys/arch/sparc64/sparc64/db_trace.c
 cvs rdiff -u -r1.244 -r1.245 src/sys/arch/sparc64/sparc64/machdep.c
 cvs rdiff -u -r1.238 -r1.239 src/sys/arch/sparc64/sparc64/pmap.c
 cvs rdiff -u -r1.39 -r1.40 src/sys/arch/sun2/sun2/pmap.c
 cvs rdiff -u -r1.160 -r1.161 src/sys/arch/sun3/sun3/pmap.c
 cvs rdiff -u -r1.106 -r1.107 src/sys/arch/sun3/sun3x/pmap.c
 cvs rdiff -u -r1.20 -r1.21 src/sys/arch/sun68k/include/cpu.h
 cvs rdiff -u -r1.2 -r1.3 src/sys/arch/usermode/include/cpu.h
 cvs rdiff -u -r1.3 -r1.4 src/sys/arch/usermode/usermode/pmap.c
 cvs rdiff -u -r1.76 -r1.77 src/sys/arch/vax/include/pmap.h
 cvs rdiff -u -r1.175 -r1.176 src/sys/arch/vax/vax/machdep.c
 cvs rdiff -u -r1.168 -r1.169 src/sys/arch/vax/vax/pmap.c
 cvs rdiff -u -r1.48 -r1.49 src/sys/arch/x68k/include/cpu.h
 cvs rdiff -u -r1.92 -r1.93 src/sys/arch/x86/x86/pmap.c
 cvs rdiff -u -r1.1 -r1.2 src/sys/arch/x86/x86/syscall.c \
 cvs rdiff -u -r1.23 -r1.24 src/sys/compat/linux/arch/i386/linux_ptrace.c
 cvs rdiff -u -r1.21 -r1.22 src/sys/compat/linux/arch/powerpc/linux_ptrace.c
 cvs rdiff -u -r1.48 -r1.49 src/sys/compat/mach/mach_thread.c
 cvs rdiff -u -r1.11 -r1.12 src/sys/compat/sa/compat_sa.c
 cvs rdiff -u -r1.12 -r1.13 src/sys/conf/std
 cvs rdiff -u -r1.76 -r1.77 src/sys/dev/i2o/iop.c
 cvs rdiff -u -r1.62 -r1.63 src/sys/dev/ic/dpt.c
 cvs rdiff -u -r1.71 -r1.72 src/sys/dev/ic/rrunner.c
 cvs rdiff -u -r1.294 -r1.295 src/sys/dev/scsipi/cd.c
 cvs rdiff -u -r1.84 -r1.85 src/sys/dev/scsipi/ch.c
 cvs rdiff -u -r1.78 -r1.79 src/sys/dev/scsipi/if_se.c
 cvs rdiff -u -r1.253 -r1.254 src/sys/dev/scsipi/scsiconf.c
 cvs rdiff -u -r1.149 -r1.150 src/sys/dev/scsipi/scsipi_base.c
 cvs rdiff -u -r1.115 -r1.116 src/sys/dev/scsipi/scsipiconf.h
 cvs rdiff -u -r1.289 -r1.290 src/sys/dev/scsipi/sd.c
 cvs rdiff -u -r1.38 -r1.39 src/sys/dev/scsipi/ss_mustek.c
 cvs rdiff -u -r1.49 -r1.50 src/sys/dev/scsipi/ss_scanjet.c
 cvs rdiff -u -r1.212 -r1.213 src/sys/dev/scsipi/st.c
 cvs rdiff -u -r1.24 -r1.25 src/sys/dev/scsipi/st_atapi.c
 cvs rdiff -u -r1.30 -r1.31 src/sys/dev/scsipi/st_scsi.c
 cvs rdiff -u -r1.34 -r1.35 src/sys/dev/usb/umass_scsipi.c
 cvs rdiff -u -r1.33 -r1.34 src/sys/kern/core_elf32.c
 cvs rdiff -u -r1.167 -r1.168 src/sys/kern/init_sysctl.c
 cvs rdiff -u -r1.26 -r1.27 src/sys/kern/kern_condvar.c \
     src/sys/kern/kern_kthread.c src/sys/kern/kern_runq.c
 cvs rdiff -u -r1.173 -r1.174 src/sys/kern/kern_fork.c
 cvs rdiff -u -r1.133 -r1.134 src/sys/kern/kern_lwp.c
 cvs rdiff -u -r1.154 -r1.155 src/sys/kern/kern_proc.c
 cvs rdiff -u -r1.36 -r1.37 src/sys/kern/kern_sleepq.c
 cvs rdiff -u -r1.270 -r1.271 src/sys/kern/kern_synch.c
 cvs rdiff -u -r1.25 -r1.26 src/sys/kern/kern_turnstile.c
 cvs rdiff -u -r1.9 -r1.10 src/sys/kern/subr_percpu.c
 cvs rdiff -u -r1.28 -r1.29 src/sys/kern/subr_workqueue.c \
 cvs rdiff -u -r1.45 -r1.46 src/sys/kern/sys_lwp.c
 cvs rdiff -u -r1.150 -r1.151 src/sys/kern/sys_process.c
 cvs rdiff -u -r1.15 -r1.16 src/sys/kern/sys_select.c
 cvs rdiff -u -r1.20 -r1.21 src/sys/miscfs/genfs/genfs_io.c
 cvs rdiff -u -r1.46 -r1.47 src/sys/miscfs/procfs/procfs_ctl.c
 cvs rdiff -u -r1.35 -r1.36 src/sys/miscfs/procfs/procfs_status.c
 cvs rdiff -u -r1.150 -r1.151 src/sys/nfs/nfs_syscalls.c
 cvs rdiff -u -r1.280 -r1.281 src/sys/nfs/nfs_vnops.c
 cvs rdiff -u -r1.63 -r1.64 src/sys/rump/librump/rumpkern/vm.c
 cvs rdiff -u -r1.120 -r1.121 src/sys/sys/lwp.h
 cvs rdiff -u -r1.16 -r1.17 src/sys/sys/sleepq.h
 cvs rdiff -u -r1.7 -r1.8 src/sys/sys/syncobj.h
 cvs rdiff -u -r1.18 -r1.19 src/sys/sys/vmmeter.h
 cvs rdiff -u -r1.15 -r1.16 src/sys/uvm/files.uvm
 cvs rdiff -u -r1.56 -r1.57 src/sys/uvm/uvm.h
 cvs rdiff -u -r1.87 -r1.88 src/sys/uvm/uvm_amap.c
 cvs rdiff -u -r1.107 -r1.108 src/sys/uvm/uvm_aobj.c
 cvs rdiff -u -r1.159 -r1.160 src/sys/uvm/uvm_extern.h
 cvs rdiff -u -r1.140 -r1.141 src/sys/uvm/uvm_glue.c
 cvs rdiff -u -r1.35 -r1.36 src/sys/uvm/uvm_init.c
 cvs rdiff -u -r1.49 -r1.50 src/sys/uvm/uvm_meter.c
 cvs rdiff -u -r1.99 -r1.100 src/sys/uvm/uvm_pdaemon.c
 cvs rdiff -u -r1.30 -r1.31 src/sys/uvm/uvm_pmap.h
 cvs rdiff -u -r1.31 -r1.32 src/sys/uvm/uvm_stat.c
 cvs rdiff -u -r1.146 -r1.147 src/sys/uvm/uvm_swap.c
 cvs rdiff -u -r1.30 -r1.31 src/usr.bin/systat/pigs.c
 cvs rdiff -u -r1.33 -r1.34 src/usr.bin/systat/ps.c
 cvs rdiff -u -r1.38 -r1.39 src/usr.bin/systat/systat.1
 cvs rdiff -u -r1.74 -r1.75 src/usr.bin/systat/vmstat.c
 cvs rdiff -u -r1.18 -r1.19 src/usr.bin/vmstat/vmstat.1
 cvs rdiff -u -r1.165 -r1.166 src/usr.bin/vmstat/vmstat.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-When: Wed, 21 Oct 2009 22:20:31 +0000
Fixed, uarea swap-out is now for historians.


NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD:,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.