You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ds...@apache.org on 2016/05/16 23:28:31 UTC
incubator-geode git commit: change defragment to not create fragments
> 2G
Repository: incubator-geode
Updated Branches:
refs/heads/feature/GEODE-1292 [created] 3e62e809a
change defragment to not create fragments > 2G
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/3e62e809
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/3e62e809
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/3e62e809
Branch: refs/heads/feature/GEODE-1292
Commit: 3e62e809a5ab175d3e48716a2c75fbf8e3bf2c23
Parents: 34d3791
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Mon May 16 16:12:46 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Mon May 16 16:12:46 2016 -0700
----------------------------------------------------------------------
.../internal/offheap/FreeListManager.java | 57 ++++++++------------
1 file changed, 23 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3e62e809/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
index c5e17e8..2e086ee 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/offheap/FreeListManager.java
@@ -301,6 +301,25 @@ public class FreeListManager {
verifyHugeMultiple(HUGE_MULTIPLE);
}
public final static int MAX_TINY = TINY_MULTIPLE*TINY_FREE_LIST_COUNT;
+
+ /**
+ * Return true if the two chunks have been combined into one.
+ * If low and high are adjacent to each other then low's size
+ * will be increased by the size of high and true will be returned.
+ */
+ private boolean combineIfAdjacent(long lowAddr, long highAddr) {
+ int lowSize = OffHeapStoredObject.getSize(lowAddr);
+ if (lowAddr + lowSize == highAddr) {
+ long newSize = lowSize + OffHeapStoredObject.getSize(highAddr);
+ if (newSize <= Integer.MAX_VALUE) {
+ // append the highAddr chunk to lowAddr
+ OffHeapStoredObject.setSize(lowAddr, (int)newSize);
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Defragments memory and returns true if enough memory to allocate chunkSize
* is freed. Otherwise returns false;
@@ -336,13 +355,7 @@ public class FreeListManager {
sorted[0] = addr;
sortedSize++;
} else {
- // see if we can conflate into sorted[idx]
- long lowAddr = sorted[idx-1];
- int lowSize = OffHeapStoredObject.getSize(lowAddr);
- if (lowAddr + lowSize == addr) {
- // append the addr chunk to lowAddr
- OffHeapStoredObject.setSize(lowAddr, lowSize + OffHeapStoredObject.getSize(addr));
- } else {
+ if (!combineIfAdjacent(sorted[idx-1], addr)) {
if (sortedSize >= sorted.length) {
long[] newSorted = new long[sorted.length+SORT_ARRAY_BLOCK_SIZE];
System.arraycopy(sorted, 0, newSorted, 0, sorted.length);
@@ -353,29 +366,10 @@ public class FreeListManager {
}
}
} else {
- int addrSize = OffHeapStoredObject.getSize(addr);
- long highAddr = sorted[idx];
- if (addr + addrSize == highAddr) {
- // append highAddr chunk to addr
- OffHeapStoredObject.setSize(addr, addrSize + OffHeapStoredObject.getSize(highAddr));
+ if (combineIfAdjacent(addr, sorted[idx])) {
sorted[idx] = addr;
} else {
- boolean insert = idx==0;
- if (!insert) {
- long lowAddr = sorted[idx-1];
- // if (lowAddr == 0L) {
- // long[] tmp = Arrays.copyOf(sorted, sortedSize);
- // throw new IllegalStateException("addr was zero at idx=" + (idx-1) + " sorted="+ Arrays.toString(tmp));
- // }
- int lowSize = OffHeapStoredObject.getSize(lowAddr);
- if (lowAddr + lowSize == addr) {
- // append the addr chunk to lowAddr
- OffHeapStoredObject.setSize(lowAddr, lowSize + addrSize);
- } else {
- insert = true;
- }
- }
- if (insert) {
+ if (idx == 0 || !combineIfAdjacent(sorted[idx-1], addr)) {
if (sortedSize >= sorted.length) {
long[] newSorted = new long[sorted.length+SORT_ARRAY_BLOCK_SIZE];
System.arraycopy(sorted, 0, newSorted, 0, idx);
@@ -394,12 +388,7 @@ public class FreeListManager {
}
}
for (int i=sortedSize-1; i > 0; i--) {
- long addr = sorted[i];
- long lowAddr = sorted[i-1];
- int lowSize = OffHeapStoredObject.getSize(lowAddr);
- if (lowAddr + lowSize == addr) {
- // append addr chunk to lowAddr
- OffHeapStoredObject.setSize(lowAddr, lowSize + OffHeapStoredObject.getSize(addr));
+ if (combineIfAdjacent(sorted[i-1], sorted[i])) {
sorted[i] = 0L;
}
}