Shared Address Space, base runtime for shared and persistent memory for multi-thread/multi-core applications.
More...
|
__C__ unsigned long | getMemLow () |
| Get the Region's lowest memory address.
|
|
__C__ unsigned long | getMemHigh () |
| Get the Region's highest memory address.
|
|
__C__ void | setSASmemrange (unsigned long low, unsigned long high) |
| Set the Region's low/high memory address for testing.
|
|
__C__ int | SASJoinRegion () |
| Join this process to a SAS Region.
|
|
__C__ int | SASJoinRegionByName (const char *store_name) |
| Join this process to a named SAS Region.
|
|
__C__ void * | SASBlockAlloc (unsigned long blockSize) |
| Allocate a block of memory within SAS Storage.
|
|
__C__ void | SASBlockDealloc (void *blockAddr, unsigned long blockSize) |
| Deallocate a block of memory within SAS Storage.
|
|
__C__ void | SASListFreeRegion (void **blockAddr, unsigned long *blockSize, int *count) |
| Return lists of currently free segment block addresses and sizes.
|
|
__C__ void | SASListAllocatedRegion (void **blockAddr, unsigned long *blockSize, int *count) |
| Return lists of currently allocated segment block addresses and sizes.
|
|
__C__ void | SASListInUseMem (void **blockAddr, unsigned long *blockSize, int *count) |
| Return lists of currently allocated block addresses and sizes.
|
|
__C__ void | SASListFreeMem (void **blockAddr, unsigned long *blockSize, int *count) |
| Return lists of freed block addresses and sizes.
|
|
__C__ void | SASListUncommittedMem (void **blockAddr, unsigned long *blockSize, int *count) |
| Return lists of currently uncommitted block addresses and sizes.
|
|
__C__ unsigned int | SASAnchorFreeSpace () |
| Get the current number of free bytes within the Anchor blocks internal heap.
|
|
__C__ void | SASReset () |
| Reset the SAS Region back to initial state.
|
|
__C__ void | SASSeize () |
| Seize the anchor block master lock.
|
|
__C__ void | SASRelease () |
| Release the anchor block master lock.
|
|
__C__ void | SASResetSem () |
| Reset the internal Semaphores used by Seize/Release the SAS lock manager.
|
|
__C__ void | SASCleanUp () |
| Process wide cleanup for the SAS runtime. +* +*.
|
|
__C__ void | SASThreadSetUp () |
| Thread specific setup for secondary thread accessing the SAS region.
|
|
__C__ void | SASThreadCleanUp () |
| Thread specific cleanup for secondary thread accessing the SAS region.
|
|
__C__ void | SASRemove () |
| Remove the SAS Region.
|
|
__C__ void | setSASFinder (void *) |
| Sets the SAS finder pointer to a SAS block or utility object.
|
|
__C__ void * | getSASFinder () |
| Get the SAS finder address.
|
|
Shared Address Space, base runtime for shared and persistent memory for multi-thread/multi-core applications.
!
Provides APIs to manage (setup and take-down) the SAS Region and backing store for cooperating processes. The region is a contiguous subrange of the process address space. The exact range varies based on the platform on the platform (as defined in sasconf.h).
Associated with an active SAS region is SAS Store which is a directory contain backing files which are memory mapped for the active portions of the region. A region is fully qualified by its SAS Store (directory) path. Processes joined to the same SAS story are accessing the same data at the same virtual address.
- Note
- : For Linux this means memory mapping the pages from the kernel's file cache, and so we are sharing the same real pages across all partipating processes. This enables zero copy sharing and persistence.
Processes using different SAS Store paths are accessing logically different and disjoint regions. A process can only access one SAS region but there is no limit (other than files system capacity) to the number different SAS regions accessed by different groups of cooperating processes.
The SAS region address range and backing file store are managed via a power of 2 buddy system. Logically the region is divided into segments and blocks. Segment are a fixed power of 2 size (defined for the platform by sasconf.h) and alignment within the region. Blocks are a variable power of 2 size and have an alignment matching their size or better. Logically blocks are sub-allocated from allocated segments (have a backing file and can be mmaped) which are sub-allocated from the region.
- Todo:
- The current runtime restricts blocks to segment size or smaller. Creating larger blocks would require creating (power of 2) multiple segments (and backing files which have to memory mapped) while holding the global anchor block lock. Future releases may remove this restriction.
- Note
- Segments and blocks inherit their virtual address (within the process) from the region. The region has a fixed starting address and segments always have a unique offset (and file index) within the region. The segment's file index is used to generate the unique file name within the SAS store directory. Obviously blocks inherit their virtual address from the containing segment which inherits from the region.
The segment is the granule of backing file allocation and memory mapping. Segment backing files are always extended to the full segment size at creation. This minimizes OS overhead by minimizing file system and memory mapping operations at runtime. Segments are not allocated (and backing files created) until additional block space is needed (when free block space, of the required size and alignment, in currently allocated segments, is depleted). This is done implicitly under the block allocate call.
- Note
- SASJoinRegion and related functions (SASTHreadSetUp) establish a sigaction handler for signal SIGSEGV. This handles the case when one process, sharing a named Region allocates a new segment and backing. Other processes (sharing the same Region) are not immediately aware of this and need not perform any specific actions until or unless that process references data in that segment. This will generate a SIGSEGV and the SAS sigaction handler will attach this segment by mmapping the associated backing file into the faulting process at the assigned address.
-
Applications that set their own signal to sigaction handlers for SIGSEGV should be aware of this and plan for proper nesting. Applications should establish their SIGSEGV handlers before joining. The SASJoinRegion will preserve the the "old action" as part of setting it own SIGSEGV handler.
-
When the SPHDE runtime handler gets control it will verify that the faulting address is within the SAS Region. If it is not, it is likely a error or something that the application should handle itself. The SPHDE runtime handler will check if the "old action" was SIG_DFL or has it own signal or sigaction handler. If the application defined it own handler SPHDE will attempt to call that handler. Otherwise SPHDE runtime handler will print a back trace and exit the effected process (or thread).
The runtime also sets up shared memory segments (shmat) for SAS locks. SAS locks need to be shared but should not persist across reboot (like memory mapped files do). Different SAS stores must have independent locks (different lock segments). So lock segments are allocated/attached via shmget/shmat using a key generated (ftok) from the SAS Store path.
__C__ int SASJoinRegion |
( |
| ) |
|
|
extern |
Join this process to a SAS Region.
Join this process to the SAS Region based on the anchor segment in the SAS Store (either the default '.' directory or the path specified in the environment variable SASSTOREPATH). The anchor segment contains the anchor block including the indexes that manage segments and (free and allocated) block space within the region.
If the backing file for the anchor segment does not exist in the SAS Store directory, the runtime creates a "SegmentSize" backing file and mmaps that file at SAS memLow. The lowest part of this segment is initialed as the SAS anchor block.
Otherwise the the runtime mmaps the anchor segment at memLow and proceeds to bring up the rest of the SAS environment. This includes mmaping additional segments from the SAS Store.
The join function also checks for, and if needed initializes, the matching lock segments. The lock segments are allocated/attached via shmget/shmat using a key generated from the SAS Store path. This insures that applications using different SAS stores also have independent lock segments.
@return a 0 value indicates success, otherwise failure.
__C__ int SASJoinRegionByName |
( |
const char * |
store_name | ) |
|
|
extern |
Join this process to a named SAS Region.
Join this process to the SAS Region based on the anchor segment backing file in the named SAS Store. The anchor segment contains the anchor block including the indexes that manage segments and (free and allocated) block space within the region.
If the backing file for the anchor segment does not exist in the SAS Store directory, the runtime creates a "SegmentSize" backing file and mmaps that file at SAS memLow. The lowest part of this segment is initialed as the SAS anchor block.
Otherwise the the runtime mmaps the anchor segment at memLow and proceeds to bring up the rest of the SAS environment. This includes mmaping additional segments from the SAS Store.
The join function also checks for, and if needed initializes, the matching lock segments. The lock segments are allocated/attached via shmat using a key generated from the SAS Store path. This insures that applications using different SAS stores also have independent lock segments.
Finally the runtime sets up as sigsegv handler. This allows the SAS runtime to automatically attach segments created by other processes in this SAS store.
- Parameters
-
store_name | C string containing the path to this SAS store directory. |
- Returns
- a 0 value indicates success, otherwise failure.