com.sleepycat.je.dbi
Class MemoryBudget

java.lang.Object
  extended by com.sleepycat.je.dbi.MemoryBudget
All Implemented Interfaces:
EnvConfigObserver

public class MemoryBudget
extends Object
implements EnvConfigObserver

MemoryBudget calculates the available memory for JE and how to apportion it between cache and log buffers. It is meant to centralize all memory calculations. Objects that ask for memory budgets should get settings from this class, rather than using the configuration parameter values directly.


Nested Class Summary
static class MemoryBudget.Totals
          Common base class for shared and private totals.
 
Field Summary
static int ARRAY_OVERHEAD
           
static int ARRAY_SIZE_INCLUDED
           
static int BIN_FIXED_OVERHEAD
           
static int CHECKPOINT_REFERENCE_SIZE
           
static boolean CLEANUP_DONE
           
static int DBFILESUMMARY_OVERHEAD
           
static int DBIN_FIXED_OVERHEAD
           
static boolean DEBUG_ADMIN
           
static boolean DEBUG_LOCK
           
static boolean DEBUG_TREE
           
static boolean DEBUG_TREEADMIN
           
static boolean DEBUG_TXN
           
static int DEFAULT_KEYVALS_OVERHEAD
           
static int DEFAULT_TARGET_ENTRY_OVERHEAD
           
static int DIN_FIXED_OVERHEAD
           
static int DUPCOUNTLN_OVERHEAD
           
static int FILESUMMARYLN_OVERHEAD
           
static int HASHMAP_ENTRY_OVERHEAD
           
static int HASHMAP_OVERHEAD
           
static int HASHSET_ENTRY_OVERHEAD
           
static int HASHSET_OVERHEAD
           
static int IN_FIXED_OVERHEAD
           
static int KEY_OVERHEAD
           
static int LN_INFO_OVERHEAD
           
static int LN_OVERHEAD
           
static int LOCKIMPL_OVERHEAD
           
static int LOCKINFO_OVERHEAD
           
static int LONG_LIST_PER_ITEM_OVERHEAD
           
static int LONG_OVERHEAD
           
static int MAPLN_OVERHEAD
           
static int MAX_KEY_SIZE_KEYVALS_OVERHEAD
           
static long MIN_MAX_MEMORY_SIZE
           
static String MIN_MAX_MEMORY_SIZE_STRING
           
static int NULL_TARGET_ENTRY_OVERHEAD
           
static int OBJECT_ARRAY_ITEM_OVERHEAD
           
static int OBJECT_OVERHEAD
           
static int PRIMITIVE_LONG_ARRAY_ITEM_OVERHEAD
           
static int SPARSE_TARGET_ENTRY_OVERHEAD
           
static int TFS_LIST_INITIAL_OVERHEAD
           
static int TFS_LIST_SEGMENT_OVERHEAD
           
static int THINLOCKIMPL_OVERHEAD
           
static int TREEMAP_ENTRY_OVERHEAD
           
static int TREEMAP_OVERHEAD
           
static int TUPLE_OUTPUT_OVERHEAD
           
static int TWOHASHMAPS_OVERHEAD
           
static int TXN_OVERHEAD
           
static int UTILIZATION_PROFILE_ENTRY
           
static int WRITE_LOCKINFO_OVERHEAD
           
 
Constructor Summary
MemoryBudget(EnvironmentImpl envImpl, EnvironmentImpl sharedCacheEnv, DbConfigManager configManager)
           
 
Method Summary
static int byteArraySize(int arrayLen)
          Returns the memory size occupied by a byte array of a given length.
 void envConfigUpdate(DbConfigManager configManager, EnvironmentMutableConfig ignore)
          Respond to config updates.
 long getAdminMemoryUsage()
          Used for unit testing.
 long getBINOverhead()
           
 long getCacheMemoryUsage()
           
 long getDBINOverhead()
           
 long getDINOverhead()
           
 long getINOverhead()
           
 long getLockMemoryUsage()
          Public for unit testing.
 long getLogBufferBudget()
           
 long getMaxMemory()
           
 long getMinTreeMemoryUsage()
          For unit tests.
static long getRuntimeMaxMemory()
          Returns Runtime.maxMemory(), accounting for a MacOS bug.
 MemoryBudget.Totals getTotals()
           
 long getTrackerBudget()
           
 long getTreeAdminMemoryUsage()
           
 long getTreeMemoryUsage()
          Used for unit testing.
(package private)  long getVariableCacheUsage()
           
(package private)  void initCacheMemoryUsage(long dbTreeAdminMemory)
          Initialize the starting environment memory state.
static int intArraySize(int arrayLen)
           
 boolean isTreeUsageAboveMinimum()
          Returns whether eviction of INList information is allowed.
(package private)  StatGroup loadStats()
           
static int objectArraySize(int arrayLen)
           
(package private)  void refreshTreeAdminMemoryUsage(long newSize)
          Called by INList when clearing tree memory usage.
(package private)  void refreshTreeMemoryUsage(long newSize)
          Called by INList when recalculating tree memory usage.
(package private)  void reset(long newMaxMemory, boolean newEnv, DbConfigManager configManager)
          Initialize at construction time and when the cache is resized.
static int shortArraySize(int arrayLen)
           
(package private)  void subtractCacheUsage()
           
 String toString()
           
static int tupleOutputSize(TupleOutput o)
           
 void updateAdminMemoryUsage(long increment)
          Update the environment wide admin memory count, wake up the evictor if necessary.
 void updateLockMemoryUsage(long increment, int lockTableIndex)
           
 void updateTreeAdminMemoryUsage(long increment)
          Update the treeAdmin memory count, wake up the evictor if necessary.
 void updateTreeMemoryUsage(long increment)
          Update the environment wide tree memory count, wake up the evictor if necessary.
 void updateTxnMemoryUsage(long increment)
          Update the environment wide txn memory count, wake up the evictor if necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLEANUP_DONE

public static boolean CLEANUP_DONE

DEBUG_ADMIN

public static boolean DEBUG_ADMIN

DEBUG_LOCK

public static boolean DEBUG_LOCK

DEBUG_TXN

public static boolean DEBUG_TXN

DEBUG_TREEADMIN

public static boolean DEBUG_TREEADMIN

DEBUG_TREE

public static boolean DEBUG_TREE

LONG_OVERHEAD

public static final int LONG_OVERHEAD

ARRAY_OVERHEAD

public static final int ARRAY_OVERHEAD

ARRAY_SIZE_INCLUDED

public static final int ARRAY_SIZE_INCLUDED

OBJECT_OVERHEAD

public static final int OBJECT_OVERHEAD

OBJECT_ARRAY_ITEM_OVERHEAD

public static final int OBJECT_ARRAY_ITEM_OVERHEAD

HASHMAP_OVERHEAD

public static final int HASHMAP_OVERHEAD

HASHMAP_ENTRY_OVERHEAD

public static final int HASHMAP_ENTRY_OVERHEAD

HASHSET_OVERHEAD

public static final int HASHSET_OVERHEAD

HASHSET_ENTRY_OVERHEAD

public static final int HASHSET_ENTRY_OVERHEAD

TWOHASHMAPS_OVERHEAD

public static final int TWOHASHMAPS_OVERHEAD

TREEMAP_OVERHEAD

public static final int TREEMAP_OVERHEAD

TREEMAP_ENTRY_OVERHEAD

public static final int TREEMAP_ENTRY_OVERHEAD

MAPLN_OVERHEAD

public static final int MAPLN_OVERHEAD

LN_OVERHEAD

public static final int LN_OVERHEAD

DUPCOUNTLN_OVERHEAD

public static final int DUPCOUNTLN_OVERHEAD

BIN_FIXED_OVERHEAD

public static final int BIN_FIXED_OVERHEAD

NULL_TARGET_ENTRY_OVERHEAD

public static final int NULL_TARGET_ENTRY_OVERHEAD

SPARSE_TARGET_ENTRY_OVERHEAD

public static final int SPARSE_TARGET_ENTRY_OVERHEAD

DEFAULT_TARGET_ENTRY_OVERHEAD

public static final int DEFAULT_TARGET_ENTRY_OVERHEAD

DEFAULT_KEYVALS_OVERHEAD

public static final int DEFAULT_KEYVALS_OVERHEAD

MAX_KEY_SIZE_KEYVALS_OVERHEAD

public static final int MAX_KEY_SIZE_KEYVALS_OVERHEAD

DIN_FIXED_OVERHEAD

public static final int DIN_FIXED_OVERHEAD

DBIN_FIXED_OVERHEAD

public static final int DBIN_FIXED_OVERHEAD

IN_FIXED_OVERHEAD

public static final int IN_FIXED_OVERHEAD

KEY_OVERHEAD

public static final int KEY_OVERHEAD

LOCKIMPL_OVERHEAD

public static final int LOCKIMPL_OVERHEAD

THINLOCKIMPL_OVERHEAD

public static final int THINLOCKIMPL_OVERHEAD

LOCKINFO_OVERHEAD

public static final int LOCKINFO_OVERHEAD

WRITE_LOCKINFO_OVERHEAD

public static final int WRITE_LOCKINFO_OVERHEAD

TXN_OVERHEAD

public static final int TXN_OVERHEAD

CHECKPOINT_REFERENCE_SIZE

public static final int CHECKPOINT_REFERENCE_SIZE

UTILIZATION_PROFILE_ENTRY

public static final int UTILIZATION_PROFILE_ENTRY

DBFILESUMMARY_OVERHEAD

public static final int DBFILESUMMARY_OVERHEAD

TFS_LIST_INITIAL_OVERHEAD

public static final int TFS_LIST_INITIAL_OVERHEAD

TFS_LIST_SEGMENT_OVERHEAD

public static final int TFS_LIST_SEGMENT_OVERHEAD

LN_INFO_OVERHEAD

public static final int LN_INFO_OVERHEAD

FILESUMMARYLN_OVERHEAD

public static final int FILESUMMARYLN_OVERHEAD

LONG_LIST_PER_ITEM_OVERHEAD

public static final int LONG_LIST_PER_ITEM_OVERHEAD

TUPLE_OUTPUT_OVERHEAD

public static final int TUPLE_OUTPUT_OVERHEAD

PRIMITIVE_LONG_ARRAY_ITEM_OVERHEAD

public static final int PRIMITIVE_LONG_ARRAY_ITEM_OVERHEAD
See Also:
Constant Field Values

MIN_MAX_MEMORY_SIZE

public static final long MIN_MAX_MEMORY_SIZE
See Also:
Constant Field Values

MIN_MAX_MEMORY_SIZE_STRING

public static final String MIN_MAX_MEMORY_SIZE_STRING
Constructor Detail

MemoryBudget

MemoryBudget(EnvironmentImpl envImpl,
             EnvironmentImpl sharedCacheEnv,
             DbConfigManager configManager)
       throws DatabaseException
Throws:
DatabaseException
Method Detail

envConfigUpdate

public void envConfigUpdate(DbConfigManager configManager,
                            EnvironmentMutableConfig ignore)
                     throws DatabaseException
Respond to config updates.

Specified by:
envConfigUpdate in interface EnvConfigObserver
Throws:
DatabaseException

reset

void reset(long newMaxMemory,
           boolean newEnv,
           DbConfigManager configManager)
     throws DatabaseException
Initialize at construction time and when the cache is resized.

Parameters:
newMaxMemory - is the new total cache budget or is less than 0 if the total should remain unchanged.
newEnv - is true if this is the first time we are resetting the budget for a new environment. Note that a new environment has not yet been added to the set of shared cache environments.
Throws:
DatabaseException

getRuntimeMaxMemory

public static long getRuntimeMaxMemory()
Returns Runtime.maxMemory(), accounting for a MacOS bug. May return Long.MAX_VALUE if there is no inherent limit. Used by unit tests as well as by this class.


initCacheMemoryUsage

void initCacheMemoryUsage(long dbTreeAdminMemory)
Initialize the starting environment memory state. We really only need to recalibrate the tree and treeAdmin categories, since there are no locks and txns yet, and the items in the admin category are cleaner items and aren't affected by the recovery splicing process.


refreshTreeAdminMemoryUsage

void refreshTreeAdminMemoryUsage(long newSize)
Called by INList when clearing tree memory usage.


refreshTreeMemoryUsage

void refreshTreeMemoryUsage(long newSize)
Called by INList when recalculating tree memory usage.


isTreeUsageAboveMinimum

public boolean isTreeUsageAboveMinimum()
Returns whether eviction of INList information is allowed. To prevent extreme cache churn, eviction of Btree information is prohibited unless the tree memory usage is above this minimum value.


getMinTreeMemoryUsage

public long getMinTreeMemoryUsage()
For unit tests.


updateTreeMemoryUsage

public void updateTreeMemoryUsage(long increment)
Update the environment wide tree memory count, wake up the evictor if necessary.

Parameters:
increment - note that increment may be negative.

updateTxnMemoryUsage

public void updateTxnMemoryUsage(long increment)
Update the environment wide txn memory count, wake up the evictor if necessary.

Parameters:
increment - note that increment may be negative.

updateAdminMemoryUsage

public void updateAdminMemoryUsage(long increment)
Update the environment wide admin memory count, wake up the evictor if necessary.

Parameters:
increment - note that increment may be negative.

updateTreeAdminMemoryUsage

public void updateTreeAdminMemoryUsage(long increment)
Update the treeAdmin memory count, wake up the evictor if necessary.

Parameters:
increment - note that increment may be negative.

updateLockMemoryUsage

public void updateLockMemoryUsage(long increment,
                                  int lockTableIndex)

subtractCacheUsage

void subtractCacheUsage()

getVariableCacheUsage

long getVariableCacheUsage()

getLockMemoryUsage

public long getLockMemoryUsage()
Public for unit testing.


getCacheMemoryUsage

public long getCacheMemoryUsage()

getMaxMemory

public long getMaxMemory()

getTreeMemoryUsage

public long getTreeMemoryUsage()
Used for unit testing.


getAdminMemoryUsage

public long getAdminMemoryUsage()
Used for unit testing.


getTreeAdminMemoryUsage

public long getTreeAdminMemoryUsage()

getLogBufferBudget

public long getLogBufferBudget()

getTrackerBudget

public long getTrackerBudget()

getINOverhead

public long getINOverhead()

getBINOverhead

public long getBINOverhead()

getDINOverhead

public long getDINOverhead()

getDBINOverhead

public long getDBINOverhead()

tupleOutputSize

public static int tupleOutputSize(TupleOutput o)

byteArraySize

public static int byteArraySize(int arrayLen)
Returns the memory size occupied by a byte array of a given length. All arrays (regardless of element type) have the same overhead for a zero length array. On 32b Java, there are 4 bytes included in that fixed overhead that can be used for the first N elements -- however many fit in 4 bytes. On 64b Java, there is no extra space included. In all cases, space is allocated in 8 byte chunks.


shortArraySize

public static int shortArraySize(int arrayLen)

intArraySize

public static int intArraySize(int arrayLen)

objectArraySize

public static int objectArraySize(int arrayLen)

loadStats

StatGroup loadStats()

toString

public String toString()
Overrides:
toString in class Object

getTotals

public MemoryBudget.Totals getTotals()


Copyright (c) 2004-2010 Oracle. All rights reserved.