From owner-svn-src-all@FreeBSD.ORG Sat Jan 21 05:03:10 2012 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 C02C31065674; Sat, 21 Jan 2012 05:03:10 +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 A5F848FC08; Sat, 21 Jan 2012 05:03:10 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q0L53Ad9075149; Sat, 21 Jan 2012 05:03:10 GMT (envelope-from alc@svn.freebsd.org) Received: (from alc@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q0L53ACK075146; Sat, 21 Jan 2012 05:03:10 GMT (envelope-from alc@svn.freebsd.org) Message-Id: <201201210503.q0L53ACK075146@svn.freebsd.org> From: Alan Cox Date: Sat, 21 Jan 2012 05:03:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r230418 - stable/9/sys/kern 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: Sat, 21 Jan 2012 05:03:11 -0000 Author: alc Date: Sat Jan 21 05:03:10 2012 New Revision: 230418 URL: http://svn.freebsd.org/changeset/base/230418 Log: MFC r226163, r228317, and r228324 Fix the handling of an empty kmem map by sysctl_kmem_map_free(). Eliminate the possibility of 32-bit arithmetic overflow in the calculation of vm_kmem_size that may occur if the system administrator has specified a vm.vm_kmem_size tunable value that exceeds the hard cap. Eliminate stale numbers from a comment. PR: 162741 Modified: stable/9/sys/kern/kern_malloc.c Directory Properties: stable/9/sys/ (props changed) stable/9/sys/amd64/include/xen/ (props changed) stable/9/sys/boot/ (props changed) stable/9/sys/boot/i386/efi/ (props changed) stable/9/sys/boot/ia64/efi/ (props changed) stable/9/sys/boot/ia64/ski/ (props changed) stable/9/sys/boot/powerpc/boot1.chrp/ (props changed) stable/9/sys/boot/powerpc/ofw/ (props changed) stable/9/sys/cddl/contrib/opensolaris/ (props changed) stable/9/sys/conf/ (props changed) stable/9/sys/contrib/dev/acpica/ (props changed) stable/9/sys/contrib/octeon-sdk/ (props changed) stable/9/sys/contrib/pf/ (props changed) stable/9/sys/contrib/x86emu/ (props changed) Modified: stable/9/sys/kern/kern_malloc.c ============================================================================== --- stable/9/sys/kern/kern_malloc.c Sat Jan 21 04:24:19 2012 (r230417) +++ stable/9/sys/kern/kern_malloc.c Sat Jan 21 05:03:10 2012 (r230418) @@ -265,8 +265,8 @@ sysctl_kmem_map_free(SYSCTL_HANDLER_ARGS u_long size; vm_map_lock_read(kmem_map); - size = kmem_map->root != NULL ? - kmem_map->root->max_free : kmem_map->size; + size = kmem_map->root != NULL ? kmem_map->root->max_free : + kmem_map->max_offset - kmem_map->min_offset; vm_map_unlock_read(kmem_map); return (sysctl_handle_long(oidp, &size, 0, req)); } @@ -661,12 +661,9 @@ kmeminit(void *dummy) /* * Try to auto-tune the kernel memory size, so that it is - * more applicable for a wider range of machine sizes. - * On an X86, a VM_KMEM_SIZE_SCALE value of 4 is good, while - * a VM_KMEM_SIZE of 12MB is a fair compromise. The + * more applicable for a wider range of machine sizes. The * VM_KMEM_SIZE_MAX is dependent on the maximum KVA space - * available, and on an X86 with a total KVA space of 256MB, - * try to keep VM_KMEM_SIZE_MAX at 80MB or below. + * available. * * Note that the kmem_map is also used by the zone allocator, * so make sure that there is enough space. @@ -703,11 +700,11 @@ kmeminit(void *dummy) /* * Limit kmem virtual size to twice the physical memory. * This allows for kmem map sparseness, but limits the size - * to something sane. Be careful to not overflow the 32bit - * ints while doing the check. + * to something sane. Be careful to not overflow the 32bit + * ints while doing the check or the adjustment. */ - if (((vm_kmem_size / 2) / PAGE_SIZE) > cnt.v_page_count) - vm_kmem_size = 2 * cnt.v_page_count * PAGE_SIZE; + if (vm_kmem_size / 2 / PAGE_SIZE > mem_size) + vm_kmem_size = 2 * mem_size * PAGE_SIZE; #ifdef DEBUG_MEMGUARD tmp = memguard_fudge(vm_kmem_size, vm_kmem_size_max);