/** * Let t = 2% of max memory. * Let e = round(log_2 t). * Then, we choose capacity = 2^e/(size of reference), * unless it is outside the close interval [1, 2^30]. */ private static int computeCapacity() { //VM detection //See http://java.sun.com/docs/hotspot/HotSpotFAQ.html#64bit_detection final String vmBit = System.getProperty("sun.arch.data.model"); //2% of max memory final double twoPC = Runtime.getRuntime().maxMemory()/50.0; //compute capacity final int e1 = (int)(Math.log(twoPC)/Math.log(2.0) + 0.5); final int e2 = e1 - ("32".equals(vmBit)? 2: 3); final int exponent = e2 < 0? 0: e2 > 30? 30: e2; final int c = 1 << exponent; LightWeightGSet.LOG.info("VM type = " + vmBit + "-bit"); LightWeightGSet.LOG.info("2% max memory = " + twoPC/(1 << 20) + " MB"); LightWeightGSet.LOG.info("capacity = 2^" + exponent + " = " + c + " entries"); return c; }
private INodeMap initInodeMap(INodeDirectory rootDir) { // Compute the map capacity by allocating 1.1% of total memory int capacity = LightWeightGSet.computeCapacity(1.1, "INodeMap"); INodeMap map = new INodeMap(capacity); map.put(rootDir); return map; }
@Override public LightWeightGSet.LinkedElement getNext() { return nextLinkedElement; }
@Override public void setNext(LightWeightGSet.LinkedElement next) { this.nextLinkedElement = next; }
BlocksMap(int initialCapacity, float loadFactor, FSNamesystem ns) { // Use 2% of total memory this.capacity = LightWeightGSet.computeCapacity(2.0, "BlocksMap"); this.blocks = new LightWeightGSet<Block, BlockInfo>(capacity); this.ns = ns; }
BlocksMap(int initialCapacity, float loadFactor) { this.capacity = computeCapacity(); this.blocks = new LightWeightGSet<Block, BlockInfo>(capacity); }
BlocksMap(int initialCapacity, float loadFactor, FSNamesystem ns) { this.capacity = computeCapacity(); this.blocks = new LightWeightGSet<Block, BlockInfo>(capacity); this.ns = ns; }