Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Enumerations | Functions | Variables
vm Namespace Reference

Enumerations

enum  PageType { kLarge, kSmall, kDefault }
 

Functions

void * ReserveAddressSpace (size_t size, size_t commitSize=largePageSize, PageType pageType=kDefault, int prot=PROT_READ|PROT_WRITE)
 reserve address space and set the parameters for any later on-demand commits. More...
 
void ReleaseAddressSpace (void *p, size_t size=0)
 release address space and decommit any memory. More...
 
bool Commit (uintptr_t address, size_t size, PageType pageType=kDefault, int prot=PROT_READ|PROT_WRITE)
 map physical memory to previously reserved address space. More...
 
bool Decommit (uintptr_t address, size_t size)
 unmap physical memory. More...
 
bool Protect (uintptr_t address, size_t size, int prot)
 set the memory protection flags for all pages that intersect the given interval. More...
 
void * Allocate (size_t size, PageType pageType=kDefault, int prot=PROT_READ|PROT_WRITE)
 reserve address space and commit memory. More...
 
void Free (void *p, size_t size=0)
 decommit memory and release address space. More...
 
void BeginOnDemandCommits ()
 install a handler that attempts to commit memory whenever a read/write page fault is encountered. More...
 
void EndOnDemandCommits ()
 decrements the reference count begun by BeginOnDemandCommit and removes the page fault handler when it reaches 0. More...
 
void DumpStatistics ()
 
 CACHE_ALIGNED (struct Statistics)
 
static bool ShouldUseLargePages (size_t allocationSize, DWORD allocationType, PageType pageType)
 
static void * AllocateLargeOrSmallPages (uintptr_t address, size_t size, DWORD allocationType, PageType pageType=kDefault, int prot=PROT_READ|PROT_WRITE)
 
 CACHE_ALIGNED (struct AddressRangeDescriptor)
 
static AddressRangeDescriptor * FindDescriptor (uintptr_t address)
 
 TIMER_ADD_CLIENT (tc_commit)
 
static LONG CALLBACK VectoredHandler (const PEXCEPTION_POINTERS ep)
 
static Status InitHandler ()
 
static void ShutdownHandler ()
 

Variables

static bool largePageAllocationTookTooLong = false
 
static AddressRangeDescriptor ranges [2 *os_cpu_MaxProcessors]
 
static PVOID handler
 
static ModuleInitState initState
 
static volatile intptr_t references = 0
 

Enumeration Type Documentation

Enumerator
kLarge 
kSmall 
kDefault 

Definition at line 42 of file vm.h.

Function Documentation

LIB_API void * vm::Allocate ( size_t  size,
PageType  pageType = kDefault,
int  prot = PROT_READ|PROT_WRITE 
)

reserve address space and commit memory.

Parameters
size[bytes] to allocate.
pageType,prot- see ReserveAddressSpace.
Returns
zero-initialized memory aligned to the respective page size.

Definition at line 98 of file uvm.cpp.

static void* vm::AllocateLargeOrSmallPages ( uintptr_t  address,
size_t  size,
DWORD  allocationType,
PageType  pageType = kDefault,
int  prot = PROT_READ|PROT_WRITE 
)
static

Definition at line 202 of file wvm.cpp.

LIB_API void vm::BeginOnDemandCommits ( )

install a handler that attempts to commit memory whenever a read/write page fault is encountered.

thread-safe.

Definition at line 120 of file uvm.cpp.

static vm::CACHE_ALIGNED ( struct Statistics  )

Definition at line 101 of file wvm.cpp.

vm::CACHE_ALIGNED ( struct AddressRangeDescriptor  )

Definition at line 264 of file wvm.cpp.

LIB_API bool vm::Commit ( uintptr_t  address,
size_t  size,
PageType  pageType = kDefault,
int  prot = PROT_READ|PROT_WRITE 
)

map physical memory to previously reserved address space.

Parameters
address,sizeneed not be aligned, but this function commits any pages intersecting that interval.
pageType,prot- see ReserveAddressSpace.
Returns
whether memory was successfully committed.

note: committing only maps virtual pages and does not actually allocate page frames. Windows XP uses a first-touch heuristic - the page will be taken from the node whose processor caused the fault. therefore, worker threads should be the first to write to their memory.

(this is surprisingly slow in XP, possibly due to PFN lock contention)

Definition at line 59 of file uvm.cpp.

LIB_API bool vm::Decommit ( uintptr_t  address,
size_t  size 
)

unmap physical memory.

Returns
whether the operation succeeded.

Definition at line 77 of file uvm.cpp.

LIB_API void vm::DumpStatistics ( )

Definition at line 131 of file uvm.cpp.

LIB_API void vm::EndOnDemandCommits ( )

decrements the reference count begun by BeginOnDemandCommit and removes the page fault handler when it reaches 0.

thread-safe.

Definition at line 125 of file uvm.cpp.

static AddressRangeDescriptor* vm::FindDescriptor ( uintptr_t  address)
static

Definition at line 372 of file wvm.cpp.

LIB_API void vm::Free ( void *  p,
size_t  size = 0 
)

decommit memory and release address space.

Parameters
pa pointer previously returned by Allocate.
sizeis required by the POSIX implementation and ignored on Windows. it also ensures compatibility with UniqueRange.

(this differs from ReleaseAddressSpace, which must account for extra padding/alignment to largePageSize.)

Definition at line 113 of file uvm.cpp.

static Status vm::InitHandler ( )
static

Definition at line 519 of file wvm.cpp.

LIB_API bool vm::Protect ( uintptr_t  address,
size_t  size,
int  prot 
)

set the memory protection flags for all pages that intersect the given interval.

the pages must currently be committed.

Parameters
protmemory protection flags: PROT_NONE or a combination of PROT_READ, PROT_WRITE, PROT_EXEC.

Definition at line 86 of file uvm.cpp.

LIB_API void vm::ReleaseAddressSpace ( void *  p,
size_t  size = 0 
)

release address space and decommit any memory.

Parameters
pa pointer previously returned by ReserveAddressSpace.
sizeis required by the POSIX implementation and ignored on Windows. it also ensures compatibility with UniqueRange.

Definition at line 49 of file uvm.cpp.

LIB_API void * vm::ReserveAddressSpace ( size_t  size,
size_t  commitSize = largePageSize,
PageType  pageType = kDefault,
int  prot = PROT_READ|PROT_WRITE 
)

reserve address space and set the parameters for any later on-demand commits.

Parameters
sizedesired number of bytes. any additional space in the last page is also accessible.
commitSize[bytes] how much to commit each time. larger values reduce the number of page faults at the cost of additional internal fragmentation. must be a multiple of largePageSize unless pageType == kSmall.
pageTypechooses between large/small pages for commits.
protmemory protection flags for newly committed pages.
Returns
base address (aligned to the respective page size) or 0 if address space/descriptor storage is exhausted (an error dialog will also be raised). must be freed via ReleaseAddressSpace.

Definition at line 40 of file uvm.cpp.

static bool vm::ShouldUseLargePages ( size_t  allocationSize,
DWORD  allocationType,
PageType  pageType 
)
static

Definition at line 155 of file wvm.cpp.

static void vm::ShutdownHandler ( )
static

Definition at line 527 of file wvm.cpp.

vm::TIMER_ADD_CLIENT ( tc_commit  )
static LONG CALLBACK vm::VectoredHandler ( const PEXCEPTION_POINTERS  ep)
static

Definition at line 469 of file wvm.cpp.

Variable Documentation

PVOID vm::handler
static

Definition at line 515 of file wvm.cpp.

ModuleInitState vm::initState
static

Definition at line 516 of file wvm.cpp.

bool vm::largePageAllocationTookTooLong = false
static

Definition at line 153 of file wvm.cpp.

AddressRangeDescriptor vm::ranges[2 *os_cpu_MaxProcessors]
static

Definition at line 366 of file wvm.cpp.

volatile intptr_t vm::references = 0
static

Definition at line 517 of file wvm.cpp.