1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.apache.hadoop.hbase.regionserver; 19 20 import org.apache.hadoop.hbase.classification.InterfaceAudience; 21 import org.apache.hadoop.hbase.util.ByteRange; 22 23 /** 24 * A memstore-local allocation buffer. 25 * <p> 26 * The MemStoreLAB is basically a bump-the-pointer allocator that allocates big (2MB) chunks from 27 * and then doles it out to threads that request slices into the array. 28 * <p> 29 * The purpose of this is to combat heap fragmentation in the regionserver. By ensuring that all 30 * KeyValues in a given memstore refer only to large chunks of contiguous memory, we ensure that 31 * large blocks get freed up when the memstore is flushed. 32 * <p> 33 * Without the MSLAB, the byte array allocated during insertion end up interleaved throughout the 34 * heap, and the old generation gets progressively more fragmented until a stop-the-world compacting 35 * collection occurs. 36 * <p> 37 */ 38 @InterfaceAudience.Private 39 public interface MemStoreLAB { 40 41 /** 42 * Allocate a slice of the given length. If the size is larger than the maximum size specified for 43 * this allocator, returns null. 44 * @param size 45 * @return {@link ByteRange} 46 */ 47 ByteRange allocateBytes(int size); 48 49 /** 50 * Close instance since it won't be used any more, try to put the chunks back to pool 51 */ 52 void close(); 53 54 /** 55 * Called when opening a scanner on the data of this MemStoreLAB 56 */ 57 void incScannerCount(); 58 59 /** 60 * Called when closing a scanner on the data of this MemStoreLAB 61 */ 62 void decScannerCount(); 63 }