public class BufferPool
extends java.lang.Object
BufferPool
instance has one GlobalPool
which allocates two kinds of chunks:
BufferPool.LocalPool
to serve buffer allocationGlobalPool
maintains two kinds of freed chunks, fully freed chunks where all buffers are released, and
partially freed chunks where some buffers are not released, eg. held by ChunkCache
.
Partially freed chunks are used to improve cache utilization and have lower priority compared to fully freed chunks.
BufferPool.LocalPool
is a thread local pool to serve buffer allocation requests. There are two kinds of local pool:
Modifier and Type | Class and Description |
---|---|
class |
BufferPool.LocalPool
A thread local class that grabs chunks from the global pool for this thread allocations.
|
Modifier and Type | Field and Description |
---|---|
protected BufferPoolMetrics |
metrics |
protected java.lang.String |
name |
static int |
NORMAL_ALLOCATION_UNIT |
static int |
NORMAL_CHUNK_SIZE
The size of a page aligned buffer, 128KiB
|
static int |
TINY_ALLOCATION_LIMIT |
static int |
TINY_ALLOCATION_UNIT |
static int |
TINY_CHUNK_SIZE |
Constructor and Description |
---|
BufferPool(java.lang.String name,
long memoryUsageThreshold,
boolean recyclePartially) |
Modifier and Type | Method and Description |
---|---|
BufferPool.LocalPool |
create() |
void |
debug(org.apache.cassandra.utils.memory.BufferPool.Debug setDebug) |
java.nio.ByteBuffer |
get(int size,
BufferType bufferType) |
java.nio.ByteBuffer |
getAtLeast(int size,
BufferType bufferType) |
org.apache.cassandra.utils.memory.BufferPool.GlobalPool |
globalPool() |
long |
memoryUsageThreshold() |
BufferPoolMetrics |
metrics() |
long |
overflowMemoryInBytes() |
void |
put(java.nio.ByteBuffer buffer) |
void |
putUnusedPortion(java.nio.ByteBuffer buffer) |
static int |
roundUp(int size) |
static int |
roundUp(int size,
int unit) |
void |
setRecycleWhenFreeForCurrentThread(boolean recycleWhenFree) |
void |
shutdownLocalCleaner(long timeout,
java.util.concurrent.TimeUnit unit) |
long |
sizeInBytes() |
java.nio.ByteBuffer |
tryGet(int size)
Unlike the get methods, this will return null if the pool is exhausted
|
java.nio.ByteBuffer |
tryGetAtLeast(int size) |
void |
unsafeReset()
This is not thread safe and should only be used for unit testing.
|
long |
usedSizeInBytes() |
public static final int NORMAL_CHUNK_SIZE
public static final int NORMAL_ALLOCATION_UNIT
public static final int TINY_CHUNK_SIZE
public static final int TINY_ALLOCATION_UNIT
public static final int TINY_ALLOCATION_LIMIT
protected final java.lang.String name
protected final BufferPoolMetrics metrics
public BufferPool(java.lang.String name, long memoryUsageThreshold, boolean recyclePartially)
public BufferPool.LocalPool create()
public java.nio.ByteBuffer get(int size, BufferType bufferType)
public java.nio.ByteBuffer getAtLeast(int size, BufferType bufferType)
public java.nio.ByteBuffer tryGet(int size)
public java.nio.ByteBuffer tryGetAtLeast(int size)
public void put(java.nio.ByteBuffer buffer)
public void putUnusedPortion(java.nio.ByteBuffer buffer)
public void setRecycleWhenFreeForCurrentThread(boolean recycleWhenFree)
public long sizeInBytes()
public long usedSizeInBytes()
public long overflowMemoryInBytes()
public long memoryUsageThreshold()
public org.apache.cassandra.utils.memory.BufferPool.GlobalPool globalPool()
public void debug(org.apache.cassandra.utils.memory.BufferPool.Debug setDebug)
public static int roundUp(int size)
public static int roundUp(int size, int unit)
public void shutdownLocalCleaner(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.util.concurrent.TimeoutException
java.lang.InterruptedException
java.util.concurrent.TimeoutException
public BufferPoolMetrics metrics()
public void unsafeReset()
Copyright © 2009-2021 The Apache Software Foundation