|
5 | 5 | /* */
|
6 | 6 | /* OpenPOWER HostBoot Project */
|
7 | 7 | /* */
|
8 |
| -/* Contributors Listed Below - COPYRIGHT 2010,2020 */ |
| 8 | +/* Contributors Listed Below - COPYRIGHT 2010,2023 */ |
9 | 9 | /* [+] International Business Machines Corp. */
|
10 | 10 | /* */
|
11 | 11 | /* */
|
|
33 | 33 | #include <usr/debugpointers.H>
|
34 | 34 | #include <arch/magic.H>
|
35 | 35 | #include <usr/vmmconst.h>
|
| 36 | +#include <kernel/misc.H> |
| 37 | +#include <stdlib.h> |
36 | 38 |
|
37 | 39 | #ifdef HOSTBOOT_DEBUG
|
38 | 40 | #define SMALL_HEAP_PAGES_TRACKED 64
|
@@ -264,16 +266,21 @@ void* _enforceBigFence(void* const i_pAddr)
|
264 | 266 |
|
265 | 267 | void * HeapManager::allocate(size_t i_sz)
|
266 | 268 | {
|
| 269 | + |
267 | 270 | HeapManager& hmgr = Singleton<HeapManager>::instance();
|
268 | 271 | size_t overhead = 0;
|
269 | 272 |
|
270 | 273 | #ifdef CONFIG_MALLOC_FENCING
|
271 | 274 | overhead = offsetof(fence_t,data) + sizeof(CHECK::END);
|
272 | 275 | #endif
|
273 |
| - |
| 276 | + // do not want huge allocations when in kernel mode (huge |
| 277 | + // allocations use mm_alloc_block); kernel memory accesses don't |
| 278 | + // go through page translation. |
274 | 279 | if( (i_sz + overhead > MAX_BIG_ALLOC_SIZE)
|
275 |
| - && (i_sz + overhead <= HC_SLOT_SIZE) ) |
| 280 | + && (i_sz + overhead <= HC_SLOT_SIZE) |
| 281 | + && !(KernelMisc::in_kernel_mode())) |
276 | 282 | {
|
| 283 | + |
277 | 284 | printkd("allocateHuge=%ld [%d]\n", i_sz, task_gettid());
|
278 | 285 | void* ptr = hmgr._allocateHuge(i_sz);
|
279 | 286 | if( ptr )
|
@@ -859,7 +866,8 @@ void* HeapManager::_allocateBig(size_t i_sz)
|
859 | 866 | }
|
860 | 867 | if(!bc)
|
861 | 868 | {
|
862 |
| - bc = new big_chunk_t(v,pages); |
| 869 | + bc = (big_chunk_t*) contiguous_malloc(sizeof(big_chunk_t)); |
| 870 | + bc = new (bc) big_chunk_t(v,pages); |
863 | 871 | big_chunk_stack.push(bc);
|
864 | 872 | }
|
865 | 873 |
|
@@ -975,8 +983,8 @@ void* HeapManager::_allocateHuge(size_t i_sz)
|
975 | 983 | addr >= VMM_VADDR_MALLOC;
|
976 | 984 | addr -= HC_SLOT_SIZE )
|
977 | 985 | {
|
978 |
| - huge_chunk_t* hc = |
979 |
| - new huge_chunk_t(reinterpret_cast<void*>(addr),0); |
| 986 | + auto hc = static_cast<huge_chunk_t*>(contiguous_malloc(sizeof(huge_chunk_t))); |
| 987 | + hc = new (hc) huge_chunk_t(reinterpret_cast<void*>(addr),0); |
980 | 988 | huge_chunk_stack.push(hc);
|
981 | 989 | }
|
982 | 990 |
|
@@ -1019,6 +1027,7 @@ void* HeapManager::_allocateHuge(size_t i_sz)
|
1019 | 1027 | int rc = mm_set_permission(hc->addr,
|
1020 | 1028 | pages*PAGESIZE,
|
1021 | 1029 | WRITABLE | ALLOCATE_FROM_ZERO );
|
| 1030 | + |
1022 | 1031 | if(rc != 0)
|
1023 | 1032 | {
|
1024 | 1033 | printk( "_allocateHuge> mm_set_permission failed for requested size=%ld!!\n", i_sz );
|
@@ -1137,4 +1146,3 @@ void* HeapManager::_reallocHuge(void* i_ptr, size_t i_sz)
|
1137 | 1146 |
|
1138 | 1147 | return i_ptr;
|
1139 | 1148 | }
|
1140 |
| - |
|
0 commit comments