ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [53/59] [abbrv] ignite git commit: IGNITE-5072 - Updated memory metrics to comply with other metrics
Date Fri, 28 Apr 2017 06:58:14 GMT
http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
index ae594fa..5062d0f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/IgniteCacheDatabaseSharedManager.java
@@ -18,7 +18,9 @@
 package org.apache.ignite.internal.processors.cache.database;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
@@ -28,8 +30,8 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.MemoryMetrics;
 import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.DataPageEvictionMode;
+import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.MemoryConfiguration;
 import org.apache.ignite.configuration.MemoryPolicyConfiguration;
 import org.apache.ignite.internal.GridKernalContext;
@@ -38,8 +40,8 @@ import org.apache.ignite.internal.mem.DirectMemoryProvider;
 import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider;
 import org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider;
 import org.apache.ignite.internal.pagemem.PageMemory;
-import org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage;
 import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl;
+import org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheMapEntry;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedManagerAdapter;
@@ -52,6 +54,7 @@ import org.apache.ignite.internal.processors.cache.database.freelist.FreeList;
 import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl;
 import org.apache.ignite.internal.processors.cache.database.tree.reuse.ReuseList;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture;
+import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
 import org.apache.ignite.mxbean.MemoryMetricsMXBean;
@@ -67,7 +70,7 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     static final String SYSTEM_MEMORY_POLICY_NAME = "sysMemPlc";
 
     /** Minimum size of memory chunk */
-    private static final long MIN_PAGE_MEMORY_SIZE = 1024 * 1024;
+    private static final long MIN_PAGE_MEMORY_SIZE = 10 * 1024 * 1024;
 
     /** */
     protected Map<String, MemoryPolicy> memPlcMap;
@@ -125,25 +128,32 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     private void registerMetricsMBeans() {
         IgniteConfiguration cfg = cctx.gridConfig();
 
-        for (MemoryMetrics memMetrics : memMetricsMap.values())
-            registerMetricsMBean((MemoryMetricsImpl) memMetrics, cfg);
+        for (MemoryMetrics memMetrics : memMetricsMap.values()) {
+            MemoryPolicyConfiguration memPlcCfg = memPlcMap.get(memMetrics.getName()).config();
+
+            registerMetricsMBean((MemoryMetricsImpl)memMetrics, memPlcCfg, cfg);
+        }
     }
 
     /**
      * @param memMetrics Memory metrics.
+     * @param memPlcCfg Memory policy configuration.
+     * @param cfg Ignite configuration.
      */
-    private void registerMetricsMBean(MemoryMetricsImpl memMetrics, IgniteConfiguration cfg) {
+    private void registerMetricsMBean(MemoryMetricsImpl memMetrics,
+        MemoryPolicyConfiguration memPlcCfg,
+        IgniteConfiguration cfg) {
         try {
             U.registerMBean(
                     cfg.getMBeanServer(),
                     cfg.getIgniteInstanceName(),
                     "MemoryMetrics",
-                    memMetrics.getName(),
-                    memMetrics,
+                    memPlcCfg.getName(),
+                    new MemoryMetricsMXBeanImpl(memMetrics, memPlcCfg),
                     MemoryMetricsMXBean.class);
         }
         catch (JMException e) {
-            log.warning("Failed to register MBean for MemoryMetrics with name: '" + memMetrics.getName() + "'");
+            U.error(log, "Failed to register MBean for MemoryMetrics with name: '" + memMetrics.getName() + "'", e);
         }
     }
 
@@ -196,35 +206,35 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     }
 
     /**
-     * @param dbCfg Database config.
+     * @param memCfg Database config.
      */
-    protected void initPageMemoryPolicies(MemoryConfiguration dbCfg) {
-        MemoryPolicyConfiguration[] memPlcsCfgs = dbCfg.getMemoryPolicies();
+    protected void initPageMemoryPolicies(MemoryConfiguration memCfg) {
+        MemoryPolicyConfiguration[] memPlcsCfgs = memCfg.getMemoryPolicies();
 
         if (memPlcsCfgs == null) {
             //reserve place for default and system memory policies
             memPlcMap = U.newHashMap(2);
             memMetricsMap = U.newHashMap(2);
 
-            addMemoryPolicy(dbCfg,
-                    dbCfg.createDefaultPolicyConfig(),
-                    DFLT_MEM_PLC_DEFAULT_NAME);
+            addMemoryPolicy(memCfg,
+                memCfg.createDefaultPolicyConfig(),
+                DFLT_MEM_PLC_DEFAULT_NAME);
 
-            log.warning("No user-defined default MemoryPolicy found; system default of 1GB size will be used.");
+            U.warn(log, "No user-defined default MemoryPolicy found; system default of 1GB size will be used.");
         }
         else {
-            String dfltMemPlcName = dbCfg.getDefaultMemoryPolicyName();
+            String dfltMemPlcName = memCfg.getDefaultMemoryPolicyName();
 
             if (DFLT_MEM_PLC_DEFAULT_NAME.equals(dfltMemPlcName) && !hasCustomDefaultMemoryPolicy(memPlcsCfgs)) {
                 //reserve additional place for default and system memory policies
                 memPlcMap = U.newHashMap(memPlcsCfgs.length + 2);
                 memMetricsMap = U.newHashMap(memPlcsCfgs.length + 2);
 
-                addMemoryPolicy(dbCfg,
-                        dbCfg.createDefaultPolicyConfig(),
-                        DFLT_MEM_PLC_DEFAULT_NAME);
+                addMemoryPolicy(memCfg,
+                    memCfg.createDefaultPolicyConfig(),
+                    DFLT_MEM_PLC_DEFAULT_NAME);
 
-                log.warning("No user-defined default MemoryPolicy found; system default will be allocated.");
+                U.warn(log, "No user-defined default MemoryPolicy found; system default of 1GB size will be used.");
             }
             else {
                 //reserve additional space for system memory policy only
@@ -233,12 +243,12 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
             }
 
             for (MemoryPolicyConfiguration memPlcCfg : memPlcsCfgs)
-                addMemoryPolicy(dbCfg, memPlcCfg, memPlcCfg.getName());
+                addMemoryPolicy(memCfg, memPlcCfg, memPlcCfg.getName());
         }
 
-        addMemoryPolicy(dbCfg,
-                createSystemMemoryPolicy(dbCfg.getSystemCacheMemorySize()),
-                SYSTEM_MEMORY_POLICY_NAME);
+        addMemoryPolicy(memCfg,
+            createSystemMemoryPolicy(memCfg.getSystemCacheInitialSize(), memCfg.getSystemCacheMaxSize()),
+            SYSTEM_MEMORY_POLICY_NAME);
     }
 
     /**
@@ -265,7 +275,7 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
         if (memPlcName.equals(dfltMemPlcName))
             dfltMemPlc = memPlc;
         else if (memPlcName.equals(DFLT_MEM_PLC_DEFAULT_NAME))
-            log.warning("Memory Policy with name 'default' isn't used as a default. " +
+            U.warn(log, "Memory Policy with name 'default' isn't used as a default. " +
                     "Please check Memory Policies configuration.");
     }
 
@@ -291,25 +301,32 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     }
 
     /**
-     * @param sysCacheMemSize size of PageMemory to be created for system cache.
+     * @param sysCacheInitSize Initial size of PageMemory to be created for system cache.
+     * @param sysCacheMaxSize Maximum size of PageMemory to be created for system cache.
+     *
+     * @return {@link MemoryPolicyConfiguration configuration} of MemoryPolicy for system cache.
      */
-    private MemoryPolicyConfiguration createSystemMemoryPolicy(long sysCacheMemSize) {
+    private MemoryPolicyConfiguration createSystemMemoryPolicy(long sysCacheInitSize, long sysCacheMaxSize) {
         MemoryPolicyConfiguration res = new MemoryPolicyConfiguration();
 
         res.setName(SYSTEM_MEMORY_POLICY_NAME);
-        res.setSize(sysCacheMemSize);
+        res.setInitialSize(sysCacheInitSize);
+        res.setMaxSize(sysCacheMaxSize);
 
         return res;
     }
 
     /**
-     * @param dbCfg configuration to validate.
+     * @param memCfg configuration to validate.
      */
-    private void validateConfiguration(MemoryConfiguration dbCfg) throws IgniteCheckedException {
-        MemoryPolicyConfiguration[] plcCfgs = dbCfg.getMemoryPolicies();
+    private void validateConfiguration(MemoryConfiguration memCfg) throws IgniteCheckedException {
+        MemoryPolicyConfiguration[] plcCfgs = memCfg.getMemoryPolicies();
 
         Set<String> plcNames = (plcCfgs != null) ? U.<String>newHashSet(plcCfgs.length) : new HashSet<String>(0);
 
+        checkSystemMemoryPolicySizeConfiguration(memCfg.getSystemCacheInitialSize(),
+            memCfg.getSystemCacheMaxSize());
+
         if (plcCfgs != null) {
             for (MemoryPolicyConfiguration plcCfg : plcCfgs) {
                 assert plcCfg != null;
@@ -318,24 +335,68 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
 
                 checkPolicySize(plcCfg);
 
-                checkPolicyEvictionProperties(plcCfg, dbCfg);
+                checkPolicyEvictionProperties(plcCfg, memCfg);
             }
         }
 
-        checkDefaultPolicyConfiguration(dbCfg.getDefaultMemoryPolicyName(), plcNames);
+        checkDefaultPolicyConfiguration(
+                memCfg.getDefaultMemoryPolicyName(),
+                memCfg.getDefaultMemoryPolicySize(),
+                plcNames);
+    }
+
+    /**
+     * @param sysCacheInitSize System cache initial size.
+     * @param sysCacheMaxSize System cache max size.
+     *
+     * @throws IgniteCheckedException In case of validation violation.
+     */
+    private void checkSystemMemoryPolicySizeConfiguration(long sysCacheInitSize, long sysCacheMaxSize) throws IgniteCheckedException {
+        if (sysCacheInitSize < MIN_PAGE_MEMORY_SIZE)
+            throw new IgniteCheckedException("Initial size for system cache must have size more than 10MB (use " +
+                "MemoryConfiguration.systemCacheInitialSize property to set correct size in bytes); " +
+                "size: " + U.readableSize(sysCacheInitSize, true)
+            );
+
+        if (sysCacheMaxSize < sysCacheInitSize)
+            throw new IgniteCheckedException("MaxSize of system cache must not be smaller than " +
+                "initialSize [initSize=" + U.readableSize(sysCacheInitSize, true) +
+                ", maxSize=" + U.readableSize(sysCacheMaxSize, true) + "]. " +
+                "Use MemoryConfiguration.systemCacheInitialSize/MemoryConfiguration.systemCacheMaxSize " +
+                "properties to set correct sizes in bytes."
+            );
     }
 
     /**
      * @param dfltPlcName Default MemoryPolicy name.
+     * @param dfltPlcSize Default size of MemoryPolicy overridden by user (equals to -1 if wasn't specified by user).
      * @param plcNames All MemoryPolicy names.
      * @throws IgniteCheckedException In case of validation violation.
      */
-    private static void checkDefaultPolicyConfiguration(String dfltPlcName, Set<String> plcNames) throws IgniteCheckedException {
+    private static void checkDefaultPolicyConfiguration(
+        String dfltPlcName,
+        long dfltPlcSize,
+        Collection<String> plcNames
+    ) throws IgniteCheckedException {
+        if (dfltPlcSize != -1) {
+            if (!F.eq(dfltPlcName, MemoryConfiguration.DFLT_MEM_PLC_DEFAULT_NAME))
+                throw new IgniteCheckedException("User-defined MemoryPolicy configuration " +
+                    "and defaultMemoryPolicySize properties are set at the same time. " +
+                    "Delete either MemoryConfiguration.defaultMemoryPolicySize property " +
+                    "or user-defined default MemoryPolicy configuration");
+
+            if (dfltPlcSize < MIN_PAGE_MEMORY_SIZE)
+                throw new IgniteCheckedException("User-defined default MemoryPolicy size is less than 1MB. " +
+                        "Use MemoryConfiguration.defaultMemoryPolicySize property to set correct size.");
+        }
+
         if (!DFLT_MEM_PLC_DEFAULT_NAME.equals(dfltPlcName)) {
             if (dfltPlcName.isEmpty())
                 throw new IgniteCheckedException("User-defined default MemoryPolicy name must be non-empty");
+
             if (!plcNames.contains(dfltPlcName))
-                throw new IgniteCheckedException("User-defined default MemoryPolicy name must be presented among configured MemoryPolices: " + dfltPlcName);
+                throw new IgniteCheckedException("User-defined default MemoryPolicy name " +
+                    "must be presented among configured MemoryPolices: " + dfltPlcName);
         }
     }
 
@@ -344,8 +405,17 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
      * @throws IgniteCheckedException If config is invalid.
      */
     private static void checkPolicySize(MemoryPolicyConfiguration plcCfg) throws IgniteCheckedException {
-        if (plcCfg.getSize() < MIN_PAGE_MEMORY_SIZE)
-            throw new IgniteCheckedException("MemoryPolicy must have size more than 1MB: " + plcCfg.getName());
+        if (plcCfg.getInitialSize() < MIN_PAGE_MEMORY_SIZE)
+            throw new IgniteCheckedException("MemoryPolicy must have size more than 10MB (use " +
+                "MemoryPolicyConfiguration.initialSize property to set correct size in bytes) " +
+                "[name=" + plcCfg.getName() + ", size=" + U.readableSize(plcCfg.getInitialSize(), true) + "]"
+            );
+
+        if (plcCfg.getMaxSize() < plcCfg.getInitialSize())
+            throw new IgniteCheckedException("MemoryPolicy maxSize must not be smaller than " +
+                "initialSize [name=" + plcCfg.getName() +
+                ", initSize=" + U.readableSize(plcCfg.getInitialSize(), true) +
+                ", maxSize=" + U.readableSize(plcCfg.getMaxSize(), true) + ']');
     }
 
     /**
@@ -366,7 +436,7 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
         if (plcCfg.getEmptyPagesPoolSize() <= 10)
             throw new IgniteCheckedException("Evicted pages pool size should be greater than 10: " + plcCfg.getName());
 
-        long maxPoolSize = plcCfg.getSize() / dbCfg.getPageSize() / 10;
+        long maxPoolSize = plcCfg.getMaxSize() / dbCfg.getPageSize() / 10;
 
         if (plcCfg.getEmptyPagesPoolSize() >= maxPoolSize) {
             throw new IgniteCheckedException("Evicted pages pool size should be lesser than " + maxPoolSize +
@@ -379,9 +449,11 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
      * @param observedNames Names of MemoryPolicies observed before.
      * @throws IgniteCheckedException If config is invalid.
      */
-    private static void checkPolicyName(String plcName, Set<String> observedNames) throws IgniteCheckedException {
+    private static void checkPolicyName(String plcName, Collection<String> observedNames)
+        throws IgniteCheckedException {
         if (plcName == null || plcName.isEmpty())
-            throw new IgniteCheckedException("User-defined MemoryPolicyConfiguration must have non-null and non-empty name.");
+            throw new IgniteCheckedException("User-defined MemoryPolicyConfiguration must have non-null and " +
+                "non-empty name.");
 
         if (observedNames.contains(plcName))
             throw new IgniteCheckedException("Two MemoryPolicies have the same name: " + plcName);
@@ -420,7 +492,17 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
      * @return MemoryMetrics for all MemoryPolicies configured in Ignite instance.
      */
     public Collection<MemoryMetrics> memoryMetrics() {
-        return memMetricsMap != null ? memMetricsMap.values() : null;
+        if (!F.isEmpty(memMetricsMap)) {
+            // Intentionally return a collection copy to make it explicitly serializable.
+            Collection<MemoryMetrics> res = new ArrayList<>(memMetricsMap.size());
+
+            for (MemoryMetrics metrics : memMetricsMap.values())
+                res.add(new MemoryMetricsSnapshot(metrics));
+
+            return res;
+        }
+        else
+            return Collections.emptyList();
     }
 
     /**
@@ -472,6 +554,20 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
                 memPlc.pageMemory().stop();
 
                 memPlc.evictionTracker().stop();
+
+                IgniteConfiguration cfg = cctx.gridConfig();
+
+                try {
+                    cfg.getMBeanServer().unregisterMBean(
+                        U.makeMBeanName(
+                            cfg.getIgniteInstanceName(),
+                            "MemoryMetrics",
+                            memPlc.memoryMetrics().getName()));
+                }
+                catch (JMException e) {
+                    U.error(log, "Failed to unregister MBean for memory metrics: " +
+                        memPlc.memoryMetrics().getName(), e);
+                }
             }
         }
     }
@@ -590,7 +686,7 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
         if (plcCfg.getPageEvictionMode() == DataPageEvictionMode.DISABLED)
             return;
 
-        long memorySize = plcCfg.getSize();
+        long memorySize = plcCfg.getMaxSize();
 
         PageMemory pageMem = memPlc.pageMemory();
 
@@ -614,36 +710,31 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     }
 
     /**
-     * @param dbCfg memory configuration with common parameters.
-     * @param plc memory policy with PageMemory specific parameters.
+     * @param memCfg memory configuration with common parameters.
+     * @param plcCfg memory policy with PageMemory specific parameters.
      * @param memMetrics {@link MemoryMetrics} object to collect memory usage metrics.
      * @return Memory policy instance.
      */
-    private MemoryPolicy initMemory(MemoryConfiguration dbCfg, MemoryPolicyConfiguration plc, MemoryMetricsImpl memMetrics) {
-        long[] sizes = calculateFragmentSizes(
-                dbCfg.getConcurrencyLevel(),
-                plc.getSize());
-
-        File allocPath = buildAllocPath(plc);
+    private MemoryPolicy initMemory(MemoryConfiguration memCfg, MemoryPolicyConfiguration plcCfg, MemoryMetricsImpl memMetrics) {
+        File allocPath = buildAllocPath(plcCfg);
 
         DirectMemoryProvider memProvider = allocPath == null ?
-            new UnsafeMemoryProvider(sizes) :
+            new UnsafeMemoryProvider(log) :
             new MappedFileMemoryProvider(
                 log,
-                allocPath,
-                true,
-                sizes);
+                allocPath);
 
-        PageMemory pageMem = createPageMemory(memProvider, dbCfg.getPageSize(), plc, memMetrics);
+        PageMemory pageMem = createPageMemory(memProvider, memCfg, plcCfg, memMetrics);
 
-        return new MemoryPolicy(pageMem, plc, memMetrics, createPageEvictionTracker(plc, pageMem));
+        return new MemoryPolicy(pageMem, plcCfg, memMetrics, createPageEvictionTracker(plcCfg,
+            (PageMemoryNoStoreImpl)pageMem));
     }
 
     /**
      * @param plc Memory Policy Configuration.
      * @param pageMem Page memory.
      */
-    private PageEvictionTracker createPageEvictionTracker(MemoryPolicyConfiguration plc, PageMemory pageMem) {
+    private PageEvictionTracker createPageEvictionTracker(MemoryPolicyConfiguration plc, PageMemoryNoStoreImpl pageMem) {
         if (Boolean.getBoolean("override.fair.fifo.page.eviction.tracker"))
             return new FairFifoPageEvictionTracker(pageMem, plc, cctx);
 
@@ -658,28 +749,6 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
     }
 
     /**
-     * Calculate fragment sizes for a cache with given size and concurrency level.
-     * @param concLvl Concurrency level.
-     * @param cacheSize Cache size.
-     */
-    protected long[] calculateFragmentSizes(int concLvl, long cacheSize) {
-        if (concLvl < 1)
-            concLvl = Runtime.getRuntime().availableProcessors();
-
-        long fragmentSize = cacheSize / concLvl;
-
-        if (fragmentSize < 1024 * 1024)
-            fragmentSize = 1024 * 1024;
-
-        long[] sizes = new long[concLvl];
-
-        for (int i = 0; i < concLvl; i++)
-            sizes[i] = fragmentSize;
-
-        return sizes;
-    }
-
-    /**
      * Builds allocation path for memory mapped file to be used with PageMemory.
      *
      * @param plc MemoryPolicyConfiguration.
@@ -701,18 +770,18 @@ public class IgniteCacheDatabaseSharedManager extends GridCacheSharedManagerAdap
      * Creates PageMemory with given size and memory provider.
      *
      * @param memProvider Memory provider.
-     * @param pageSize Page size.
+     * @param memCfg Memory configuartion.
      * @param memPlcCfg Memory policy configuration.
      * @param memMetrics MemoryMetrics to collect memory usage metrics.
      * @return PageMemory instance.
      */
     protected PageMemory createPageMemory(
         DirectMemoryProvider memProvider,
-        int pageSize,
+        MemoryConfiguration memCfg,
         MemoryPolicyConfiguration memPlcCfg,
         MemoryMetricsImpl memMetrics
     ) {
-        return new PageMemoryNoStoreImpl(log, memProvider, cctx, pageSize, memPlcCfg, memMetrics, false);
+        return new PageMemoryNoStoreImpl(log, memProvider, cctx, memCfg.getPageSize(), memPlcCfg, memMetrics, false);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java
index ed4cae0..4a7e951 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsImpl.java
@@ -18,17 +18,17 @@ package org.apache.ignite.internal.processors.cache.database;
 
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
+import org.apache.ignite.MemoryMetrics;
 import org.apache.ignite.configuration.MemoryPolicyConfiguration;
 import org.apache.ignite.internal.processors.cache.database.freelist.FreeListImpl;
 import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.mxbean.MemoryMetricsMXBean;
 import org.jsr166.LongAdder8;
 
 /**
  *
  */
-public class MemoryMetricsImpl implements MemoryMetricsMXBean {
+public class MemoryMetricsImpl implements MemoryMetrics {
     /** */
     private FreeListImpl freeList;
 
@@ -68,6 +68,8 @@ public class MemoryMetricsImpl implements MemoryMetricsMXBean {
     public MemoryMetricsImpl(MemoryPolicyConfiguration memPlcCfg) {
         this.memPlcCfg = memPlcCfg;
 
+        metricsEnabled = memPlcCfg.isMetricsEnabled();
+
         for (int i = 0; i < subInts; i++)
             allocRateCounters[i] = new LongAdder8();
     }
@@ -78,16 +80,6 @@ public class MemoryMetricsImpl implements MemoryMetricsMXBean {
     }
 
     /** {@inheritDoc} */
-    @Override public int getSize() {
-        return (int) (memPlcCfg.getSize() / (1024 * 1024));
-    }
-
-    /** {@inheritDoc} */
-    @Override public String getSwapFilePath() {
-        return memPlcCfg.getSwapFilePath();
-    }
-
-    /** {@inheritDoc} */
     @Override public long getTotalAllocatedPages() {
         return metricsEnabled ? totalAllocatedPages.longValue() : 0;
     }
@@ -264,19 +256,19 @@ public class MemoryMetricsImpl implements MemoryMetricsMXBean {
     }
 
     /** {@inheritDoc} */
-    @Override public void enableMetrics() {
+    public void enableMetrics() {
         metricsEnabled = true;
     }
 
     /** {@inheritDoc} */
-    @Override public void disableMetrics() {
+    public void disableMetrics() {
         metricsEnabled = false;
     }
 
     /**
      * @param rateTimeInterval Time interval used to calculate allocation/eviction rate.
      */
-    @Override public void rateTimeInterval(int rateTimeInterval) {
+    public void rateTimeInterval(int rateTimeInterval) {
         this.rateTimeInterval = rateTimeInterval;
     }
 
@@ -285,7 +277,7 @@ public class MemoryMetricsImpl implements MemoryMetricsMXBean {
      *
      * @param subInts Number of subintervals.
      */
-    @Override public void subIntervals(int subInts) {
+    public void subIntervals(int subInts) {
         assert subInts > 0;
 
         if (this.subInts == subInts)

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java
new file mode 100644
index 0000000..05c6677
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsMXBeanImpl.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.cache.database;
+
+import org.apache.ignite.MemoryMetrics;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
+import org.apache.ignite.mxbean.MemoryMetricsMXBean;
+
+/**
+ * MBean to expose {@link MemoryMetrics} through JMX interface.
+ */
+class MemoryMetricsMXBeanImpl implements MemoryMetricsMXBean {
+    /** */
+    private final MemoryMetricsImpl memMetrics;
+
+    /** */
+    private final MemoryPolicyConfiguration memPlcCfg;
+
+    /**
+     * @param memMetrics MemoryMetrics instance to expose through JMX interface.
+     * @param memPlcCfg configuration of memory policy this MX Bean is created for.
+     */
+    MemoryMetricsMXBeanImpl(MemoryMetricsImpl memMetrics,
+        MemoryPolicyConfiguration memPlcCfg
+    ) {
+        this.memMetrics = memMetrics;
+        this.memPlcCfg = memPlcCfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getAllocationRate() {
+        return memMetrics.getAllocationRate();
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getEvictionRate() {
+        return memMetrics.getEvictionRate();
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getLargeEntriesPagesPercentage() {
+        return memMetrics.getLargeEntriesPagesPercentage();
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getPagesFillFactor() {
+        return memMetrics.getPagesFillFactor();
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getTotalAllocatedPages() {
+        return memMetrics.getTotalAllocatedPages();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void rateTimeInterval(int rateTimeInterval) {
+        memMetrics.rateTimeInterval(rateTimeInterval);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void subIntervals(int subInts) {
+        memMetrics.subIntervals(subInts);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void enableMetrics() {
+        memMetrics.enableMetrics();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void disableMetrics() {
+        memMetrics.disableMetrics();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getName() {
+        return memMetrics.getName();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getInitialSize() {
+        return (int) (memPlcCfg.getInitialSize() / (1024 * 1024));
+    }
+
+    /** {@inheritDoc} */
+    @Override public int getMaxSize() {
+        return (int) (memPlcCfg.getMaxSize() / (1024 * 1024));
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getSwapFilePath() {
+        return memPlcCfg.getSwapFilePath();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java
new file mode 100644
index 0000000..5f337bd
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryMetricsSnapshot.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.database;
+
+import org.apache.ignite.MemoryMetrics;
+
+/**
+ *
+ */
+public class MemoryMetricsSnapshot implements MemoryMetrics {
+    /** */
+    private String name;
+
+    /** */
+    private long totalAllocatedPages;
+
+    /** */
+    private float allocationRate;
+
+    /** */
+    private float evictionRate;
+
+    /** */
+    private float largeEntriesPagesPercentage;
+
+    /** */
+    private float pagesFillFactor;
+
+    /**
+     * @param metrics Metrics instance to take a copy.
+     */
+    public MemoryMetricsSnapshot(MemoryMetrics metrics) {
+        name = metrics.getName();
+        totalAllocatedPages = metrics.getTotalAllocatedPages();
+        allocationRate = metrics.getAllocationRate();
+        evictionRate = metrics.getEvictionRate();
+        largeEntriesPagesPercentage = metrics.getLargeEntriesPagesPercentage();
+        pagesFillFactor = metrics.getPagesFillFactor();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String getName() {
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long getTotalAllocatedPages() {
+        return totalAllocatedPages;
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getAllocationRate() {
+        return allocationRate;
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getEvictionRate() {
+        return evictionRate;
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getLargeEntriesPagesPercentage() {
+        return largeEntriesPagesPercentage;
+    }
+
+    /** {@inheritDoc} */
+    @Override public float getPagesFillFactor() {
+        return pagesFillFactor;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicy.java
index 90e5ac1..cb35d33 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicy.java
@@ -16,7 +16,6 @@
  */
 package org.apache.ignite.internal.processors.cache.database;
 
-import org.apache.ignite.MemoryMetrics;
 import org.apache.ignite.configuration.MemoryPolicyConfiguration;
 import org.apache.ignite.internal.pagemem.PageMemory;
 import org.apache.ignite.internal.processors.cache.database.evict.PageEvictionTracker;
@@ -29,7 +28,7 @@ public class MemoryPolicy {
     private final PageMemory pageMem;
 
     /** */
-    private final MemoryMetrics memMetrics;
+    private final MemoryMetricsImpl memMetrics;
 
     /** */
     private final MemoryPolicyConfiguration cfg;
@@ -46,7 +45,7 @@ public class MemoryPolicy {
     public MemoryPolicy(
         PageMemory pageMem,
         MemoryPolicyConfiguration cfg,
-        MemoryMetrics memMetrics,
+        MemoryMetricsImpl memMetrics,
         PageEvictionTracker evictionTracker) {
         this.pageMem = pageMem;
         this.memMetrics = memMetrics;
@@ -71,7 +70,7 @@ public class MemoryPolicy {
     /**
      * @return Memory Metrics.
      */
-    public MemoryMetrics memoryMetrics() {
+    public MemoryMetricsImpl memoryMetrics() {
         return memMetrics;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/FairFifoPageEvictionTracker.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/FairFifoPageEvictionTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/FairFifoPageEvictionTracker.java
index 8847013..b7c6b57 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/FairFifoPageEvictionTracker.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/FairFifoPageEvictionTracker.java
@@ -14,6 +14,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
+
 package org.apache.ignite.internal.processors.cache.database.evict;
 
 import java.util.LinkedList;
@@ -21,7 +22,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.configuration.MemoryPolicyConfiguration;
 import org.apache.ignite.internal.pagemem.PageIdUtils;
-import org.apache.ignite.internal.pagemem.PageMemory;
+import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
 
 /**
@@ -36,7 +37,8 @@ public class FairFifoPageEvictionTracker extends PageAbstractEvictionTracker {
      * @param plcCfg Memory policy configuration.
      * @param sharedCtx Shared context.
      */
-    public FairFifoPageEvictionTracker(PageMemory pageMem,
+    public FairFifoPageEvictionTracker(
+        PageMemoryNoStoreImpl pageMem,
         MemoryPolicyConfiguration plcCfg,
         GridCacheSharedContext sharedCtx) {
         super(pageMem, plcCfg, sharedCtx);

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageAbstractEvictionTracker.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageAbstractEvictionTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageAbstractEvictionTracker.java
index 61f62fd..c61aced 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageAbstractEvictionTracker.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/PageAbstractEvictionTracker.java
@@ -18,10 +18,9 @@ package org.apache.ignite.internal.processors.cache.database.evict;
 
 import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.configuration.MemoryConfiguration;
 import org.apache.ignite.configuration.MemoryPolicyConfiguration;
 import org.apache.ignite.internal.pagemem.PageIdUtils;
-import org.apache.ignite.internal.pagemem.PageMemory;
+import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
@@ -42,7 +41,7 @@ public abstract class PageAbstractEvictionTracker implements PageEvictionTracker
     private static final int DAY = 24 * 60 * 60 * 1000;
 
     /** Page memory. */
-    protected final PageMemory pageMem;
+    protected final PageMemoryNoStoreImpl pageMem;
 
     /** Tracking array size. */
     protected final int trackingSize;
@@ -53,21 +52,13 @@ public abstract class PageAbstractEvictionTracker implements PageEvictionTracker
     /** Shared context. */
     private final GridCacheSharedContext sharedCtx;
 
-    /* TODO: IGNITE-4921: Will be removed after segments refactoring >>>> */
-    protected final int segBits;
-    protected final int idxBits;
-    protected final int segMask;
-    protected final int idxMask;
-    protected final int segmentPageCount;
-    /* <<<< */
-
     /**
      * @param pageMem Page memory.
      * @param plcCfg Memory policy configuration.
      * @param sharedCtx Shared context.
      */
     PageAbstractEvictionTracker(
-        PageMemory pageMem,
+        PageMemoryNoStoreImpl pageMem,
         MemoryPolicyConfiguration plcCfg,
         GridCacheSharedContext sharedCtx
     ) {
@@ -75,33 +66,7 @@ public abstract class PageAbstractEvictionTracker implements PageEvictionTracker
 
         this.sharedCtx = sharedCtx;
 
-        MemoryConfiguration memCfg = sharedCtx.kernalContext().config().getMemoryConfiguration();
-
-        /* TODO: IGNITE-4921: Will be removed after segments refactoring >>>> */
-        int concurrencyLevel = memCfg.getConcurrencyLevel();
-
-        if (concurrencyLevel < 1)
-            concurrencyLevel = Runtime.getRuntime().availableProcessors();
-
-        int pageSize = memCfg.getPageSize();
-
-        long segSize = plcCfg.getSize() / concurrencyLevel;
-
-        if (segSize < 1024 * 1024)
-            segSize = 1024 * 1024;
-
-        segmentPageCount = (int)(segSize / pageSize);
-
-        segBits = Integer.SIZE - Integer.numberOfLeadingZeros(concurrencyLevel - 1);
-
-        idxBits = PageIdUtils.PAGE_IDX_SIZE - segBits;
-
-        segMask = ~(-1 << segBits);
-
-        idxMask = ~(-1 << idxBits);
-        /* <<<< */
-
-        trackingSize = segmentPageCount << segBits;
+        trackingSize = pageMem.totalPages();
 
         baseCompactTs = (U.currentTimeMillis() - DAY) >> COMPACT_TS_SHIFT;
         // We subtract day to avoid fail in case of daylight shift or timezone change.
@@ -191,15 +156,7 @@ public abstract class PageAbstractEvictionTracker implements PageEvictionTracker
      * @return Position of page in tracking array.
      */
     int trackingIdx(int pageIdx) {
-        int inSegmentPageIdx = inSegmentPageIdx(pageIdx);
-
-        assert inSegmentPageIdx < segmentPageCount : inSegmentPageIdx;
-
-        int trackingIdx = segmentIdx(pageIdx) * segmentPageCount + inSegmentPageIdx;
-
-        assert trackingIdx < trackingSize : trackingIdx;
-
-        return trackingIdx;
+        return pageMem.pageSequenceNumber(pageIdx);
     }
 
     /**
@@ -209,36 +166,6 @@ public abstract class PageAbstractEvictionTracker implements PageEvictionTracker
      * @return Page index.
      */
     int pageIdx(int trackingIdx) {
-        assert trackingIdx < trackingSize;
-
-        long res = 0;
-
-        long segIdx = trackingIdx / segmentPageCount;
-        long pageIdx = trackingIdx % segmentPageCount;
-
-        res = (res << segBits) | (segIdx & segMask);
-        res = (res << idxBits) | (pageIdx & idxMask);
-
-        assert (res & (-1L << 32)) == 0 : res;
-
-        return (int)res;
-    }
-
-    /* TODO: IGNITE-4921: Will be removed after segments refactoring >>>> */
-    /**
-     * @param pageIdx Page index.
-     * @return Number of segment.
-     */
-    private int segmentIdx(int pageIdx) {
-        return (pageIdx >> idxBits) & segMask;
-    }
-
-    /**
-     * @param pageIdx Page index.
-     * @return Number of page inside segment.
-     */
-    private int inSegmentPageIdx(int pageIdx) {
-        return pageIdx & idxMask;
+        return pageMem.pageIndex(trackingIdx);
     }
-    /* <<<< */
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/Random2LruPageEvictionTracker.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/Random2LruPageEvictionTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/Random2LruPageEvictionTracker.java
index f0ad813..21ebba1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/Random2LruPageEvictionTracker.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/Random2LruPageEvictionTracker.java
@@ -23,7 +23,7 @@ import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.configuration.MemoryConfiguration;
 import org.apache.ignite.configuration.MemoryPolicyConfiguration;
 import org.apache.ignite.internal.pagemem.PageIdUtils;
-import org.apache.ignite.internal.pagemem.PageMemory;
+import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
 import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.typedef.internal.LT;
@@ -54,7 +54,7 @@ public class Random2LruPageEvictionTracker extends PageAbstractEvictionTracker {
      * @param sharedCtx Shared context.
      */
     public Random2LruPageEvictionTracker(
-        PageMemory pageMem,
+        PageMemoryNoStoreImpl pageMem,
         MemoryPolicyConfiguration plcCfg,
         GridCacheSharedContext<?, ?> sharedCtx
     ) {
@@ -62,7 +62,7 @@ public class Random2LruPageEvictionTracker extends PageAbstractEvictionTracker {
 
         MemoryConfiguration memCfg = sharedCtx.kernalContext().config().getMemoryConfiguration();
 
-        assert plcCfg.getSize() / memCfg.getPageSize() < Integer.MAX_VALUE;
+        assert plcCfg.getMaxSize() / memCfg.getPageSize() < Integer.MAX_VALUE;
 
         log = sharedCtx.logger(getClass());
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/RandomLruPageEvictionTracker.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/RandomLruPageEvictionTracker.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/RandomLruPageEvictionTracker.java
index 8818b1c..d241148 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/RandomLruPageEvictionTracker.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/database/evict/RandomLruPageEvictionTracker.java
@@ -14,6 +14,7 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
+
 package org.apache.ignite.internal.processors.cache.database.evict;
 
 import java.util.concurrent.ThreadLocalRandom;
@@ -24,6 +25,7 @@ import org.apache.ignite.configuration.MemoryConfiguration;
 import org.apache.ignite.configuration.MemoryPolicyConfiguration;
 import org.apache.ignite.internal.pagemem.PageIdUtils;
 import org.apache.ignite.internal.pagemem.PageMemory;
+import org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl;
 import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
 import org.apache.ignite.internal.util.GridUnsafe;
 import org.apache.ignite.internal.util.typedef.internal.LT;
@@ -58,11 +60,11 @@ public class RandomLruPageEvictionTracker extends PageAbstractEvictionTracker {
         MemoryPolicyConfiguration plcCfg,
         GridCacheSharedContext<?, ?> sharedCtx
     ) {
-        super(pageMem, plcCfg, sharedCtx);
+        super((PageMemoryNoStoreImpl)pageMem, plcCfg, sharedCtx);
 
         MemoryConfiguration memCfg = sharedCtx.kernalContext().config().getMemoryConfiguration();
 
-        assert plcCfg.getSize() / memCfg.getPageSize() < Integer.MAX_VALUE;
+        assert plcCfg.getMaxSize() / memCfg.getPageSize() < Integer.MAX_VALUE;
 
         log = sharedCtx.logger(getClass());
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java
index 7fa2355..621b833 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDataManager.java
@@ -245,7 +245,7 @@ public class IgfsDataManager extends IgfsManager {
     public long maxSpaceSize() {
         MemoryPolicy plc = dataCachePrj.context().memoryPolicy();
 
-        long size = plc != null ? plc.config().getSize() : 0;
+        long size = plc != null ? plc.config().getMaxSize() : 0;
 
         return (size <= 0) ? 0 : size ;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
index 9a08b2b..c61b75e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
@@ -1415,7 +1415,6 @@ public class PlatformCache extends PlatformAbstractTarget {
         writer.writeLong(metrics.getOffHeapPrimaryEntriesCount());
         writer.writeLong(metrics.getOffHeapBackupEntriesCount());
         writer.writeLong(metrics.getOffHeapAllocatedSize());
-        writer.writeLong(metrics.getOffHeapMaxSize());
         writer.writeInt(metrics.getSize());
         writer.writeInt(metrics.getKeySize());
         writer.writeBoolean(metrics.isEmpty());

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
index 908b63c..98b438d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
@@ -649,7 +649,8 @@ public class PlatformConfigurationUtils {
                 break;
         }
 
-        cfg.setMemoryConfiguration(readMemoryConfiguration(in));
+        if (in.readBoolean())
+            cfg.setMemoryConfiguration(readMemoryConfiguration(in));
 
         readPluginConfiguration(cfg, in);
     }
@@ -1327,12 +1328,10 @@ public class PlatformConfigurationUtils {
      * @return Config.
      */
     private static MemoryConfiguration readMemoryConfiguration(BinaryRawReader in) {
-        if (!in.readBoolean())
-            return null;
-
         MemoryConfiguration res = new MemoryConfiguration();
 
-        res.setSystemCacheMemorySize(in.readLong())
+        res.setSystemCacheInitialSize(in.readLong())
+                .setSystemCacheMaxSize(in.readLong())
                 .setPageSize(in.readInt())
                 .setConcurrencyLevel(in.readInt())
                 .setDefaultMemoryPolicyName(in.readString());
@@ -1346,7 +1345,8 @@ public class PlatformConfigurationUtils {
                 MemoryPolicyConfiguration cfg = new MemoryPolicyConfiguration();
 
                 cfg.setName(in.readString())
-                        .setSize(in.readLong())
+                        .setInitialSize(in.readLong())
+                        .setMaxSize(in.readLong())
                         .setSwapFilePath(in.readString())
                         .setPageEvictionMode(DataPageEvictionMode.values()[in.readInt()])
                         .setEvictionThreshold(in.readDouble())
@@ -1375,7 +1375,8 @@ public class PlatformConfigurationUtils {
 
         w.writeBoolean(true);
 
-        w.writeLong(cfg.getSystemCacheMemorySize());
+        w.writeLong(cfg.getSystemCacheInitialSize());
+        w.writeLong(cfg.getSystemCacheMaxSize());
         w.writeInt(cfg.getPageSize());
         w.writeInt(cfg.getConcurrencyLevel());
         w.writeString(cfg.getDefaultMemoryPolicyName());
@@ -1387,7 +1388,8 @@ public class PlatformConfigurationUtils {
 
             for (MemoryPolicyConfiguration plc : plcs) {
                 w.writeString(plc.getName());
-                w.writeLong(plc.getSize());
+                w.writeLong(plc.getInitialSize());
+                w.writeLong(plc.getMaxSize());
                 w.writeString(plc.getSwapFilePath());
                 w.writeInt(plc.getPageEvictionMode().ordinal());
                 w.writeDouble(plc.getEvictionThreshold());

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
index afe9fea..0c8f857 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/service/GridServiceProcessor.java
@@ -20,14 +20,11 @@ package org.apache.ignite.internal.processors.service;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ConcurrentMap;
@@ -48,7 +45,6 @@ import org.apache.ignite.compute.ComputeJobContext;
 import org.apache.ignite.configuration.DeploymentMode;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.events.DiscoveryEvent;
-import org.apache.ignite.events.Event;
 import org.apache.ignite.events.EventType;
 import org.apache.ignite.internal.GridClosureCallMode;
 import org.apache.ignite.internal.GridKernalContext;
@@ -73,9 +69,7 @@ import org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposed
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
 import org.apache.ignite.internal.processors.cache.query.CacheQuery;
 import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager;
-import org.apache.ignite.internal.processors.marshaller.MappingAcceptedMessage;
-import org.apache.ignite.internal.processors.marshaller.MappingProposedMessage;
-import org.apache.ignite.internal.processors.continuous.AbstractContinuousMessage;
+import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
 import org.apache.ignite.internal.processors.task.GridInternal;
 import org.apache.ignite.internal.processors.timeout.GridTimeoutObject;
 import org.apache.ignite.internal.util.GridEmptyIterator;
@@ -92,7 +86,6 @@ import org.apache.ignite.internal.util.typedef.internal.CU;
 import org.apache.ignite.internal.util.typedef.internal.LT;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
 import org.apache.ignite.lang.IgniteBiPredicate;
 import org.apache.ignite.lang.IgniteCallable;
 import org.apache.ignite.lang.IgniteFuture;

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index 59d334a..6f8728c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -177,8 +177,6 @@ import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.IgniteNodeAttributes;
-import org.apache.ignite.internal.binary.BinaryObjectEx;
-import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException;
 import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
 import org.apache.ignite.internal.compute.ComputeTaskCancelledCheckedException;
@@ -5629,6 +5627,28 @@ public abstract class IgniteUtils {
     }
 
     /**
+     * Gets amount of RAM memory available on this machine.
+     *
+     * @return Total amount of memory in bytes or -1 if any exception happened.
+     */
+    public static long getTotalMemoryAvailable() {
+        MBeanServer mBeanSrv = ManagementFactory.getPlatformMBeanServer();
+
+        Object attr;
+
+        try {
+            attr = mBeanSrv.getAttribute(
+                    ObjectName.getInstance("java.lang", "type", "OperatingSystem"),
+                    "TotalPhysicalMemorySize");
+        }
+        catch (Exception e) {
+            return -1;
+        }
+
+        return (attr instanceof Long) ? (Long) attr : -1;
+    }
+
+    /**
      * Gets compilation MBean.
      *
      * @return Compilation MBean.
@@ -9554,7 +9574,7 @@ public abstract class IgniteUtils {
     public static <T extends R, R> List<R> arrayList(Collection<T> c, @Nullable IgnitePredicate<? super T>... p) {
         assert c != null;
 
-        return IgniteUtils.arrayList(c, c.size(), p);
+        return arrayList(c, c.size(), p);
     }
 
     /**
@@ -10113,4 +10133,4 @@ public abstract class IgniteUtils {
             }
         };
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryConfiguration.java
index 7a0bc76..b756938 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryConfiguration.java
@@ -66,7 +66,7 @@ public class VisorMemoryConfiguration extends VisorDataTransferObject {
     public VisorMemoryConfiguration(MemoryConfiguration memCfg) {
         assert memCfg != null;
 
-        sysCacheMemSize = memCfg.getSystemCacheMemorySize();
+        sysCacheMemSize = memCfg.getSystemCacheInitialSize();
         pageSize = memCfg.getPageSize();
         concLvl = memCfg.getConcurrencyLevel();
         dfltMemPlcName = memCfg.getDefaultMemoryPolicyName();

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryPolicyConfiguration.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryPolicyConfiguration.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryPolicyConfiguration.java
index d117e5f..dedd71c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryPolicyConfiguration.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/node/VisorMemoryPolicyConfiguration.java
@@ -70,7 +70,7 @@ public class VisorMemoryPolicyConfiguration extends VisorDataTransferObject {
         assert plc != null;
 
         name = plc.getName();
-        size = plc.getSize();
+        size = plc.getMaxSize();
         swapFilePath = plc.getSwapFilePath();
         pageEvictionMode = plc.getPageEvictionMode();
         evictionThreshold = plc.getEvictionThreshold();

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/mxbean/CacheMetricsMXBean.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/mxbean/CacheMetricsMXBean.java b/modules/core/src/main/java/org/apache/ignite/mxbean/CacheMetricsMXBean.java
index 61d2984..3d05763 100644
--- a/modules/core/src/main/java/org/apache/ignite/mxbean/CacheMetricsMXBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/mxbean/CacheMetricsMXBean.java
@@ -144,10 +144,6 @@ public interface CacheMetricsMXBean extends CacheStatisticsMXBean, CacheMXBean,
     public long getOffHeapAllocatedSize();
 
     /** {@inheritDoc} */
-    @MXBeanDescription("Off-heap memory maximum size.")
-    public long getOffHeapMaxSize();
-
-    /** {@inheritDoc} */
     @MXBeanDescription("Number of non-null values in the cache.")
     public int getSize();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java b/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java
index db75f57..6835073 100644
--- a/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/mxbean/MemoryMetricsMXBean.java
@@ -24,24 +24,33 @@ import org.apache.ignite.MemoryMetrics;
 @MXBeanDescription("MBean that provides access to MemoryMetrics of current Ignite node.")
 public interface MemoryMetricsMXBean extends MemoryMetrics {
     /** {@inheritDoc} */
-    @MXBeanDescription("Name of PageMemory metrics are collected for.")
+    @MXBeanDescription("Name of MemoryPolicy metrics are collected for.")
     @Override public String getName();
 
-    /** {@inheritDoc} */
-    @MXBeanDescription("Size of PageMemory in MBytes.")
-    @Override public int getSize();
+    /**
+     * Initial size configured for MemoryPolicy on local node.
+     *
+     * @return Initial size in MB.
+     */
+    @MXBeanDescription("Initial size configured for MemoryPolicy on local node.")
+    public int getInitialSize();
 
-    /** {@inheritDoc} */
-    @MXBeanDescription("File path of memory-mapped swap file.")
-    @Override public String getSwapFilePath();
+    /**
+     * Maximum size configured for MemoryPolicy on local node.
+     *
+     * @return Maximum size in MB.
+     */
+    @MXBeanDescription("Maximum size configured for MemoryPolicy on local node.")
+    public int getMaxSize();
 
-    /** {@inheritDoc} */
-    @MXBeanDescription("Enables metrics gathering.")
-    @Override public void enableMetrics();
-
-    /** {@inheritDoc} */
-    @MXBeanDescription("Disables metrics gathering.")
-    @Override public void disableMetrics();
+    /**
+     * Path from MemoryPolicy configuration to directory where memory-mapped files used for swap are created.
+     * Depending on configuration may be absolute or relative; in the latter case it is relative to IGNITE_HOME.
+     *
+     * @return path to directory with memory-mapped files.
+     */
+    @MXBeanDescription("Path to directory with memory-mapped files.")
+    public String getSwapFilePath();
 
     /** {@inheritDoc} */
     @MXBeanDescription("Total number of allocated pages.")
@@ -63,27 +72,53 @@ public interface MemoryMetricsMXBean extends MemoryMetrics {
     @MXBeanDescription("Pages fill factor: size of all entries in cache over size of all allocated pages.")
     @Override public float getPagesFillFactor();
 
-    /** {@inheritDoc} */
+    /**
+     * Enables collecting memory metrics on local node.
+     */
+    @MXBeanDescription("Enables collecting memory metrics on local node.")
+    public void enableMetrics();
+
+    /**
+     * Disables collecting memory metrics on local node.
+     */
+    @MXBeanDescription("Disables collecting memory metrics on local node.")
+    public void disableMetrics();
+
+    /**
+     * Sets interval of time (in seconds) to monitor allocation rate.
+     *
+     * E.g. after setting rateTimeInterval to 60 seconds subsequent calls to {@link #getAllocationRate()}
+     * will return average allocation rate (pages per second) for the last minute.
+     *
+     * @param rateTimeInterval Time interval used to calculate allocation/eviction rate.
+     */
     @MXBeanDescription(
-            "Sets time interval average allocation rate (pages per second) is calculated over."
+        "Sets time interval average allocation rate (pages per second) is calculated over."
     )
     @MXBeanParametersNames(
-            "rateTimeInterval"
+        "rateTimeInterval"
     )
     @MXBeanParametersDescriptions(
-            "Time interval (in seconds) to set."
+        "Time interval (in seconds) to set."
     )
-    @Override public void rateTimeInterval(int rateTimeInterval);
+    public void rateTimeInterval(int rateTimeInterval);
 
-    /** {@inheritDoc} */
+    /**
+     * Sets number of subintervals the whole rateTimeInterval will be split into to calculate allocation rate,
+     * 5 by default.
+     * Setting it to bigger number allows more precise calculation and smaller drops of allocationRate metric
+     * when next subinterval has to be recycled but introduces bigger calculation overhead.
+     *
+     * @param subInts Number of subintervals.
+     */
     @MXBeanDescription(
-            "Sets number of subintervals to calculate allocationRate metrics."
+        "Sets number of subintervals to calculate allocationRate metrics."
     )
     @MXBeanParametersNames(
-            "subInts"
+        "subInts"
     )
     @MXBeanParametersDescriptions(
-            "Number of subintervals to set."
+        "Number of subintervals to set."
     )
-    @Override public void subIntervals(int subInts);
+    public void subIntervals(int subInts);
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java
index d204a39..26bd941 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/ClusterNodeMetricsSelfTest.java
@@ -24,12 +24,12 @@ import org.apache.ignite.GridTestTask;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.MemoryMetrics;
 import org.apache.ignite.cache.eviction.fifo.FifoEvictionPolicy;
 import org.apache.ignite.cluster.ClusterMetrics;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.events.Event;
+import org.apache.ignite.internal.processors.cache.database.MemoryMetricsImpl;
 import org.apache.ignite.internal.processors.task.GridInternal;
 import org.apache.ignite.internal.util.lang.GridAbsPredicate;
 import org.apache.ignite.lang.IgnitePredicate;
@@ -111,7 +111,7 @@ public class ClusterNodeMetricsSelfTest extends GridCommonAbstractTest {
 
         final IgniteCache cache = ignite.getOrCreateCache(CACHE_NAME);
 
-        MemoryMetrics memMetrics = getDefaultMemoryPolicyMetrics(ignite);
+        MemoryMetricsImpl memMetrics = getDefaultMemoryPolicyMetrics(ignite);
 
         memMetrics.enableMetrics();
 
@@ -128,7 +128,7 @@ public class ClusterNodeMetricsSelfTest extends GridCommonAbstractTest {
     /**
      * @param ignite Ignite instance.
      */
-    private MemoryMetrics getDefaultMemoryPolicyMetrics(IgniteEx ignite) throws IgniteCheckedException {
+    private MemoryMetricsImpl getDefaultMemoryPolicyMetrics(IgniteEx ignite) throws IgniteCheckedException {
         return ignite.context().cache().context().database().memoryPolicy(null).memoryMetrics();
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
index 0fe90cd..84db565 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/pagemem/impl/PageMemoryNoLoadSelfTest.java
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.MemoryPolicyConfiguration;
 import org.apache.ignite.internal.mem.DirectMemoryProvider;
 import org.apache.ignite.internal.mem.file.MappedFileMemoryProvider;
 import org.apache.ignite.internal.pagemem.FullPageId;
@@ -279,15 +280,18 @@ public class PageMemoryNoLoadSelfTest extends GridCommonAbstractTest {
     protected PageMemory memory() throws Exception {
         File memDir = U.resolveWorkDirectory(U.defaultWorkDirectory(), "pagemem", false);
 
-        long[] sizes = new long[10];
+        MemoryPolicyConfiguration plcCfg = new MemoryPolicyConfiguration().setMaxSize(10 * 1024 * 1024);
 
-        for (int i = 0; i < sizes.length; i++)
-            sizes[i] = 1024 * 1024;
+        DirectMemoryProvider provider = new MappedFileMemoryProvider(log(), memDir);
 
-        DirectMemoryProvider provider = new MappedFileMemoryProvider(log(), memDir, true,
-            sizes);
-
-        return new PageMemoryNoStoreImpl(log(), provider, null, PAGE_SIZE, null, new MemoryMetricsImpl(null), true);
+        return new PageMemoryNoStoreImpl(
+            log(),
+            provider,
+            null,
+            PAGE_SIZE,
+            plcCfg,
+            new MemoryMetricsImpl(plcCfg),
+            true);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheConfigurationLeakTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheConfigurationLeakTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheConfigurationLeakTest.java
index b97bb26..bf94d16 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheConfigurationLeakTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheConfigurationLeakTest.java
@@ -48,7 +48,7 @@ public class CacheConfigurationLeakTest extends GridCommonAbstractTest {
         MemoryPolicyConfiguration plc = new MemoryPolicyConfiguration();
 
         plc.setName("dfltPlc");
-        plc.setSize(MemoryConfiguration.DFLT_MEMORY_POLICY_SIZE * 10);
+        plc.setMaxSize(MemoryConfiguration.DFLT_MEMORY_POLICY_MAX_SIZE * 10);
 
         memCfg.setDefaultMemoryPolicyName("dfltPlc");
         memCfg.setMemoryPolicies(plc);

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMemoryPolicyConfigurationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMemoryPolicyConfigurationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMemoryPolicyConfigurationTest.java
index 92e7e84..326a830 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMemoryPolicyConfigurationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheMemoryPolicyConfigurationTest.java
@@ -84,11 +84,12 @@ public class CacheMemoryPolicyConfigurationTest extends GridCommonAbstractTest {
 
         MemoryPolicyConfiguration dfltPlcCfg = new MemoryPolicyConfiguration();
         dfltPlcCfg.setName("dfltPlc");
-        dfltPlcCfg.setSize(1024 * 1024);
+        dfltPlcCfg.setInitialSize(10 * 1024 * 1024);
+        dfltPlcCfg.setMaxSize(10 * 1024 * 1024);
 
         MemoryPolicyConfiguration bigPlcCfg = new MemoryPolicyConfiguration();
         bigPlcCfg.setName("bigPlc");
-        bigPlcCfg.setSize(1024 * 1024 * 1024);
+        bigPlcCfg.setMaxSize(1024 * 1024 * 1024);
 
         memCfg.setMemoryPolicies(dfltPlcCfg, bigPlcCfg);
         memCfg.setDefaultMemoryPolicyName("dfltPlc");
@@ -137,11 +138,12 @@ public class CacheMemoryPolicyConfigurationTest extends GridCommonAbstractTest {
 
         MemoryPolicyConfiguration dfltPlcCfg = new MemoryPolicyConfiguration();
         dfltPlcCfg.setName("dfltPlc");
-        dfltPlcCfg.setSize(1024 * 1024);
+        dfltPlcCfg.setInitialSize(1024 * 1024);
+        dfltPlcCfg.setMaxSize(1024 * 1024);
 
         MemoryPolicyConfiguration bigPlcCfg = new MemoryPolicyConfiguration();
         bigPlcCfg.setName("bigPlc");
-        bigPlcCfg.setSize(1024 * 1024 * 1024);
+        bigPlcCfg.setMaxSize(1024 * 1024 * 1024);
 
         memCfg.setMemoryPolicies(dfltPlcCfg, bigPlcCfg);
         memCfg.setDefaultMemoryPolicyName("dfltPlc");

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/MemoryPolicyConfigValidationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/MemoryPolicyConfigValidationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/MemoryPolicyConfigValidationTest.java
index 154e562..a1a05eb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/MemoryPolicyConfigValidationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/MemoryPolicyConfigValidationTest.java
@@ -26,6 +26,15 @@ import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
  *
  */
 public class MemoryPolicyConfigValidationTest extends GridCommonAbstractTest {
+    /** */
+    private static final String VALID_DEFAULT_MEM_PLC_NAME = "valid_dlft_mem_plc";
+
+    /** */
+    private static final String VALID_USER_MEM_PLC_NAME = "valid_user_mem_plc";
+
+    /** */
+    private static final String MISSING_DEFAULT_MEM_PLC_NAME = "missing_mem_plc";
+
     /** Configuration violation type to check. */
     private ValidationViolationType violationType;
 
@@ -61,9 +70,30 @@ public class MemoryPolicyConfigValidationTest extends GridCommonAbstractTest {
             case MISSING_USER_DEFINED_DEFAULT:
                 plcs = createMissingUserDefinedDefault();
 
-                memCfg.setDefaultMemoryPolicyName("missingMemoryPolicyName");
+                memCfg.setDefaultMemoryPolicyName(MISSING_DEFAULT_MEM_PLC_NAME);
+
+                break;
+
+            case TOO_SMALL_USER_DEFINED_DFLT_MEM_PLC_SIZE:
+                memCfg.setDefaultMemoryPolicySize(1);
+
+                break;
+
+            case DEFAULT_SIZE_IS_DEFINED_TWICE:
+                plcs = createValidUserDefault();
+
+                memCfg.setDefaultMemoryPolicyName(VALID_DEFAULT_MEM_PLC_NAME);
+                memCfg.setDefaultMemoryPolicySize(10 * 1014 * 1024);
+
+                break;
+
+            case MAX_SIZE_IS_SMALLER_THAN_INITIAL_SIZE:
+                plcs = createMaxSizeSmallerThanInitialSize();
 
                 break;
+
+            default:
+                fail("Violation type was not configured: " + violationType);
         }
 
         memCfg.setMemoryPolicies(plcs);
@@ -73,18 +103,35 @@ public class MemoryPolicyConfigValidationTest extends GridCommonAbstractTest {
         return cfg;
     }
 
+    /**
+     *
+     */
+    private MemoryPolicyConfiguration[] createValidUserDefault() {
+        MemoryPolicyConfiguration[] res = new MemoryPolicyConfiguration[1];
+
+        res[0] = createMemoryPolicy(VALID_DEFAULT_MEM_PLC_NAME, 100 * 1024 * 1024, 100 * 1024 * 1024);
+
+        return res;
+    }
+
+    /**
+     *
+     */
     private MemoryPolicyConfiguration[] createMissingUserDefinedDefault() {
         MemoryPolicyConfiguration[] res = new MemoryPolicyConfiguration[1];
 
-        res[0] = createMemoryPolicy("presentedPolicyCfg", 10 * 1024 * 1024);
+        res[0] = createMemoryPolicy(VALID_USER_MEM_PLC_NAME, 10 * 1024 * 1024, 10 * 1024 * 1024);
 
         return res;
     }
 
+    /**
+     *
+     */
     private MemoryPolicyConfiguration[] createPlcWithNullName() {
         MemoryPolicyConfiguration[] res = new MemoryPolicyConfiguration[1];
 
-        res[0] = createMemoryPolicy(null, 10 * 1024 * 1024);
+        res[0] = createMemoryPolicy(null, 10 * 1024 * 1024, 10 * 1024 * 1024);
 
         return res;
     }
@@ -95,7 +142,7 @@ public class MemoryPolicyConfigValidationTest extends GridCommonAbstractTest {
     private MemoryPolicyConfiguration[] createTooSmallMemoryCfg() {
         MemoryPolicyConfiguration[] res = new MemoryPolicyConfiguration[1];
 
-        res[0] = createMemoryPolicy("dflt", 10);
+        res[0] = createMemoryPolicy(VALID_DEFAULT_MEM_PLC_NAME, 10, 10);
 
         return res;
     }
@@ -106,7 +153,7 @@ public class MemoryPolicyConfigValidationTest extends GridCommonAbstractTest {
     private MemoryPolicyConfiguration[] createPlcWithReservedNameMisuseCfg() {
         MemoryPolicyConfiguration[] res = new MemoryPolicyConfiguration[1];
 
-        res[0] = createMemoryPolicy("sysMemPlc", 1024 * 1024);
+        res[0] = createMemoryPolicy("sysMemPlc", 1024 * 1024, 1024 * 1024);
 
         return res;
     }
@@ -117,8 +164,19 @@ public class MemoryPolicyConfigValidationTest extends GridCommonAbstractTest {
     private MemoryPolicyConfiguration[] createPlcsWithNamesConflictCfg() {
         MemoryPolicyConfiguration[] res = new MemoryPolicyConfiguration[2];
 
-        res[0] = createMemoryPolicy("cflt0", 1024 * 1024);
-        res[1] = createMemoryPolicy("cflt0", 1024 * 1024);
+        res[0] = createMemoryPolicy("cflt0", 10 * 1024 * 1024, 10 * 1024 * 1024);
+        res[1] = createMemoryPolicy("cflt0", 10 * 1024 * 1024, 10 * 1024 * 1024);
+
+        return res;
+    }
+
+    /**
+     *
+     */
+    private MemoryPolicyConfiguration[] createMaxSizeSmallerThanInitialSize() {
+        MemoryPolicyConfiguration[] res = new MemoryPolicyConfiguration[1];
+
+        res[0] = createMemoryPolicy("invalidSize", 100 * 1024 * 1024, 10 * 1024 * 1024);
 
         return res;
     }
@@ -132,13 +190,15 @@ public class MemoryPolicyConfigValidationTest extends GridCommonAbstractTest {
 
     /**
      * @param name Name of MemoryPolicyConfiguration.
-     * @param size Size of MemoryPolicyConfiguration in bytes.
+     * @param initialSize Initial size of MemoryPolicyConfiguration in bytes.
+     * @param maxSize Max size of MemoryPolicyConfiguration in bytes.
      */
-    private MemoryPolicyConfiguration createMemoryPolicy(String name, long size) {
+    private MemoryPolicyConfiguration createMemoryPolicy(String name, long initialSize, long maxSize) {
         MemoryPolicyConfiguration plc = new MemoryPolicyConfiguration();
 
         plc.setName(name);
-        plc.setSize(size);
+        plc.setInitialSize(initialSize);
+        plc.setMaxSize(maxSize);
 
         return plc;
     }
@@ -189,6 +249,34 @@ public class MemoryPolicyConfigValidationTest extends GridCommonAbstractTest {
     }
 
     /**
+     * MemoryPolicy must be configured with size of at least 1MB.
+     */
+    public void testMaxSizeSmallerThanInitialSize() throws Exception {
+        violationType = ValidationViolationType.MAX_SIZE_IS_SMALLER_THAN_INITIAL_SIZE;
+
+        doTest(violationType);
+    }
+
+    /**
+     * User-defined size of default MemoryPolicy must be at least 1MB.
+     */
+    public void testUserDefinedDefaultMemoryTooSmall() throws Exception {
+        violationType = ValidationViolationType.TOO_SMALL_USER_DEFINED_DFLT_MEM_PLC_SIZE;
+
+        doTest(violationType);
+    }
+
+    /**
+     * Defining size of default MemoryPolicy twice with and through <b>defaultMemoryPolicySize</b> property
+     * and using <b>MemoryPolicyConfiguration</b> description is prohibited.
+     */
+    public void testDefaultMemoryPolicySizeDefinedTwice() throws Exception {
+        violationType = ValidationViolationType.DEFAULT_SIZE_IS_DEFINED_TWICE;
+
+        doTest(violationType);
+    }
+
+    /**
      * Tries to start ignite node with invalid configuration and checks that corresponding exception is thrown.
      *
      * @param violationType Configuration violation type.
@@ -220,13 +308,22 @@ public class MemoryPolicyConfigValidationTest extends GridCommonAbstractTest {
         SYSTEM_MEMORY_POLICY_NAME_MISUSE("'sysMemPlc' policy name is reserved for internal use."),
 
         /** */
-        TOO_SMALL_MEMORY_SIZE("MemoryPolicy must have size more than 1MB: "),
+        TOO_SMALL_MEMORY_SIZE("MemoryPolicy must have size more than 10MB "),
 
         /** */
         NULL_NAME_ON_USER_DEFINED_POLICY("User-defined MemoryPolicyConfiguration must have non-null and non-empty name."),
 
         /** */
-        MISSING_USER_DEFINED_DEFAULT("User-defined default MemoryPolicy name must be presented among configured MemoryPolices: ");
+        MISSING_USER_DEFINED_DEFAULT("User-defined default MemoryPolicy name must be presented among configured MemoryPolices: "),
+
+        /** */
+        DEFAULT_SIZE_IS_DEFINED_TWICE("User-defined MemoryPolicy configuration and defaultMemoryPolicySize properties are set at the same time."),
+
+        /** */
+        TOO_SMALL_USER_DEFINED_DFLT_MEM_PLC_SIZE("User-defined default MemoryPolicy size is less than 1MB."),
+
+        /** */
+        MAX_SIZE_IS_SMALLER_THAN_INITIAL_SIZE("MemoryPolicy maxSize must not be smaller than initialSize");
 
         /**
          * @param violationMsg Violation message.

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicyInitializationTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicyInitializationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicyInitializationTest.java
index 1e3f328..a1c9728 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicyInitializationTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/database/MemoryPolicyInitializationTest.java
@@ -117,7 +117,7 @@ public class MemoryPolicyInitializationTest extends GridCommonAbstractTest {
 
         MemoryPolicy dfltMemPlc = U.field(dbMgr, "dfltMemPlc");
 
-        assertTrue(dfltMemPlc.config().getSize() == USER_DEFAULT_MEM_PLC_SIZE);
+        assertTrue(dfltMemPlc.config().getMaxSize() == USER_DEFAULT_MEM_PLC_SIZE);
     }
 
     /**
@@ -141,7 +141,7 @@ public class MemoryPolicyInitializationTest extends GridCommonAbstractTest {
 
         MemoryPolicy dfltMemPlc = U.field(dbMgr, "dfltMemPlc");
 
-        assertTrue(dfltMemPlc.config().getSize() == USER_CUSTOM_MEM_PLC_SIZE);
+        assertTrue(dfltMemPlc.config().getMaxSize() == USER_CUSTOM_MEM_PLC_SIZE);
     }
 
     /**
@@ -232,11 +232,11 @@ public class MemoryPolicyInitializationTest extends GridCommonAbstractTest {
 
         memCfg.setMemoryPolicies(new MemoryPolicyConfiguration()
                 .setName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME)
-                .setSize(USER_CUSTOM_MEM_PLC_SIZE),
+                .setMaxSize(USER_CUSTOM_MEM_PLC_SIZE),
 
                 new MemoryPolicyConfiguration()
                 .setName(DFLT_MEM_PLC_DEFAULT_NAME)
-                .setSize(USER_DEFAULT_MEM_PLC_SIZE)
+                .setMaxSize(USER_DEFAULT_MEM_PLC_SIZE)
         );
     }
 
@@ -249,7 +249,7 @@ public class MemoryPolicyInitializationTest extends GridCommonAbstractTest {
 
         memCfg.setMemoryPolicies(new MemoryPolicyConfiguration()
                 .setName(DFLT_MEM_PLC_DEFAULT_NAME)
-                .setSize(USER_DEFAULT_MEM_PLC_SIZE)
+                .setMaxSize(USER_DEFAULT_MEM_PLC_SIZE)
         );
     }
 
@@ -261,11 +261,11 @@ public class MemoryPolicyInitializationTest extends GridCommonAbstractTest {
 
         memCfg.setMemoryPolicies(new MemoryPolicyConfiguration()
                 .setName(DFLT_MEM_PLC_DEFAULT_NAME)
-                .setSize(USER_DEFAULT_MEM_PLC_SIZE),
+                .setMaxSize(USER_DEFAULT_MEM_PLC_SIZE),
 
                 new MemoryPolicyConfiguration()
                 .setName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME)
-                .setSize(USER_CUSTOM_MEM_PLC_SIZE)
+                .setMaxSize(USER_CUSTOM_MEM_PLC_SIZE)
         );
     }
 
@@ -288,7 +288,7 @@ public class MemoryPolicyInitializationTest extends GridCommonAbstractTest {
 
         memCfg.setMemoryPolicies(new MemoryPolicyConfiguration()
                 .setName(CUSTOM_NON_DEFAULT_MEM_PLC_NAME)
-                .setSize(USER_CUSTOM_MEM_PLC_SIZE)
+                .setMaxSize(USER_CUSTOM_MEM_PLC_SIZE)
         );
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionAbstractTest.java
index 39927be..bda7940 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/eviction/paged/PageEvictionAbstractTest.java
@@ -88,7 +88,9 @@ public class PageEvictionAbstractTest extends GridCommonAbstractTest {
 
         MemoryPolicyConfiguration plc = new MemoryPolicyConfiguration();
 
-        plc.setSize(SIZE);
+        // This will test additional segment allocation.
+        plc.setInitialSize(SIZE / 2);
+        plc.setMaxSize(SIZE);
         plc.setEmptyPagesPoolSize(EMPTY_PAGES_POOL_SIZE);
         plc.setEvictionThreshold(EVICTION_THRESHOLD);
         plc.setName(DEFAULT_POLICY_NAME);

http://git-wip-us.apache.org/repos/asf/ignite/blob/11c23b62/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java
index 4660972..bc297a2 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/transactions/TxPessimisticDeadlockDetectionTest.java
@@ -103,7 +103,7 @@ public class TxPessimisticDeadlockDetectionTest extends GridCommonAbstractTest {
         MemoryPolicyConfiguration plc = new MemoryPolicyConfiguration();
 
         plc.setName("dfltPlc");
-        plc.setSize(MemoryConfiguration.DFLT_MEMORY_POLICY_SIZE * 10);
+        plc.setMaxSize(MemoryConfiguration.DFLT_MEMORY_POLICY_MAX_SIZE * 10);
 
         memCfg.setDefaultMemoryPolicyName("dfltPlc");
         memCfg.setMemoryPolicies(plc);


Mime
View raw message