Configuring Subsystem and Process MSpaces

The Subsystem always uses local memory. You can set the minimum size of the external MSpace for the Subsystem, networking components, and RTSS processes wRTOS Settings.

Note: If you do not allocate MSpace memory at process startup, your first memory request will be non-deterministic.

Note: Ensure the external MSpace commit size is large enough to support your application’s memory needs. Suppose the external MSpace does not have enough memory to handle application requests. In that case, the allocation requests will fail (when Auto expand MSpaces is disabled), or a non-deterministic call will be made to acquire more memory from Windows based on the expand size set in the wRTOS Settings.

MSpaces logic can be configured to Automatically Expand and/or Shrink. When an MSpace does not have enough memory to fulfill allocation requests, the Subsystem behaves as follows:

The table below describes the configurable MSpace behaviors:

Behavior MSpaces
 

Subsystem Default

(via wRTOS Settings)

Individual Override

(via RtssRun and Task Manager)

Whether or not to allocate MSpaces memory at process startup

No

Yes

/i initial_size

Note: This does not happen when you use wRTOS Native or Managed APIs to start a process, unless you pass the initial size of the process MSpaces to those APIs.

Whether or not to automatically expand MSpaces on depletion

Yes

Yes

/e expand_size

Setting the minimum expandable size of the external MSpace

Yes

Yes

/e expand_size

Whether or not to automatically shrink external MSpace on freeing

Yes No

Setting the minimum size of a process MSpace

Yes

Yes

/i initial_size

Note: The expandable feature of a process’ external MSpace can be individually overridden using RtssRun with the /e expand_size option. When the specified /e expand_size is zero, this disables automatic expansion for the process’ MSpaces.

Note: A process’ MSpaces can be configured to shrink automatically at the time of allocation, trimming its pool cache, or freeing memory allocated directly from the MSpaces. This decreases the free memory in the MSpaces. However, it does not shrink an MSpace below its minimum size. You can disable this automatic shrink feature in wRTOS Settings. At process exit, all MSpace memory will be freed.

Regardless of the Subsystem default setting for memory use and the setting for MSpaces, you can monitor the size of the local pool and pool cache for any MSpace using RtQueryProcessMSpace. You can expand the local pool by using RtExpandMSpace. Rather than wait until the MSpace memory is fully depleted, you can force the MSpace to expand. This allows you to decide when to handle a non-deterministic call within your application.

Note: You cannot expand your MSpace or request additional memory from Windows from within a shutdown handler.

All memory allocations explicitly or implicitly in the RTSS application are allocated from the Subsystem or process MSpaces. As a result, the following functions become deterministic and can be called in the shutdown handler:

RtCreateSharedMemory

malloc

RtCreateSemaphore

RtOpenSharedMemory

calloc

RtOpenSemaphore

HeapAlloc

realloc

RtCloseHandle

HeapCreate

free

InitializeCriticalSection

HeapDestroy

RtCreateEvent

DeleteCriticalSection

HeapFree

RtOpenEvent

CreateThread* The stack has no guard page for the thread.

HeapReAlloc

RtCreateMutex

 

RtAllocateLocalMemoryEx

RtOpenMutex

 

Related topics: