* Initialize the kernel memory (kmem) arena. */
| 1073 | * Initialize the kernel memory (kmem) arena. |
| 1074 | */ |
| 1075 | void |
| 1076 | kmeminit(void) |
| 1077 | { |
| 1078 | u_long mem_size; |
| 1079 | u_long tmp; |
| 1080 | |
| 1081 | #ifdef VM_KMEM_SIZE |
| 1082 | if (vm_kmem_size == 0) |
| 1083 | vm_kmem_size = VM_KMEM_SIZE; |
| 1084 | #endif |
| 1085 | #ifdef VM_KMEM_SIZE_MIN |
| 1086 | if (vm_kmem_size_min == 0) |
| 1087 | vm_kmem_size_min = VM_KMEM_SIZE_MIN; |
| 1088 | #endif |
| 1089 | #ifdef VM_KMEM_SIZE_MAX |
| 1090 | if (vm_kmem_size_max == 0) |
| 1091 | vm_kmem_size_max = VM_KMEM_SIZE_MAX; |
| 1092 | #endif |
| 1093 | /* |
| 1094 | * Calculate the amount of kernel virtual address (KVA) space that is |
| 1095 | * preallocated to the kmem arena. In order to support a wide range |
| 1096 | * of machines, it is a function of the physical memory size, |
| 1097 | * specifically, |
| 1098 | * |
| 1099 | * min(max(physical memory size / VM_KMEM_SIZE_SCALE, |
| 1100 | * VM_KMEM_SIZE_MIN), VM_KMEM_SIZE_MAX) |
| 1101 | * |
| 1102 | * Every architecture must define an integral value for |
| 1103 | * VM_KMEM_SIZE_SCALE. However, the definitions of VM_KMEM_SIZE_MIN |
| 1104 | * and VM_KMEM_SIZE_MAX, which represent respectively the floor and |
| 1105 | * ceiling on this preallocation, are optional. Typically, |
| 1106 | * VM_KMEM_SIZE_MAX is itself a function of the available KVA space on |
| 1107 | * a given architecture. |
| 1108 | */ |
| 1109 | mem_size = vm_cnt.v_page_count; |
| 1110 | if (mem_size <= 32768) /* delphij XXX 128MB */ |
| 1111 | kmem_zmax = PAGE_SIZE; |
| 1112 | |
| 1113 | if (vm_kmem_size_scale < 1) |
| 1114 | vm_kmem_size_scale = VM_KMEM_SIZE_SCALE; |
| 1115 | |
| 1116 | /* |
| 1117 | * Check if we should use defaults for the "vm_kmem_size" |
| 1118 | * variable: |
| 1119 | */ |
| 1120 | if (vm_kmem_size == 0) { |
| 1121 | vm_kmem_size = mem_size / vm_kmem_size_scale; |
| 1122 | vm_kmem_size = vm_kmem_size * PAGE_SIZE < vm_kmem_size ? |
| 1123 | vm_kmem_size_max : vm_kmem_size * PAGE_SIZE; |
| 1124 | if (vm_kmem_size_min > 0 && vm_kmem_size < vm_kmem_size_min) |
| 1125 | vm_kmem_size = vm_kmem_size_min; |
| 1126 | if (vm_kmem_size_max > 0 && vm_kmem_size >= vm_kmem_size_max) |
| 1127 | vm_kmem_size = vm_kmem_size_max; |
| 1128 | } |
| 1129 | if (vm_kmem_size == 0) |
| 1130 | panic("Tune VM_KMEM_SIZE_* for the platform"); |
| 1131 | |
| 1132 | /* |
no test coverage detected