diff --git common/src/java/org/apache/hadoop/hive/conf/HiveConf.java common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index 348e07bbf8..70246000cd 100644 --- common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -3883,6 +3883,8 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal "Maximum size for IO allocator or ORC low-level cache.", "hive.llap.io.cache.orc.size"), LLAP_ALLOCATOR_DIRECT("hive.llap.io.allocator.direct", true, "Whether ORC low-level cache should use direct allocation."), + LLAP_ALLOCATOR_PREALLOCATE("hive.llap.io.allocator.preallocate", true, + "Whether to preallocate the entire IO memory at init time."), LLAP_ALLOCATOR_MAPPED("hive.llap.io.allocator.mmap", false, "Whether ORC low-level cache should use memory mapped allocation (direct I/O). \n" + "This is recommended to be used along-side NVDIMM (DAX) or NVMe flash storage."), diff --git llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java index a27964f1a0..995e5e321e 100644 --- llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java +++ llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java @@ -101,7 +101,9 @@ public BuddyAllocator(Configuration conf, MemoryManager mm, LlapDaemonCacheMetri getMaxTotalMemorySize(conf), HiveConf.getSizeVar(conf, ConfVars.LLAP_ALLOCATOR_DEFRAG_HEADROOM), HiveConf.getVar(conf, ConfVars.LLAP_ALLOCATOR_MAPPED_PATH), - mm, metrics, HiveConf.getVar(conf, ConfVars.LLAP_ALLOCATOR_DISCARD_METHOD)); + mm, metrics, HiveConf.getVar(conf, ConfVars.LLAP_ALLOCATOR_DISCARD_METHOD), + HiveConf.getBoolVar(conf, ConfVars.LLAP_ALLOCATOR_PREALLOCATE) + ); } private static boolean areAssertsEnabled() { @@ -122,9 +124,10 @@ private static long getMaxTotalMemorySize(Configuration conf) { } @VisibleForTesting - public BuddyAllocator(boolean isDirectVal, boolean isMappedVal, int minAllocVal, - int maxAllocVal, int arenaCount, long maxSizeVal, long defragHeadroom, String mapPath, - MemoryManager memoryManager, LlapDaemonCacheMetrics metrics, String discardMethod) { + public BuddyAllocator(boolean isDirectVal, boolean isMappedVal, int minAllocVal, int maxAllocVal, + int arenaCount, long maxSizeVal, long defragHeadroom, String mapPath, + MemoryManager memoryManager, LlapDaemonCacheMetrics metrics, String discardMethod, + boolean doPreallocate) { isDirect = isDirectVal; isMapped = isMappedVal; minAllocation = minAllocVal; @@ -153,9 +156,11 @@ public BuddyAllocator(boolean isDirectVal, boolean isMappedVal, int minAllocVal, for (int i = 0; i < maxArenas; ++i) { arenas[i] = new Arena(); } - Arena firstArena = arenas[0]; - firstArena.init(0); - allocatedArenas.set(1); + int initCount = doPreallocate && !isMapped ? maxArenas : 1; + for (int i = 0; i < initCount; ++i) { + arenas[i].init(i); + } + allocatedArenas.set(initCount); this.memoryManager = memoryManager; defragCounters = new AtomicLong[maxAllocLog2 - minAllocLog2 + 1]; for (int i = 0; i < defragCounters.length; ++i) { diff --git llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocator.java llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocator.java index b3179c0a74..11d7aa653f 100644 --- llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocator.java +++ llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocator.java @@ -87,7 +87,7 @@ public void testSameSizes() throws Exception { int min = 3, max = 8, maxAlloc = 1 << max; BuddyAllocator a = new BuddyAllocator(isDirect, isMapped, 1 << min, maxAlloc, maxAlloc, maxAlloc, 0, tmpDir, new DummyMemoryManager(), - LlapDaemonCacheMetrics.create("test", "1"), null); + LlapDaemonCacheMetrics.create("test", "1"), null, true); for (int i = max; i >= min; --i) { allocSameSize(a, 1 << (max - i), i); } @@ -98,7 +98,7 @@ public void testMultipleArenas() throws Exception { int max = 8, maxAlloc = 1 << max, allocLog2 = max - 1, arenaCount = 5; BuddyAllocator a = new BuddyAllocator(isDirect, isMapped, 1 << 3, maxAlloc, maxAlloc, maxAlloc * arenaCount, 0, tmpDir, new DummyMemoryManager(), - LlapDaemonCacheMetrics.create("test", "1"), null); + LlapDaemonCacheMetrics.create("test", "1"), null, true); allocSameSize(a, arenaCount * 2, allocLog2); } @@ -107,7 +107,7 @@ public void testMTT() { final int min = 3, max = 8, maxAlloc = 1 << max, allocsPerSize = 3; final BuddyAllocator a = new BuddyAllocator(isDirect, isMapped, 1 << min, maxAlloc, maxAlloc * 8, maxAlloc * 24, 0, tmpDir, new DummyMemoryManager(), - LlapDaemonCacheMetrics.create("test", "1"), null); + LlapDaemonCacheMetrics.create("test", "1"), null, true); ExecutorService executor = Executors.newFixedThreadPool(3); final CountDownLatch cdlIn = new CountDownLatch(3), cdlOut = new CountDownLatch(1); FutureTask upTask = new FutureTask(new Callable() { @@ -152,7 +152,7 @@ public void testMTTArenas() { final int min = 3, max = 4, maxAlloc = 1 << max, minAllocCount = 2048, threadCount = 4; final BuddyAllocator a = new BuddyAllocator(isDirect, isMapped, 1 << min, maxAlloc, maxAlloc, (1 << min) * minAllocCount, 0, tmpDir, new DummyMemoryManager(), - LlapDaemonCacheMetrics.create("test", "1"), null); + LlapDaemonCacheMetrics.create("test", "1"), null, true); ExecutorService executor = Executors.newFixedThreadPool(threadCount); final CountDownLatch cdlIn = new CountDownLatch(threadCount), cdlOut = new CountDownLatch(1); Callable testCallable = new Callable() { @@ -193,7 +193,7 @@ private void testVariableSizeInternal( int min = 3, max = 8, maxAlloc = 1 << max, arenaSize = maxAlloc * arenaSizeMult; BuddyAllocator a = new BuddyAllocator(isDirect, isMapped, 1 << min, maxAlloc, arenaSize, arenaSize * arenaCount, 0, tmpDir, new DummyMemoryManager(), - LlapDaemonCacheMetrics.create("test", "1"), null); + LlapDaemonCacheMetrics.create("test", "1"), null, true); allocateUp(a, min, max, allocCount, true); allocateDown(a, min, max, allocCount, true); allocateDown(a, min, max, allocCount, false); diff --git llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocatorForceEvict.java llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocatorForceEvict.java index b3617a68d8..c9e41e6866 100644 --- llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocatorForceEvict.java +++ llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestBuddyAllocatorForceEvict.java @@ -228,7 +228,7 @@ public static void runMttTest(BuddyAllocator a, FutureTask[] allocTasks, cdlIn.await(); // Wait for all threads to be ready. } catch (InterruptedException e) { throw new RuntimeException(e); - } + } cdlOut.countDown(); // Release them at the same time. for (int i = 0; i < allocTasks.length; ++i) { try { @@ -417,7 +417,7 @@ private static void checkTestValue( public static BuddyAllocator create(int max, int arenas, int total, boolean isShortcut, boolean isBruteForceOnly) { BuddyAllocator result = new BuddyAllocator(false, false, 8, max, arenas, total, 0, - null, MM, METRICS, isBruteForceOnly ? "brute" : null); + null, MM, METRICS, isBruteForceOnly ? "brute" : null, true); if (!isShortcut) { result.disableDefragShortcutForTest(); } diff --git llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestOrcMetadataCache.java llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestOrcMetadataCache.java index aa9d6ed970..ad6b90e358 100644 --- llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestOrcMetadataCache.java +++ llap-server/src/test/org/apache/hadoop/hive/llap/cache/TestOrcMetadataCache.java @@ -102,7 +102,7 @@ public void testBuffers() throws Exception { final int MAX_ALLOC = 64; LlapDaemonCacheMetrics metrics = LlapDaemonCacheMetrics.create("", ""); BuddyAllocator alloc = new BuddyAllocator( - false, false, 8, MAX_ALLOC, 1, 4096, 0, null, mm, metrics, null); + false, false, 8, MAX_ALLOC, 1, 4096, 0, null, mm, metrics, null, true); MetadataCache cache = new MetadataCache(alloc, mm, cp, true, metrics); Object fileKey1 = new Object(); Random rdm = new Random(); @@ -163,7 +163,7 @@ public void testIncompleteCbs() throws Exception { final int MAX_ALLOC = 64; LlapDaemonCacheMetrics metrics = LlapDaemonCacheMetrics.create("", ""); BuddyAllocator alloc = new BuddyAllocator( - false, false, 8, MAX_ALLOC, 1, 4096, 0, null, mm, metrics, null); + false, false, 8, MAX_ALLOC, 1, 4096, 0, null, mm, metrics, null, true); MetadataCache cache = new MetadataCache(alloc, mm, cp, true, metrics); DataCache.BooleanRef gotAllData = new DataCache.BooleanRef(); Object fileKey1 = new Object();