ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agoncha...@apache.org
Subject [ignite] 02/02: IGNITE-12412 Fixed ABA issue in PagePool#releaseFreePage
Date Mon, 16 Dec 2019 16:34:19 GMT
This is an automated email from the ASF dual-hosted git repository.

agoncharuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git

commit 20571410eaf1776b532ea686be464f0b2a831813
Author: Alexey Goncharuk <alexey.goncharuk@gmail.com>
AuthorDate: Tue Dec 10 12:22:22 2019 +0300

    IGNITE-12412 Fixed ABA issue in PagePool#releaseFreePage
---
 .../processors/cache/persistence/pagemem/PagePool.java   | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PagePool.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PagePool.java
index d267b36..d87044d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PagePool.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/pagemem/PagePool.java
@@ -120,14 +120,14 @@ public class PagePool {
      */
     private long borrowFreePage() {
         while (true) {
-            long freePageRelPtrMasked = GridUnsafe.getLong(null, freePageListPtr);
+            long freePageRelPtrMasked = GridUnsafe.getLongVolatile(null, freePageListPtr);
 
             long freePageRelPtr = freePageRelPtrMasked & ADDRESS_MASK;
 
             if (freePageRelPtr != PageMemoryImpl.INVALID_REL_PTR) {
                 long freePageAbsPtr = absolute(freePageRelPtr);
 
-                long nextFreePageRelPtr = GridUnsafe.getLong(null, freePageAbsPtr) &
ADDRESS_MASK;
+                long nextFreePageRelPtr = GridUnsafe.getLongVolatile(null, freePageAbsPtr)
& ADDRESS_MASK;
 
                 // nextFreePageRelPtr may be invalid because a concurrent thread may have
already polled this value
                 // and used it.
@@ -153,7 +153,7 @@ public class PagePool {
         long limit = region.address() + region.size();
 
         while (true) {
-            long lastIdx = GridUnsafe.getLong(null, lastAllocatedIdxPtr);
+            long lastIdx = GridUnsafe.getLongVolatile(null, lastAllocatedIdxPtr);
 
             // Check if we have enough space to allocate a page.
             if (pagesBase + (lastIdx + 1) * sysPageSize > limit)
@@ -192,13 +192,17 @@ public class PagePool {
             resCntr = pagesCntr.decrementAndGet();
 
         while (true) {
-            long freePageRelPtrMasked = GridUnsafe.getLong(null, freePageListPtr);
+            long freePageRelPtrMasked = GridUnsafe.getLongVolatile(null, freePageListPtr);
 
             long freePageRelPtr = freePageRelPtrMasked & PageMemoryImpl.RELATIVE_PTR_MASK;
 
-            GridUnsafe.putLong(null, absPtr, freePageRelPtr);
+            GridUnsafe.putLongVolatile(null, absPtr, freePageRelPtr);
 
-            if (GridUnsafe.compareAndSwapLong(null, freePageListPtr, freePageRelPtrMasked,
relPtr))
+            long cnt = freePageRelPtrMasked & COUNTER_MASK;
+
+            long relPtrWithCnt = (relPtr & ADDRESS_MASK) | cnt;
+
+            if (GridUnsafe.compareAndSwapLong(null, freePageListPtr, freePageRelPtrMasked,
relPtrWithCnt))
                 return resCntr;
         }
     }


Mime
View raw message