Skip to content

Commit c24bc55

Browse files
committed
fix for madvise + alignedMalloc combination
1 parent a9b0607 commit c24bc55

1 file changed

Lines changed: 3 additions & 20 deletions

File tree

kernels/common/alloc.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -456,36 +456,19 @@ namespace embree
456456
/* either use alignedMalloc or os_reserve/os_commit */
457457
void *ptr = nullptr;
458458
if (!osAllocation) {
459-
#if 1
460459
if (bytesReserve == (2*PAGE_SIZE_2M))
461460
{
462461
/* full 2M alignment for very first block */
463-
#if 1
464462
const size_t alignment = (next == NULL) ? PAGE_SIZE_2M : PAGE_SIZE;
465-
ptr = alignedMalloc(bytesReserve,alignment);
466-
463+
ptr = alignedMalloc(bytesReserve,alignment);
467464
const size_t ptr_aligned_begin = ((size_t)ptr) & ~(PAGE_SIZE_2M-1);
468-
const size_t ptr_aligned_end = ((size_t)ptr+bytesReserve+PAGE_SIZE-1) & ~(PAGE_SIZE_2M-1);
469-
os_advise((void*)ptr_aligned_begin,ptr_aligned_end-ptr_aligned_begin);
470-
//os_advise((void*)(ptr_aligned_begin + 0),PAGE_SIZE_2M);
471-
//os_advise((void*)(ptr_aligned_begin + PAGE_SIZE_2M),PAGE_SIZE_2M);
472-
#else
473-
const size_t alignment = (next == NULL) ? PAGE_SIZE_2M : PAGE_SIZE_2M/2;
474-
ptr = alignedMalloc(bytesReserve,alignment);
475-
void *new_ptr = (void*)((next == NULL) ? (size_t)ptr : ((size_t)ptr & ~(PAGE_SIZE_2M-1)));
476465
/* first os_advise could fail as speculative */
477-
os_advise(new_ptr,PAGE_SIZE_2M);
466+
os_advise((void*)(ptr_aligned_begin + 0),PAGE_SIZE_2M);
478467
/* second os_advise should succeed as with 4M block */
479-
os_advise((void*)((size_t)new_ptr + PAGE_SIZE_2M),PAGE_SIZE_2M);
480-
#endif
468+
os_advise((void*)(ptr_aligned_begin + PAGE_SIZE_2M),PAGE_SIZE_2M);
481469
}
482470
else
483471
ptr = alignedMalloc(bytesReserve,CACHELINE_SIZE);
484-
#else
485-
/* non KNL path */
486-
ptr = alignedMalloc(bytesReserve,CACHELINE_SIZE);
487-
#endif
488-
489472
} else {
490473
ptr = os_reserve(bytesReserve);
491474
os_commit(ptr,bytesAllocate);

0 commit comments

Comments
 (0)