org.apache.ignite.configuration

## Class MemoryConfiguration

- java.lang.Object
- - org.apache.ignite.configuration.MemoryConfiguration

All Implemented Interfaces:
  Serializable

    public class MemoryConfiguration
    extends Object
    implements Serializable

A page memory configuration for an Apache Ignite node. The page memory is a manageable off-heap based memory architecture that divides all expandable memory regions into pages of fixed size (see `getPageSize()`. An individual page can store one or many cache key-value entries that allows reusing the memory in the most efficient way and avoid memory fragmentation issues.

By default, the page memory allocates a single expandable memory region using settings of `createDefaultPolicyConfig()`. All the caches that will be configured in an application will be mapped to this memory region by default, thus, all the cache data will reside in that memory region.

If initial size of the default memory region doesn't satisfy requirements or it's required to have multiple memory regions with different properties then `MemoryPolicyConfiguration` can be used for both scenarios. For instance, using memory policies you can define memory regions of different maximum size, eviction policies, swapping options, etc. Once you define a new memory region you can bind particular Ignite caches to it.

To learn more about memory policies refer to `MemoryPolicyConfiguration` documentation.

Sample configuration below shows how to make 5 GB memory regions the default one for Apache Ignite:

         <property name="memoryConfiguration">
             <bean class="org.apache.ignite.configuration.MemoryConfiguration">
                 <property name="systemCacheInitialSize" value="#{100 * 1024 * 1024}"/>
                 <property name="defaultMemoryPolicyName" value="default_mem_plc"/>

                 <property name="memoryPolicies">
                     <list>
                         <bean class="org.apache.ignite.configuration.MemoryPolicyConfiguration">
                             <property name="name" value="default_mem_plc"/>
                             <property name="initialSize" value="#{5 * 1024 * 1024 * 1024}"/>
                         </bean>
                     </list>
                 </property>
             </bean>
         </property>

See Also:
  Serialized Form

### Field Summary

Fields
`static String` `DFLT_MEM_PLC_DEFAULT_NAME` This name is assigned to default MemoryPolicy if no user-defined default MemPlc is specified
`static long` `DFLT_MEMORY_POLICY_INITIAL_SIZE` Default memory policy start size (256 MB).
`static long` `DFLT_MEMORY_POLICY_MAX_SIZE` Default memory policy's size is 80% of physical memory available on current machine.
`static int` `DFLT_PAGE_SIZE` Default memory page size.

### Constructor Summary

Constructors
Constructor and Description
`MemoryConfiguration()`

### Method Summary

Methods
`MemoryPolicyConfiguration` `createDefaultPolicyConfig()` Creates a configuration for the default memory policy that will instantiate the default memory region.
`int` `getConcurrencyLevel()` Returns the number of concurrent segments in Ignite internal page mapping tables.
`String` `getDefaultMemoryPolicyName()` Gets a name of default memory policy.
`long` `getDefaultMemoryPolicySize()` Gets a size for default memory policy overridden by user.
`MemoryPolicyConfiguration[]` `getMemoryPolicies()` Gets an array of all memory policies configured.
`int` `getPageSize()` The pages memory consists of one or more expandable memory regions defined by `MemoryPolicyConfiguration`.
`long` `getSystemCacheInitialSize()` Initial size of a memory region reserved for system cache.
`long` `getSystemCacheMaxSize()` Maximum memory region size reserved for system cache.
`MemoryConfiguration` `setConcurrencyLevel(int concLvl)` Sets the number of concurrent segments in Ignite internal page mapping tables.
`MemoryConfiguration` `setDefaultMemoryPolicyName(String dfltMemPlcName)` Sets the name for the default memory policy that will initialize the default memory region.
`MemoryConfiguration` `setDefaultMemoryPolicySize(long dfltMemPlcSize)` Overrides size of default memory policy which is created automatically.
`MemoryConfiguration` `setMemoryPolicies(MemoryPolicyConfiguration... memPlcs)` Sets memory policies configurations.
`MemoryConfiguration` `setPageSize(int pageSize)` Changes the page size.
`MemoryConfiguration` `setSystemCacheInitialSize(long sysCacheInitSize)` Sets initial size of a memory region reserved for system cache.
`MemoryConfiguration` `setSystemCacheMaxSize(long sysCacheMaxSize)` Sets maximum memory region size reserved for system cache.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### DFLT_MEMORY_POLICY_INITIAL_SIZE

    public static final long DFLT_MEMORY_POLICY_INITIAL_SIZE

Default memory policy start size (256 MB).

See Also:
  Constant Field Values

#### DFLT_MEMORY_POLICY_MAX_SIZE

    public static final long DFLT_MEMORY_POLICY_MAX_SIZE

Default memory policy's size is 80% of physical memory available on current machine.

#### DFLT_PAGE_SIZE

    public static final int DFLT_PAGE_SIZE

Default memory page size.

See Also:
  Constant Field Values

#### DFLT_MEM_PLC_DEFAULT_NAME

    public static final String DFLT_MEM_PLC_DEFAULT_NAME

This name is assigned to default MemoryPolicy if no user-defined default MemPlc is specified

See Also:
  Constant Field Values

### Constructor Detail

#### MemoryConfiguration

    public MemoryConfiguration()

### Method Detail

#### getSystemCacheInitialSize

    public long getSystemCacheInitialSize()

Initial size of a memory region reserved for system cache.

Returns:
  Size in bytes.

#### setSystemCacheInitialSize

    public MemoryConfiguration setSystemCacheInitialSize(long sysCacheInitSize)

Sets initial size of a memory region reserved for system cache. Default value is `DFLT_SYS_CACHE_INIT_SIZE`

Parameters:
  `sysCacheInitSize` - Size in bytes.
Returns:
  `this` for chaining.

#### getSystemCacheMaxSize

    public long getSystemCacheMaxSize()

Maximum memory region size reserved for system cache.

Returns:
  Size in bytes.

#### setSystemCacheMaxSize

    public MemoryConfiguration setSystemCacheMaxSize(long sysCacheMaxSize)

Sets maximum memory region size reserved for system cache. The total size should not be less than 10 MB due to internal data structures overhead.

Parameters:
  `sysCacheMaxSize` - Maximum size in bytes for system cache memory region.
Returns:
  `this` for chaining.

#### getPageSize

    public int getPageSize()

The pages memory consists of one or more expandable memory regions defined by `MemoryPolicyConfiguration`. Every memory region is split on pages of fixed size that store actual cache entries.

Returns:
  Page size in bytes.

#### setPageSize

    public MemoryConfiguration setPageSize(int pageSize)

Changes the page size. Default value is `DFLT_PAGE_SIZE`

Parameters:
  `pageSize` - Page size in bytes.

#### getMemoryPolicies

    public MemoryPolicyConfiguration[] getMemoryPolicies()

Gets an array of all memory policies configured. Apache Ignite will instantiate a dedicated memory region per policy. An Apache Ignite cache can be mapped to a specific policy with `CacheConfiguration.setMemoryPolicyName(String)` method.

Returns:
  Array of configured memory policies.

#### setMemoryPolicies

    public MemoryConfiguration setMemoryPolicies(MemoryPolicyConfiguration... memPlcs)

Sets memory policies configurations.

Parameters:
  `memPlcs` - Memory policies configurations.

#### createDefaultPolicyConfig

    public MemoryPolicyConfiguration createDefaultPolicyConfig()

Creates a configuration for the default memory policy that will instantiate the default memory region. To override settings of the default memory policy in order to create the default memory region with different parameters, create own memory policy first, pass it to `setMemoryPolicies(MemoryPolicyConfiguration...)` method and change the name of the default memory policy with `setDefaultMemoryPolicyName(String)`.

Returns:
  default Memory policy configuration.

#### getConcurrencyLevel

    public int getConcurrencyLevel()

Returns the number of concurrent segments in Ignite internal page mapping tables. By default equals to the number of available CPUs multiplied by 4.

Returns:
  Mapping table concurrency level.

#### setConcurrencyLevel

    public MemoryConfiguration setConcurrencyLevel(int concLvl)

Sets the number of concurrent segments in Ignite internal page mapping tables.

Parameters:
  `concLvl` - Mapping table oncurrency level.

#### getDefaultMemoryPolicySize

    public long getDefaultMemoryPolicySize()

Gets a size for default memory policy overridden by user.

Returns:
  default memory policy size overridden by user or -1 if nothing was specified.

#### setDefaultMemoryPolicySize

    public MemoryConfiguration setDefaultMemoryPolicySize(long dfltMemPlcSize)

Overrides size of default memory policy which is created automatically. If user doesn't specify any memory policy configuration, a default one with default size (80% of available RAM) is created by Ignite. This property allows user to specify desired size of default memory policy without having to use more verbose syntax of MemoryPolicyConfiguration elements.

Parameters:
  `dfltMemPlcSize` - Size of default memory policy overridden by user.

#### getDefaultMemoryPolicyName

    public String getDefaultMemoryPolicyName()

Gets a name of default memory policy.

Returns:
  A name of a custom memory policy configured with `MemoryConfiguration` or `null` of the default policy is used.

#### setDefaultMemoryPolicyName

    public MemoryConfiguration setDefaultMemoryPolicyName(String dfltMemPlcName)

Sets the name for the default memory policy that will initialize the default memory region. To set own default memory policy, create the policy first, pass it to `setMemoryPolicies(MemoryPolicyConfiguration...)` method and change the name of the default memory policy with `MemoryConfiguration#setDefaultMemoryPolicyName(String)`. If nothing is specified by user, it is set to `DFLT_MEM_PLC_DEFAULT_NAME` value.

Parameters:
  `dfltMemPlcName` - Name of a memory policy to be used as default one.

2017 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Fabric | : ver. 2.0.0
Release Date | : April 30 2017