MCPcopy Create free account
hub / github.com/catboost/catboost / AllocWithMMap

Function AllocWithMMap

library/cpp/lfalloc/lf_allocX64.h:366–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364#endif
365
366static 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
393enum class ELarge : ui8 {
394 Free = 0, // block in free cache

Callers 2

LargeBlockAllocFunction · 0.85
SlowLFAllocFunction · 0.85

Calls 4

VerifyMmapResultFunction · 0.85
AllocWithMMapLinuxImplFunction · 0.85
IncrementCounterFunction · 0.85

Tested by

no test coverage detected