MCPcopy Create free account
hub / github.com/facebook/CacheLib / mmapAlignedZeroedMemory

Function mmapAlignedZeroedMemory

cachelib/common/Utils.cpp:168–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166}
167
168void* mmapAlignedZeroedMemory(size_t alignment,
169 size_t numBytes,
170 bool noAccess) {
171 // to enforce alignment, we try to make sure that the address we return is
172 // aligned to slab size.
173 size_t newBytes = numBytes + alignment;
174 const auto protFlag = noAccess ? PROT_NONE : PROT_READ | PROT_WRITE;
175 const auto mapFlag = MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE;
176 void* memory = mmap(nullptr, newBytes, protFlag, mapFlag, -1, 0);
177 if (memory != MAP_FAILED) {
178 auto alignedMemory = align(alignment, numBytes, memory, newBytes);
179 XDCHECK_NE(alignedMemory, nullptr);
180 return alignedMemory;
181 }
182 throw std::system_error(errno, std::system_category(), "Cannot mmap");
183}
184
185void setMaxLockMemory(uint64_t bytes) {
186 struct rlimit rlim{bytes, bytes};

Callers 5

createShmMappingMethod · 0.85
SlabAllocatorMethod · 0.85
mapAddressMethod · 0.85
resetMethod · 0.85
resetMethod · 0.85

Calls 1

alignFunction · 0.85

Tested by

no test coverage detected