zstan commented on a change in pull request #8513:
URL: https://github.com/apache/ignite/pull/8513#discussion_r555541716



##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/SegmentedLruPageList.java
##########
@@ -0,0 +1,364 @@
+/*
+ * 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.persistence.pagemem;
+
+import org.apache.ignite.configuration.PageReplacementMode;
+import org.apache.ignite.internal.util.GridUnsafe;
+
+/**
+ * Pages Segmented-LRU (SLRU) list implementation.
+ *
+ * @see PageReplacementMode#SEGMENTED_LRU
+ */
+public class SegmentedLruPageList {
+    /** Ratio to limit count of protected pages. */
+    private static final double PROTECTED_TO_TOTAL_PAGES_RATIO = 0.5;
+
+    /** Null page index. */
+    static final int NULL_IDX = -1;
+
+    /** Index of the head page of LRU list. */
+    private int headIdx = NULL_IDX;
+
+    /** Index of the tail page of LRU list. */
+    private int tailIdx = NULL_IDX;
+
+    /** Index of the tail page of probationary segment. */
+    private int probTailIdx = NULL_IDX;
+
+    /** Count of protected pages in the list. */
+    private int protectedPagesCnt;
+
+    /** Protected pages segment limit. */
+    private final int protectedPagesLimit;
+
+    /** Pointer to memory region to store links. */
+    private final long linksPtr;
+
+    /** Pointer to memory region to store protected flags. */
+    private final long flagsPtr;
+
+    /**
+     * @param totalPagesCnt Total pages count.
+     * @param memPtr Pointer to memory region.
+     */
+    public SegmentedLruPageList(int totalPagesCnt, long memPtr) {
+        linksPtr = memPtr;
+        flagsPtr = memPtr + (((long)totalPagesCnt) << 3);
+
+        GridUnsafe.setMemory(linksPtr, ((long)totalPagesCnt) << 3, (byte)0xFF);
+        GridUnsafe.setMemory(flagsPtr, (totalPagesCnt + 7) >> 3, (byte)0);
+
+        protectedPagesLimit = (int)(totalPagesCnt * 
PROTECTED_TO_TOTAL_PAGES_RATIO);
+    }
+
+    /**
+     * Remove page from the head of LRU list.
+     *
+     * @return Page index or {@code -1} if list is empty.
+     */
+    public synchronized int poll() {
+        int idx = headIdx;
+
+        if (idx != NULL_IDX)
+            remove(idx);
+
+        return idx;
+    }
+
+    /**
+     * Remove page from LRU list by page index.
+     *
+     * @param pageIdx Page index.
+     */
+    public synchronized void remove(int pageIdx) {

Review comment:
       this methoad are always calling under wlock as i see, thus no need in 
sync here, only wlock hold check or simple comment, i hope.

##########
File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/SegmentedLruPageList.java
##########
@@ -0,0 +1,364 @@
+/*
+ * 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.persistence.pagemem;
+
+import org.apache.ignite.configuration.PageReplacementMode;
+import org.apache.ignite.internal.util.GridUnsafe;
+
+/**
+ * Pages Segmented-LRU (SLRU) list implementation.
+ *
+ * @see PageReplacementMode#SEGMENTED_LRU
+ */
+public class SegmentedLruPageList {
+    /** Ratio to limit count of protected pages. */
+    private static final double PROTECTED_TO_TOTAL_PAGES_RATIO = 0.5;
+
+    /** Null page index. */
+    static final int NULL_IDX = -1;
+
+    /** Index of the head page of LRU list. */
+    private int headIdx = NULL_IDX;
+
+    /** Index of the tail page of LRU list. */
+    private int tailIdx = NULL_IDX;
+
+    /** Index of the tail page of probationary segment. */
+    private int probTailIdx = NULL_IDX;
+
+    /** Count of protected pages in the list. */
+    private int protectedPagesCnt;
+
+    /** Protected pages segment limit. */
+    private final int protectedPagesLimit;
+
+    /** Pointer to memory region to store links. */
+    private final long linksPtr;
+
+    /** Pointer to memory region to store protected flags. */
+    private final long flagsPtr;
+
+    /**
+     * @param totalPagesCnt Total pages count.
+     * @param memPtr Pointer to memory region.
+     */
+    public SegmentedLruPageList(int totalPagesCnt, long memPtr) {
+        linksPtr = memPtr;
+        flagsPtr = memPtr + (((long)totalPagesCnt) << 3);
+
+        GridUnsafe.setMemory(linksPtr, ((long)totalPagesCnt) << 3, (byte)0xFF);
+        GridUnsafe.setMemory(flagsPtr, (totalPagesCnt + 7) >> 3, (byte)0);
+
+        protectedPagesLimit = (int)(totalPagesCnt * 
PROTECTED_TO_TOTAL_PAGES_RATIO);
+    }
+
+    /**
+     * Remove page from the head of LRU list.
+     *
+     * @return Page index or {@code -1} if list is empty.
+     */
+    public synchronized int poll() {
+        int idx = headIdx;
+
+        if (idx != NULL_IDX)
+            remove(idx);
+
+        return idx;
+    }
+
+    /**
+     * Remove page from LRU list by page index.
+     *
+     * @param pageIdx Page index.
+     */
+    public synchronized void remove(int pageIdx) {

Review comment:
       this method are always calling under wlock as i see, thus no need in 
sync here, only wlock hold check or simple comment, i hope.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to