proxygen
folly::fibers::GuardPageAllocator Class Reference

#include <GuardPageAllocator.h>

Public Member Functions

 GuardPageAllocator (bool useGuardPages)
 
 ~GuardPageAllocator ()
 
unsigned char * allocate (size_t size)
 
void deallocate (unsigned char *limit, size_t size)
 

Private Attributes

std::unique_ptr< StackCacheEntrystackCache_
 
std::allocator< unsigned char > fallbackAllocator_
 
bool useGuardPages_ {true}
 

Detailed Description

Stack allocator that protects an extra memory page after the end of the stack. Will only add extra memory pages up to a certain number of allocations to avoid creating too many memory maps for the process.

Definition at line 31 of file GuardPageAllocator.h.

Constructor & Destructor Documentation

folly::fibers::GuardPageAllocator::GuardPageAllocator ( bool  useGuardPages)
explicit
Parameters
useGuardPagesif true, protect limited amount of stacks with guard pages, otherwise acts as std::allocator.

Definition at line 293 of file GuardPageAllocator.cpp.

References ~GuardPageAllocator().

294  : useGuardPages_(useGuardPages) {
295 #ifndef _WIN32
296  installSignalHandler();
297 #endif
298 }
folly::fibers::GuardPageAllocator::~GuardPageAllocator ( )
default

Referenced by GuardPageAllocator().

Member Function Documentation

unsigned char * folly::fibers::GuardPageAllocator::allocate ( size_t  size)
Returns
pointer to the bottom of the allocated stack of `size' bytes.

Definition at line 302 of file GuardPageAllocator.cpp.

References fallbackAllocator_, folly::fibers::CacheManager::getStackCache(), folly::fibers::CacheManager::instance(), stackCache_, and useGuardPages_.

302  {
303  if (useGuardPages_ && !stackCache_) {
305  }
306 
307  if (stackCache_) {
308  auto p = stackCache_->cache().borrow(size);
309  if (p != nullptr) {
310  return p;
311  }
312  }
313  return fallbackAllocator_.allocate(size);
314 }
std::unique_ptr< StackCacheEntry > stackCache_
std::unique_ptr< StackCacheEntry > getStackCache(size_t stackSize)
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
std::allocator< unsigned char > fallbackAllocator_
static CacheManager & instance()
void folly::fibers::GuardPageAllocator::deallocate ( unsigned char *  limit,
size_t  size 
)

Deallocates the previous result of an `allocate(size)' call.

Definition at line 316 of file GuardPageAllocator.cpp.

References fallbackAllocator_, and stackCache_.

Referenced by folly::fibers::Fiber::~Fiber().

316  {
317  if (!(stackCache_ && stackCache_->cache().giveBack(limit, size))) {
318  fallbackAllocator_.deallocate(limit, size);
319  }
320 }
std::unique_ptr< StackCacheEntry > stackCache_
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
std::allocator< unsigned char > fallbackAllocator_

Member Data Documentation

std::allocator<unsigned char> folly::fibers::GuardPageAllocator::fallbackAllocator_
private

Definition at line 52 of file GuardPageAllocator.h.

Referenced by allocate(), and deallocate().

std::unique_ptr<StackCacheEntry> folly::fibers::GuardPageAllocator::stackCache_
private

Definition at line 51 of file GuardPageAllocator.h.

Referenced by allocate(), and deallocate().

bool folly::fibers::GuardPageAllocator::useGuardPages_ {true}
private

Definition at line 53 of file GuardPageAllocator.h.

Referenced by allocate().


The documentation for this class was generated from the following files: