Date: Fri, 16 May 2014 01:30:30 +0000 (UTC) From: Ian Lepore <ian@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r266204 - in stable/10/sys: amd64/include arm/include i386/include ia64/include kern mips/include powerpc/include sparc64/include Message-ID: <201405160130.s4G1UUl4025373@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ian Date: Fri May 16 01:30:30 2014 New Revision: 266204 URL: http://svnweb.freebsd.org/changeset/base/266204 Log: MFC r257854 (discussed with alc@) As of r257209, all architectures have defined VM_KMEM_SIZE_SCALE. In other words, every architecture is now auto-sizing the kmem arena. This revision changes kmeminit() so that the definition of VM_KMEM_SIZE_SCALE becomes mandatory and the definition of VM_KMEM_SIZE becomes optional. Replace or eliminate all existing definitions of VM_KMEM_SIZE. With auto-sizing enabled, VM_KMEM_SIZE effectively became an alternate spelling for VM_KMEM_SIZE_MIN on most architectures. Use VM_KMEM_SIZE_MIN for clarity. Modified: stable/10/sys/amd64/include/vmparam.h stable/10/sys/arm/include/vmparam.h stable/10/sys/i386/include/vmparam.h stable/10/sys/ia64/include/vmparam.h stable/10/sys/kern/kern_malloc.c stable/10/sys/mips/include/vmparam.h stable/10/sys/powerpc/include/vmparam.h stable/10/sys/sparc64/include/vmparam.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/amd64/include/vmparam.h ============================================================================== --- stable/10/sys/amd64/include/vmparam.h Fri May 16 00:14:50 2014 (r266203) +++ stable/10/sys/amd64/include/vmparam.h Fri May 16 01:30:30 2014 (r266204) @@ -178,23 +178,16 @@ #define PHYS_TO_DMAP(x) ((x) | DMAP_MIN_ADDRESS) #define DMAP_TO_PHYS(x) ((x) & ~DMAP_MIN_ADDRESS) -/* virtual sizes (bytes) for various kernel submaps */ -#ifndef VM_KMEM_SIZE -#define VM_KMEM_SIZE (12 * 1024 * 1024) -#endif - /* - * How many physical pages per KVA page allocated. - * min(max(max(VM_KMEM_SIZE, Physical memory/VM_KMEM_SIZE_SCALE), - * VM_KMEM_SIZE_MIN), VM_KMEM_SIZE_MAX) - * is the total KVA space allocated for kmem_map. + * How many physical pages per kmem arena virtual page. */ #ifndef VM_KMEM_SIZE_SCALE #define VM_KMEM_SIZE_SCALE (1) #endif /* - * Ceiling on amount of kmem_map kva space. + * Optional ceiling (in bytes) on the size of the kmem arena: 60% of the + * kernel map. */ #ifndef VM_KMEM_SIZE_MAX #define VM_KMEM_SIZE_MAX ((VM_MAX_KERNEL_ADDRESS - \ Modified: stable/10/sys/arm/include/vmparam.h ============================================================================== --- stable/10/sys/arm/include/vmparam.h Fri May 16 00:14:50 2014 (r266203) +++ stable/10/sys/arm/include/vmparam.h Fri May 16 01:30:30 2014 (r266204) @@ -145,17 +145,22 @@ #define VM_MAX_KERNEL_ADDRESS (vm_max_kernel_address) /* - * Virtual size (bytes) for various kernel submaps. + * How many physical pages per kmem arena virtual page. */ -#ifndef VM_KMEM_SIZE -#define VM_KMEM_SIZE (12*1024*1024) -#endif #ifndef VM_KMEM_SIZE_SCALE -#define VM_KMEM_SIZE_SCALE (3) +#define VM_KMEM_SIZE_SCALE (3) +#endif + +/* + * Optional floor (in bytes) on the size of the kmem arena. + */ +#ifndef VM_KMEM_SIZE_MIN +#define VM_KMEM_SIZE_MIN (12 * 1024 * 1024) #endif /* - * Ceiling on the size of the kmem submap: 40% of the kernel map. + * Optional ceiling (in bytes) on the size of the kmem arena: 40% of the + * kernel map. */ #ifndef VM_KMEM_SIZE_MAX #define VM_KMEM_SIZE_MAX ((vm_max_kernel_address - \ Modified: stable/10/sys/i386/include/vmparam.h ============================================================================== --- stable/10/sys/i386/include/vmparam.h Fri May 16 00:14:50 2014 (r266203) +++ stable/10/sys/i386/include/vmparam.h Fri May 16 01:30:30 2014 (r266204) @@ -164,24 +164,23 @@ #define VM_MAX_ADDRESS VADDR(PTDPTDI, PTDPTDI) #define VM_MIN_ADDRESS ((vm_offset_t)0) -/* virtual sizes (bytes) for various kernel submaps */ -#ifndef VM_KMEM_SIZE -#define VM_KMEM_SIZE (12 * 1024 * 1024) -#endif - /* - * How many physical pages per KVA page allocated. - * min(max(max(VM_KMEM_SIZE, Physical memory/VM_KMEM_SIZE_SCALE), - * VM_KMEM_SIZE_MIN), VM_KMEM_SIZE_MAX) - * is the total KVA space allocated for kmem_map. + * How many physical pages per kmem arena virtual page. */ #ifndef VM_KMEM_SIZE_SCALE #define VM_KMEM_SIZE_SCALE (3) #endif /* - * Ceiling on the amount of kmem_map KVA space: 40% of the entire KVA space - * rounded to the nearest multiple of the superpage size. + * Optional floor (in bytes) on the size of the kmem arena. + */ +#ifndef VM_KMEM_SIZE_MIN +#define VM_KMEM_SIZE_MIN (12 * 1024 * 1024) +#endif + +/* + * Optional ceiling (in bytes) on the size of the kmem arena: 40% of the + * kernel map rounded to the nearest multiple of the superpage size. */ #ifndef VM_KMEM_SIZE_MAX #define VM_KMEM_SIZE_MAX (((((VM_MAX_KERNEL_ADDRESS - \ Modified: stable/10/sys/ia64/include/vmparam.h ============================================================================== --- stable/10/sys/ia64/include/vmparam.h Fri May 16 00:14:50 2014 (r266203) +++ stable/10/sys/ia64/include/vmparam.h Fri May 16 01:30:30 2014 (r266204) @@ -189,19 +189,11 @@ #define USRSTACK VM_MAXUSER_ADDRESS #define IA64_BACKINGSTORE (USRSTACK - (2 * MAXSSIZ) - PAGE_SIZE) -/* virtual sizes (bytes) for various kernel submaps */ -#ifndef VM_KMEM_SIZE -#define VM_KMEM_SIZE (12 * 1024 * 1024) -#endif - /* - * How many physical pages per KVA page allocated. - * min(max(max(VM_KMEM_SIZE, Physical memory/VM_KMEM_SIZE_SCALE), - * VM_KMEM_SIZE_MIN), VM_KMEM_SIZE_MAX) - * is the total KVA space allocated for kmem_map. + * How many physical pages per kmem arena virtual page. */ #ifndef VM_KMEM_SIZE_SCALE -#define VM_KMEM_SIZE_SCALE (4) /* XXX 8192 byte pages */ +#define VM_KMEM_SIZE_SCALE (4) #endif /* initial pagein size of beginning of executable file */ Modified: stable/10/sys/kern/kern_malloc.c ============================================================================== --- stable/10/sys/kern/kern_malloc.c Fri May 16 00:14:50 2014 (r266203) +++ stable/10/sys/kern/kern_malloc.c Fri May 16 01:30:30 2014 (r266204) @@ -684,41 +684,47 @@ kmem_reclaim(vmem_t *vm, int flags) pagedaemon_wakeup(); } +CTASSERT(VM_KMEM_SIZE_SCALE >= 1); + /* - * Initialize the kernel memory arena. + * Initialize the kernel memory (kmem) arena. */ void kmeminit(void) { u_long mem_size, tmp; - + /* - * Try to auto-tune the kernel memory size, so that it is - * more applicable for a wider range of machine sizes. The - * VM_KMEM_SIZE_MAX is dependent on the maximum KVA space - * available. + * Calculate the amount of kernel virtual address (KVA) space that is + * preallocated to the kmem arena. In order to support a wide range + * of machines, it is a function of the physical memory size, + * specifically, + * + * min(max(physical memory size / VM_KMEM_SIZE_SCALE, + * VM_KMEM_SIZE_MIN), VM_KMEM_SIZE_MAX) * - * Note that the kmem arena is also used by the zone allocator, - * so make sure that there is enough space. + * Every architecture must define an integral value for + * VM_KMEM_SIZE_SCALE. However, the definitions of VM_KMEM_SIZE_MIN + * and VM_KMEM_SIZE_MAX, which represent respectively the floor and + * ceiling on this preallocation, are optional. Typically, + * VM_KMEM_SIZE_MAX is itself a function of the available KVA space on + * a given architecture. */ - vm_kmem_size = VM_KMEM_SIZE; mem_size = cnt.v_page_count; -#if defined(VM_KMEM_SIZE_SCALE) vm_kmem_size_scale = VM_KMEM_SIZE_SCALE; -#endif TUNABLE_INT_FETCH("vm.kmem_size_scale", &vm_kmem_size_scale); - if (vm_kmem_size_scale > 0 && - (mem_size / vm_kmem_size_scale) > (vm_kmem_size / PAGE_SIZE)) - vm_kmem_size = (mem_size / vm_kmem_size_scale) * PAGE_SIZE; + if (vm_kmem_size_scale < 1) + vm_kmem_size_scale = VM_KMEM_SIZE_SCALE; + + vm_kmem_size = (mem_size / vm_kmem_size_scale) * PAGE_SIZE; #if defined(VM_KMEM_SIZE_MIN) vm_kmem_size_min = VM_KMEM_SIZE_MIN; #endif TUNABLE_ULONG_FETCH("vm.kmem_size_min", &vm_kmem_size_min); - if (vm_kmem_size_min > 0 && vm_kmem_size < vm_kmem_size_min) { + if (vm_kmem_size_min > 0 && vm_kmem_size < vm_kmem_size_min) vm_kmem_size = vm_kmem_size_min; - } #if defined(VM_KMEM_SIZE_MAX) vm_kmem_size_max = VM_KMEM_SIZE_MAX; @@ -727,15 +733,17 @@ kmeminit(void) if (vm_kmem_size_max > 0 && vm_kmem_size >= vm_kmem_size_max) vm_kmem_size = vm_kmem_size_max; - /* Allow final override from the kernel environment */ - TUNABLE_ULONG_FETCH("vm.kmem_size", &vm_kmem_size); - /* - * 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 or the adjustment. + * Alternatively, the amount of KVA space that is preallocated to the + * kmem arena can be set statically at compile-time or manually + * through the kernel environment. However, it is still limited to + * twice the physical memory size, which has been sufficient to handle + * the most severe cases of external fragmentation in the kmem arena. */ +#if defined(VM_KMEM_SIZE) + vm_kmem_size = VM_KMEM_SIZE; +#endif + TUNABLE_ULONG_FETCH("vm.kmem_size", &vm_kmem_size); if (vm_kmem_size / 2 / PAGE_SIZE > mem_size) vm_kmem_size = 2 * mem_size * PAGE_SIZE; Modified: stable/10/sys/mips/include/vmparam.h ============================================================================== --- stable/10/sys/mips/include/vmparam.h Fri May 16 00:14:50 2014 (r266203) +++ stable/10/sys/mips/include/vmparam.h Fri May 16 01:30:30 2014 (r266204) @@ -108,22 +108,23 @@ #define VM_NRESERVLEVEL 0 #endif -/* virtual sizes (bytes) for various kernel submaps */ -#ifndef VM_KMEM_SIZE -#define VM_KMEM_SIZE (12 * 1024 * 1024) -#endif - /* - * How many physical pages per KVA page allocated. - * min(max(VM_KMEM_SIZE, Physical memory/VM_KMEM_SIZE_SCALE), VM_KMEM_SIZE_MAX) - * is the total KVA space allocated for kmem_map. + * How many physical pages per kmem arena virtual page. */ #ifndef VM_KMEM_SIZE_SCALE #define VM_KMEM_SIZE_SCALE (3) #endif /* - * Ceiling on the amount of kmem_map KVA space: 40% of the entire KVA space. + * Optional floor (in bytes) on the size of the kmem arena. + */ +#ifndef VM_KMEM_SIZE_MIN +#define VM_KMEM_SIZE_MIN (12 * 1024 * 1024) +#endif + +/* + * Optional ceiling (in bytes) on the size of the kmem arena: 40% of the + * kernel map. */ #ifndef VM_KMEM_SIZE_MAX #define VM_KMEM_SIZE_MAX ((VM_MAX_KERNEL_ADDRESS - \ Modified: stable/10/sys/powerpc/include/vmparam.h ============================================================================== --- stable/10/sys/powerpc/include/vmparam.h Fri May 16 00:14:50 2014 (r266203) +++ stable/10/sys/powerpc/include/vmparam.h Fri May 16 01:30:30 2014 (r266204) @@ -172,21 +172,23 @@ struct pmap_physseg { #define SGROWSIZ (128UL*1024) /* amount to grow stack */ #endif -#ifndef VM_KMEM_SIZE -#define VM_KMEM_SIZE (12 * 1024 * 1024) +/* + * How many physical pages per kmem arena virtual page. + */ +#ifndef VM_KMEM_SIZE_SCALE +#define VM_KMEM_SIZE_SCALE (3) #endif /* - * How many physical pages per KVA page allocated. - * min(max(VM_KMEM_SIZE, Physical memory/VM_KMEM_SIZE_SCALE), VM_KMEM_SIZE_MAX) - * is the total KVA space allocated for kmem_map. + * Optional floor (in bytes) on the size of the kmem arena. */ -#ifndef VM_KMEM_SIZE_SCALE -#define VM_KMEM_SIZE_SCALE (3) +#ifndef VM_KMEM_SIZE_MIN +#define VM_KMEM_SIZE_MIN (12 * 1024 * 1024) #endif /* - * Ceiling on the amount of kmem_map KVA space: 40% of the entire KVA space. + * Optional ceiling (in bytes) on the size of the kmem arena: 40% of the + * usable KVA space. */ #ifndef VM_KMEM_SIZE_MAX #define VM_KMEM_SIZE_MAX ((VM_MAX_SAFE_KERNEL_ADDRESS - \ Modified: stable/10/sys/sparc64/include/vmparam.h ============================================================================== --- stable/10/sys/sparc64/include/vmparam.h Fri May 16 00:14:50 2014 (r266203) +++ stable/10/sys/sparc64/include/vmparam.h Fri May 16 01:30:30 2014 (r266204) @@ -198,24 +198,22 @@ #define USRSTACK (VM_MAX_USER_ADDRESS) /* - * Virtual size (bytes) for various kernel submaps. + * How many physical pages per kmem arena virtual page. */ -#ifndef VM_KMEM_SIZE -#define VM_KMEM_SIZE (16*1024*1024) +#ifndef VM_KMEM_SIZE_SCALE +#define VM_KMEM_SIZE_SCALE (tsb_kernel_ldd_phys == 0 ? 3 : 2) #endif /* - * How many physical pages per KVA page allocated. - * min(max(max(VM_KMEM_SIZE, Physical memory/VM_KMEM_SIZE_SCALE), - * VM_KMEM_SIZE_MIN), VM_KMEM_SIZE_MAX) - * is the total KVA space allocated for kmem_map. + * Optional floor (in bytes) on the size of the kmem arena. */ -#ifndef VM_KMEM_SIZE_SCALE -#define VM_KMEM_SIZE_SCALE (tsb_kernel_ldd_phys == 0 ? 3 : 2) +#ifndef VM_KMEM_SIZE_MIN +#define VM_KMEM_SIZE_MIN (16 * 1024 * 1024) #endif /* - * Ceiling on amount of kmem_map kva space. + * Optional ceiling (in bytes) on the size of the kmem arena: 60% of the + * kernel map. */ #ifndef VM_KMEM_SIZE_MAX #define VM_KMEM_SIZE_MAX ((VM_MAX_KERNEL_ADDRESS - \
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405160130.s4G1UUl4025373>