| 364 | #endif |
| 365 | |
| 366 | static char* AllocWithMMap(uintptr_t sz, EMMapMode mode) { |
| 367 | (void)mode; |
| 368 | #ifdef _MSC_VER |
| 369 | char* largeBlock = (char*)VirtualAlloc(0, sz, MEM_RESERVE, PAGE_READWRITE); |
| 370 | if (Y_UNLIKELY(largeBlock == nullptr)) |
| 371 | NMalloc::AbortFromCorruptedAllocator("out of memory"); |
| 372 | if (Y_UNLIKELY(uintptr_t(((char*)largeBlock - ALLOC_START) + sz) >= N_MAX_WORKSET_SIZE)) |
| 373 | NMalloc::AbortFromCorruptedAllocator("out of working set, something has broken"); |
| 374 | #else |
| 375 | #if defined(_freebsd_) || !defined(_64_) |
| 376 | char* largeBlock = (char*)mmap(0, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); |
| 377 | VerifyMmapResult(largeBlock); |
| 378 | if (Y_UNLIKELY(uintptr_t(((char*)largeBlock - ALLOC_START) + sz) >= N_MAX_WORKSET_SIZE)) |
| 379 | NMalloc::AbortFromCorruptedAllocator("out of working set, something has broken"); |
| 380 | #else |
| 381 | char* largeBlock = AllocWithMMapLinuxImpl(sz, mode); |
| 382 | if (TransparentHugePages) { |
| 383 | madvise(largeBlock, sz, MADV_HUGEPAGE); |
| 384 | } |
| 385 | #endif |
| 386 | #endif |
| 387 | Y_ASSERT_NOBT(largeBlock); |
| 388 | IncrementCounter(CT_MMAP, sz); |
| 389 | IncrementCounter(CT_MMAP_CNT, 1); |
| 390 | return largeBlock; |
| 391 | } |
| 392 | |
| 393 | enum class ELarge : ui8 { |
| 394 | Free = 0, // block in free cache |
no test coverage detected