Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Jan 2012 07:57:28 +0000 (UTC)
From:      Alan Cox <alc@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r230420 - stable/7/sys/kern
Message-ID:  <201201210757.q0L7vS0h080930@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: alc
Date: Sat Jan 21 07:57:27 2012
New Revision: 230420
URL: http://svn.freebsd.org/changeset/base/230420

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/7/sys/kern/kern_malloc.c
Directory Properties:
  stable/7/sys/   (props changed)
  stable/7/sys/cddl/contrib/opensolaris/   (props changed)
  stable/7/sys/contrib/dev/acpica/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)

Modified: stable/7/sys/kern/kern_malloc.c
==============================================================================
--- stable/7/sys/kern/kern_malloc.c	Sat Jan 21 07:21:44 2012	(r230419)
+++ stable/7/sys/kern/kern_malloc.c	Sat Jan 21 07:57:27 2012	(r230420)
@@ -258,8 +258,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));
 }
@@ -594,12 +594,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.
@@ -640,11 +637,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;
 
 	/*
 	 * Tune settings based on the kmem map's size at this time.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201201210757.q0L7vS0h080930>