proxygen
|
#include <MemoryMapping.h>
Classes | |
struct | Options |
Public Types | |
enum | LockMode { LockMode::TRY_LOCK, LockMode::MUST_LOCK } |
enum | AnonymousType { kAnonymous } |
Public Member Functions | |
MemoryMapping (AnonymousType, off_t length, Options options=Options()) | |
MemoryMapping (File file, off_t offset=0, off_t length=-1, Options options=Options()) | |
MemoryMapping (const char *name, off_t offset=0, off_t length=-1, Options options=Options()) | |
MemoryMapping (int fd, off_t offset=0, off_t length=-1, Options options=Options()) | |
MemoryMapping (MemoryMapping &&) noexcept | |
~MemoryMapping () | |
MemoryMapping & | operator= (MemoryMapping) |
void | swap (MemoryMapping &other) noexcept |
bool | mlock (LockMode lock) |
void | munlock (bool dontneed=false) |
void | hintLinearScan () |
void | advise (int advice) const |
void | advise (int advice, size_t offset, size_t length) const |
template<class T > | |
Range< const T * > | asRange () const |
ByteRange | range () const |
template<class T > | |
Range< T * > | asWritableRange () const |
MutableByteRange | writableRange () const |
StringPiece | data () const |
bool | mlocked () const |
int | fd () const |
Static Public Member Functions | |
static Options | writable () |
Private Types | |
enum | InitFlags { kGrow = 1 << 0, kAnon = 1 << 1 } |
Private Member Functions | |
MemoryMapping () | |
void | init (off_t offset, off_t length) |
Private Attributes | |
File | file_ |
void * | mapStart_ = nullptr |
off_t | mapLength_ = 0 |
Options | options_ |
bool | locked_ = false |
MutableByteRange | data_ |
Maps files in memory (read-only).
Definition at line 32 of file MemoryMapping.h.
Enumerator | |
---|---|
kAnonymous |
Definition at line 123 of file MemoryMapping.h.
|
private |
Enumerator | |
---|---|
kGrow | |
kAnon |
Definition at line 238 of file MemoryMapping.h.
|
strong |
Lock the pages in memory? TRY_LOCK = try to lock, log warning if permission denied MUST_LOCK = lock, fail assertion if permission denied.
Enumerator | |
---|---|
TRY_LOCK | |
MUST_LOCK |
Definition at line 39 of file MemoryMapping.h.
folly::MemoryMapping::MemoryMapping | ( | AnonymousType | , |
off_t | length, | ||
Options | options = Options() |
||
) |
Create an anonymous mapping.
Definition at line 92 of file MemoryMapping.cpp.
References folly::getHugePageSizeForDevice(), and init().
|
explicit |
Definition at line 64 of file MemoryMapping.cpp.
|
explicit |
Definition at line 74 of file MemoryMapping.cpp.
|
explicit |
Definition at line 85 of file MemoryMapping.cpp.
|
noexcept |
folly::MemoryMapping::~MemoryMapping | ( | ) |
Definition at line 329 of file MemoryMapping.cpp.
References folly::FATAL, folly::format(), mapLength_, mapStart_, options_, and folly::MemoryMapping::Options::pageSize.
|
private |
Referenced by fd().
void folly::MemoryMapping::advise | ( | int | advice | ) | const |
Advise the kernel about memory access.
Definition at line 344 of file MemoryMapping.cpp.
References mapLength_.
Referenced by hintLinearScan(), and folly::TEST().
void folly::MemoryMapping::advise | ( | int | advice, |
size_t | offset, | ||
size_t | length | ||
) | const |
Definition at line 348 of file MemoryMapping.cpp.
References mapLength_, mapStart_, options_, folly::MemoryMapping::Options::pageSize, and folly::WARNING.
A bitwise cast of the mapped bytes as range of values. Only intended for use with POD or in-place usable types.
Definition at line 187 of file MemoryMapping.h.
References count, folly::Range< Iter >::data(), data_, folly::Range< Iter >::size(), and folly::T.
Referenced by folly::TEST().
A bitwise cast of the mapped bytes as range of mutable values. Only intended for use with POD or in-place usable types.
Definition at line 205 of file MemoryMapping.h.
References count, folly::Range< Iter >::data(), data_, options_, folly::Range< Iter >::size(), folly::T, and folly::MemoryMapping::Options::writable.
Referenced by folly::TEST().
|
inline |
Return the memory area where the file was mapped. Deprecated; use range() instead.
Definition at line 223 of file MemoryMapping.h.
Referenced by folly::TEST().
|
inline |
Definition at line 231 of file MemoryMapping.h.
References folly::File::fd(), file_, and MemoryMapping().
void folly::MemoryMapping::hintLinearScan | ( | ) |
Hint that these pages will be scanned linearly. madvise(MADV_SEQUENTIAL)
Definition at line 325 of file MemoryMapping.cpp.
References advise().
Referenced by folly::mmapFileCopy().
|
private |
Definition at line 113 of file MemoryMapping.cpp.
References addr, folly::MemoryMapping::Options::address, data_, folly::File::fd(), file_, folly::MemoryMapping::Options::grow, MAP_POPULATE, mapLength_, mapStart_, min, options_, folly::MemoryMapping::Options::pageSize, folly::MemoryMapping::Options::prefault, folly::MemoryMapping::Options::readable, folly::Range< Iter >::reset(), folly::MemoryMapping::Options::shared, folly::size(), start, and folly::MemoryMapping::Options::writable.
Referenced by MemoryMapping().
bool folly::MemoryMapping::mlock | ( | LockMode | lock | ) |
Lock the pages in memory
Definition at line 269 of file MemoryMapping.cpp.
References folly::FATAL, folly::format(), locked_, mapLength_, mapStart_, munlock(), options_, folly::MemoryMapping::Options::pageSize, TRY_LOCK, and folly::WARNING.
Referenced by folly::TEST().
|
inline |
void folly::MemoryMapping::munlock | ( | bool | dontneed = false | ) |
Unlock the pages. If dontneed is true, the kernel is instructed to release these pages (per madvise(MADV_DONTNEED)).
Definition at line 304 of file MemoryMapping.cpp.
References locked_, mapLength_, mapStart_, options_, folly::MemoryMapping::Options::pageSize, and folly::WARNING.
Referenced by mlock().
MemoryMapping & folly::MemoryMapping::operator= | ( | MemoryMapping | other | ) |
|
inline |
A range of bytes mapped by this mapping.
Definition at line 196 of file MemoryMapping.h.
References data_.
Referenced by folly::mmapFileCopy(), and folly::RecordIOReader::seek().
|
noexcept |
Definition at line 376 of file MemoryMapping.cpp.
References data_, file_, locked_, mapLength_, mapStart_, options_, and folly::swap().
Referenced by MemoryMapping(), and operator=().
|
inlinestatic |
Definition at line 119 of file MemoryMapping.h.
References folly::MemoryMapping::Options::setGrow(), and folly::MemoryMapping::Options::setWritable().
Referenced by folly::mmapFileCopy(), folly::MemoryMapping::Options::setWritable(), and folly::TEST().
|
inline |
A range of mutable bytes mapped by this mapping.
Definition at line 214 of file MemoryMapping.h.
References data_, options_, and folly::MemoryMapping::Options::writable.
|
private |
Definition at line 249 of file MemoryMapping.h.
Referenced by asRange(), asWritableRange(), init(), range(), swap(), and writableRange().
|
private |
Definition at line 244 of file MemoryMapping.h.
Referenced by fd(), init(), MemoryMapping(), and swap().
|
private |
|
private |
Definition at line 246 of file MemoryMapping.h.
Referenced by advise(), init(), mlock(), munlock(), swap(), and ~MemoryMapping().
|
private |
Definition at line 245 of file MemoryMapping.h.
Referenced by advise(), init(), mlock(), munlock(), swap(), and ~MemoryMapping().
|
private |
Definition at line 247 of file MemoryMapping.h.
Referenced by advise(), asWritableRange(), init(), mlock(), munlock(), swap(), writableRange(), and ~MemoryMapping().