#include <folly/system/MemoryMapping.h>
#include <algorithm>
#include <cerrno>
#include <utility>
#include <fmt/core.h>
#include <glog/logging.h>
#include <folly/Portability.h>
#include <folly/portability/GFlags.h>
#include <folly/portability/SysMman.h>
#include <folly/portability/SysSyscall.h>
#include <folly/portability/Unistd.h>
#ifdef __linux__
#include <folly/experimental/io/HugePages.h>
#endif
#include <fcntl.h>
#include <sys/types.h>
#include <system_error>
static constexpr ssize_t kDefaultMlockChunkSize = …;
FOLLY_GFLAGS_DEFINE_int64(…);
namespace folly {
namespace {
enum mmap_flags : int { … };
}
MemoryMapping::MemoryMapping(MemoryMapping&& other) noexcept { … }
MemoryMapping::MemoryMapping(
File file, off64_t offset, off64_t length, Options options)
: … { … }
MemoryMapping::MemoryMapping(
const char* name, off64_t offset, off64_t length, Options options)
: … { … }
MemoryMapping::MemoryMapping(
int fd, off64_t offset, off64_t length, Options options)
: … { … }
MemoryMapping::MemoryMapping(AnonymousType, off64_t length, Options options)
: … { … }
namespace {
#ifdef __linux__
void getDeviceOptions(dev_t device, off64_t& pageSize, bool& autoExtend) {
auto ps = getHugePageSizeForDevice(device);
if (ps) {
pageSize = ps->size;
autoExtend = true;
}
}
#else
inline void getDeviceOptions(dev_t, off64_t&, bool&) { … }
#endif
}
void MemoryMapping::init(off64_t offset, off64_t length) { … }
namespace {
off64_t memOpChunkSize(off64_t length, off64_t pageSize) { … }
template <typename Op>
bool memOpInChunks(
Op op,
void* mem,
size_t bufSize,
off64_t pageSize,
size_t& amountSucceeded) { … }
}
int mlock2wrapper(
[[maybe_unused]] const void* addr,
[[maybe_unused]] size_t len,
MemoryMapping::LockFlags flags) { … }
bool MemoryMapping::mlock(LockMode mode, LockFlags flags) { … }
void MemoryMapping::munlock(bool dontneed) { … }
void MemoryMapping::hintLinearScan() { … }
MemoryMapping::~MemoryMapping() { … }
void MemoryMapping::advise(int advice) const { … }
void MemoryMapping::advise(int advice, size_t offset, size_t length) const { … }
MemoryMapping& MemoryMapping::operator=(MemoryMapping&& other) { … }
void MemoryMapping::swap(MemoryMapping& other) noexcept { … }
void swap(MemoryMapping& a, MemoryMapping& b) noexcept { … }
void alignedForwardMemcpy(void* dst, const void* src, size_t size) { … }
void mmapFileCopy(const char* src, const char* dest, mode_t mode) { … }
bool MemoryMapping::LockFlags::operator==(const LockFlags& other) const { … }
}