From owner-svn-src-all@FreeBSD.ORG Sun Apr 11 16:26:08 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 56187106566B; Sun, 11 Apr 2010 16:26:08 +0000 (UTC) (envelope-from alc@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 45A7F8FC20; Sun, 11 Apr 2010 16:26:08 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o3BGQ89T049336; Sun, 11 Apr 2010 16:26:08 GMT (envelope-from alc@svn.freebsd.org) Received: (from alc@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o3BGQ8Ah049332; Sun, 11 Apr 2010 16:26:08 GMT (envelope-from alc@svn.freebsd.org) Message-Id: <201004111626.o3BGQ8Ah049332@svn.freebsd.org> From: Alan Cox Date: Sun, 11 Apr 2010 16:26:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r206483 - in head/sys: kern vm X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Apr 2010 16:26:08 -0000 Author: alc Date: Sun Apr 11 16:26:07 2010 New Revision: 206483 URL: http://svn.freebsd.org/changeset/base/206483 Log: Initialize the virtual memory-related resource limits in a single place. Previously, one of these limits was initialized in two places to a different value in each place. Moreover, because an unsigned int was used to represent the amount of pageable physical memory, some of these limits were incorrectly initialized on 64-bit architectures. (Currently, this error is masked by login.conf's default settings.) Make vm_thread_swapin() and vm_thread_swapout() static. Submitted by: bde (an earlier version) Reviewed by: kib Modified: head/sys/kern/init_main.c head/sys/vm/vm_extern.h head/sys/vm/vm_glue.c Modified: head/sys/kern/init_main.c ============================================================================== --- head/sys/kern/init_main.c Sun Apr 11 16:06:09 2010 (r206482) +++ head/sys/kern/init_main.c Sun Apr 11 16:26:07 2010 (r206483) @@ -382,8 +382,9 @@ static void proc0_init(void *dummy __unused) { struct proc *p; - unsigned i; struct thread *td; + vm_paddr_t pageablemem; + int i; GIANT_REQUIRED; p = &proc0; @@ -493,10 +494,16 @@ proc0_init(void *dummy __unused) p->p_limit->pl_rlimit[RLIMIT_NOFILE].rlim_max = maxfiles; p->p_limit->pl_rlimit[RLIMIT_NPROC].rlim_cur = p->p_limit->pl_rlimit[RLIMIT_NPROC].rlim_max = maxproc; - i = ptoa(cnt.v_free_count); - p->p_limit->pl_rlimit[RLIMIT_RSS].rlim_max = i; - p->p_limit->pl_rlimit[RLIMIT_MEMLOCK].rlim_max = i; - p->p_limit->pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = i / 3; + p->p_limit->pl_rlimit[RLIMIT_DATA].rlim_cur = dfldsiz; + p->p_limit->pl_rlimit[RLIMIT_DATA].rlim_max = maxdsiz; + p->p_limit->pl_rlimit[RLIMIT_STACK].rlim_cur = dflssiz; + p->p_limit->pl_rlimit[RLIMIT_STACK].rlim_max = maxssiz; + /* Cast to avoid overflow on i386/PAE. */ + pageablemem = ptoa((vm_paddr_t)cnt.v_free_count); + p->p_limit->pl_rlimit[RLIMIT_RSS].rlim_cur = + p->p_limit->pl_rlimit[RLIMIT_RSS].rlim_max = pageablemem; + p->p_limit->pl_rlimit[RLIMIT_MEMLOCK].rlim_cur = pageablemem / 3; + p->p_limit->pl_rlimit[RLIMIT_MEMLOCK].rlim_max = pageablemem; p->p_cpulimit = RLIM_INFINITY; p->p_stats = pstats_alloc(); Modified: head/sys/vm/vm_extern.h ============================================================================== --- head/sys/vm/vm_extern.h Sun Apr 11 16:06:09 2010 (r206482) +++ head/sys/vm/vm_extern.h Sun Apr 11 16:26:07 2010 (r206483) @@ -84,7 +84,5 @@ struct sf_buf *vm_imgact_map_page(vm_obj void vm_imgact_unmap_page(struct sf_buf *sf); void vm_thread_dispose(struct thread *td); int vm_thread_new(struct thread *td, int pages); -void vm_thread_swapin(struct thread *td); -void vm_thread_swapout(struct thread *td); #endif /* _KERNEL */ #endif /* !_VM_EXTERN_H_ */ Modified: head/sys/vm/vm_glue.c ============================================================================== --- head/sys/vm/vm_glue.c Sun Apr 11 16:06:09 2010 (r206482) +++ head/sys/vm/vm_glue.c Sun Apr 11 16:26:07 2010 (r206483) @@ -99,12 +99,6 @@ extern int maxslp; /* * System initialization * - * Note: proc0 from proc.h - */ -static void vm_init_limits(void *); -SYSINIT(vm_limits, SI_SUB_VM_CONF, SI_ORDER_FIRST, vm_init_limits, &proc0); - -/* * THIS MUST BE THE LAST INITIALIZATION ITEM!!! * * Note: run scheduling should be divorced from the vm system. @@ -115,6 +109,8 @@ SYSINIT(scheduler, SI_SUB_RUN_SCHEDULER, #ifndef NO_SWAPPING static int swapout(struct proc *); static void swapclear(struct proc *); +static void vm_thread_swapin(struct thread *td); +static void vm_thread_swapout(struct thread *td); #endif /* @@ -498,10 +494,11 @@ kstack_cache_init(void *nulll) MTX_SYSINIT(kstack_cache, &kstack_cache_mtx, "kstkch", MTX_DEF); SYSINIT(vm_kstacks, SI_SUB_KTHREAD_INIT, SI_ORDER_ANY, kstack_cache_init, NULL); +#ifndef NO_SWAPPING /* * Allow a thread's kernel stack to be paged out. */ -void +static void vm_thread_swapout(struct thread *td) { vm_object_t ksobj; @@ -528,7 +525,7 @@ vm_thread_swapout(struct thread *td) /* * Bring the kernel stack for a specified thread back in. */ -void +static void vm_thread_swapin(struct thread *td) { vm_object_t ksobj; @@ -556,6 +553,7 @@ vm_thread_swapin(struct thread *td) pmap_qenter(td->td_kstack, ma, pages); cpu_thread_swapin(td); } +#endif /* !NO_SWAPPING */ /* * Implement fork's actions on an address space. @@ -629,38 +627,6 @@ vm_waitproc(p) vmspace_exitfree(p); /* and clean-out the vmspace */ } -/* - * Set default limits for VM system. - * Called for proc 0, and then inherited by all others. - * - * XXX should probably act directly on proc0. - */ -static void -vm_init_limits(udata) - void *udata; -{ - struct proc *p = udata; - struct plimit *limp; - int rss_limit; - - /* - * Set up the initial limits on process VM. Set the maximum resident - * set size to be half of (reasonably) available memory. Since this - * is a soft limit, it comes into effect only when the system is out - * of memory - half of main memory helps to favor smaller processes, - * and reduces thrashing of the object cache. - */ - limp = p->p_limit; - limp->pl_rlimit[RLIMIT_STACK].rlim_cur = dflssiz; - limp->pl_rlimit[RLIMIT_STACK].rlim_max = maxssiz; - limp->pl_rlimit[RLIMIT_DATA].rlim_cur = dfldsiz; - limp->pl_rlimit[RLIMIT_DATA].rlim_max = maxdsiz; - /* limit the limit to no less than 2MB */ - rss_limit = max(cnt.v_free_count, 512); - limp->pl_rlimit[RLIMIT_RSS].rlim_cur = ptoa(rss_limit); - limp->pl_rlimit[RLIMIT_RSS].rlim_max = RLIM_INFINITY; -} - void faultin(p) struct proc *p;