FreeBSD/sys/kern/kern_malloc.c
/*
 * Initialize the kernel memory (kmem) arena.
 */
Initialize the kernel memory (kmem) arena.
Initialize the kernel memory ( kmem ) arena .
void
kmeminit(void)
{
	u_long mem_size;
	u_long tmp;
#ifdef VM_KMEM_SIZE
	if (vm_kmem_size == 0)
		vm_kmem_size = VM_KMEM_SIZE;
#endif
#ifdef VM_KMEM_SIZE_MIN
	if (vm_kmem_size_min == 0)
		vm_kmem_size_min = VM_KMEM_SIZE_MIN;
#endif
#ifdef VM_KMEM_SIZE_MAX
	if (vm_kmem_size_max == 0)
		vm_kmem_size_max = VM_KMEM_SIZE_MAX;
#endif
	mem_size = vm_cnt.v_page_count;
	if (mem_size <= 32768) 
		kmem_zmax = PAGE_SIZE;
	if (vm_kmem_size_scale < 1)
		vm_kmem_size_scale = VM_KMEM_SIZE_SCALE;
	if (vm_kmem_size == 0) {
		vm_kmem_size = (mem_size / vm_kmem_size_scale) * PAGE_SIZE;
		if (vm_kmem_size_min > 0 && vm_kmem_size < vm_kmem_size_min)
			vm_kmem_size = vm_kmem_size_min;
		if (vm_kmem_size_max > 0 && vm_kmem_size >= vm_kmem_size_max)
			vm_kmem_size = vm_kmem_size_max;
	}
	if (vm_kmem_size / 2 / PAGE_SIZE > mem_size)
		vm_kmem_size = 2 * mem_size * PAGE_SIZE;
	vm_kmem_size = round_page(vm_kmem_size);
#ifdef DEBUG_MEMGUARD
	tmp = memguard_fudge(vm_kmem_size, kernel_map);
#else
	tmp = vm_kmem_size;
#endif
	vmem_init(kmem_arena, "kmem arena", kva_alloc(tmp), tmp, PAGE_SIZE,
	    0, 0);
	vmem_set_reclaim(kmem_arena, kmem_reclaim);
#ifdef DEBUG_MEMGUARD
	memguard_init(kmem_arena);
#endif
}
void kmeminit ( void ) { u_long mem_size ; u_long tmp ; #ifdef VM_KMEM_SIZE if ( vm_kmem_size == 0 ) vm_kmem_size = VM_KMEM_SIZE ; #endif #ifdef VM_KMEM_SIZE_MIN if ( vm_kmem_size_min == 0 ) vm_kmem_size_min = VM_KMEM_SIZE_MIN ; #endif #ifdef VM_KMEM_SIZE_MAX if ( vm_kmem_size_max == 0 ) vm_kmem_size_max = VM_KMEM_SIZE_MAX ; #endif mem_size = vm_cnt . v_page_count ; if ( mem_size <= 32768 ) kmem_zmax = PAGE_SIZE ; if ( vm_kmem_size_scale < 1 ) vm_kmem_size_scale = VM_KMEM_SIZE_SCALE ; if ( vm_kmem_size == 0 ) { vm_kmem_size = ( mem_size / vm_kmem_size_scale ) * PAGE_SIZE ; if ( vm_kmem_size_min > 0 && vm_kmem_size < vm_kmem_size_min ) vm_kmem_size = vm_kmem_size_min ; if ( vm_kmem_size_max > 0 && vm_kmem_size >= vm_kmem_size_max ) vm_kmem_size = vm_kmem_size_max ; } if ( vm_kmem_size / 2 / PAGE_SIZE > mem_size ) vm_kmem_size = 2 * mem_size * PAGE_SIZE ; vm_kmem_size = round_page ( vm_kmem_size ) ; #ifdef DEBUG_MEMGUARD tmp = memguard_fudge ( vm_kmem_size , kernel_map ) ; #else tmp = vm_kmem_size ; #endif vmem_init ( kmem_arena , " " , kva_alloc ( tmp ) , tmp , PAGE_SIZE , 0 , 0 ) ; vmem_set_reclaim ( kmem_arena , kmem_reclaim ) ; #ifdef DEBUG_MEMGUARD memguard_init ( kmem_arena ) ; #endif }
Initialize the kernel memory (kmem) arena.
Initialize the kernel memory ( kmem ) arena .
/*
	 * 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)
	 *
	 * 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.
	 */ /* delphij XXX 128MB */ /*
	 * Check if we should use defaults for the "vm_kmem_size"
	 * variable:
	 */ /*
	 * 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. 
	 */ /*
	 * Initialize MemGuard if support compiled in.  MemGuard is a
	 * replacement allocator used for detecting tamper-after-free
	 * scenarios as they occur.  It is only used for debugging.
	 */