Changeset View
Changeset View
Standalone View
Standalone View
sys/kern/kern_malloc.c
Show First 20 Lines • Show All 914 Lines • ▼ Show 20 Lines | #endif | ||||
if (vm_kmem_size_scale < 1) | if (vm_kmem_size_scale < 1) | ||||
vm_kmem_size_scale = VM_KMEM_SIZE_SCALE; | vm_kmem_size_scale = VM_KMEM_SIZE_SCALE; | ||||
/* | /* | ||||
* Check if we should use defaults for the "vm_kmem_size" | * Check if we should use defaults for the "vm_kmem_size" | ||||
* variable: | * variable: | ||||
*/ | */ | ||||
if (vm_kmem_size == 0) { | if (vm_kmem_size == 0) { | ||||
vm_kmem_size = (mem_size / vm_kmem_size_scale) * PAGE_SIZE; | vm_kmem_size = mem_size / vm_kmem_size_scale; | ||||
vm_kmem_size = vm_kmem_size * PAGE_SIZE < vm_kmem_size ? | |||||
vm_kmem_size_max : vm_kmem_size * PAGE_SIZE; | |||||
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; | vm_kmem_size = vm_kmem_size_min; | ||||
if (vm_kmem_size_max > 0 && vm_kmem_size >= vm_kmem_size_max) | if (vm_kmem_size_max > 0 && vm_kmem_size >= vm_kmem_size_max) | ||||
vm_kmem_size = vm_kmem_size_max; | vm_kmem_size = vm_kmem_size_max; | ||||
} | } | ||||
if (vm_kmem_size == 0) | |||||
markj: Why does vm_kmem_size * PAGE_SIZE < vm_kmem_size imply that the overflowed value is 0?
Also… | |||||
Done Inline ActionsI only want to panic if the value for the vm_kmem_size is insane. If there are some defined values for VM_KMEM_SIZE_MIN/MAX, and they are used, this should be fine. Even if only _MIN is defined and used. So no, the overflow does not imply that the overflown value is zero, it only means that we fall back to vm_kmem_size_max, whatever it is (except zero). kib: I only want to panic if the value for the vm_kmem_size is insane. If there are some defined… | |||||
Not Done Inline ActionsBut if there is an overflow and vm_kmem_size_max == vm_kmem_size_min == 0, we may set vm_kmem_size to a non-zero insane value. markj: But if there is an overflow and vm_kmem_size_max == vm_kmem_size_min == 0, we may set… | |||||
panic("Tune VM_KMEM_SIZE_* for the platform"); | |||||
/* | /* | ||||
* The amount of KVA space that is preallocated to the | * The amount of KVA space that is preallocated to the | ||||
* kmem arena can be set statically at compile-time or manually | * kmem arena can be set statically at compile-time or manually | ||||
* through the kernel environment. However, it is still limited to | * through the kernel environment. However, it is still limited to | ||||
* twice the physical memory size, which has been sufficient to handle | * twice the physical memory size, which has been sufficient to handle | ||||
* the most severe cases of external fragmentation in the kmem arena. | * the most severe cases of external fragmentation in the kmem arena. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 378 Lines • Show Last 20 Lines |
Why does vm_kmem_size * PAGE_SIZE < vm_kmem_size imply that the overflowed value is 0?
Also, if vm_kmem_size_max == 0 and vm_kmem_size_min != 0, the code above may just silently set vm_kmem_size = vm_kmem_size_min in the overflow case. Shouldn't we panic in that case too?