[ https://issues.apache.org/jira/browse/HIVE-21686?focusedWorklogId=241290&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-241290 ]
ASF GitHub Bot logged work on HIVE-21686: ----------------------------------------- Author: ASF GitHub Bot Created on: 13/May/19 20:46 Start Date: 13/May/19 20:46 Worklog Time Spent: 10m Work Description: odraese commented on pull request #626: [HIVE-21686] ensure that memory allocator does not evict using brute … URL: https://github.com/apache/hive/pull/626#discussion_r283497915 ########## File path: llap-server/src/java/org/apache/hadoop/hive/llap/cache/BuddyAllocator.java ########## @@ -277,7 +301,74 @@ public void allocateMultiple(MemoryBuffer[] dest, int size, BufferObjectFactory long threadId = arenaCount > 1 ? Thread.currentThread().getId() : 0; int destAllocIx = allocateFast(dest, null, 0, dest.length, freeListIx, allocationSize, (int)(threadId % arenaCount), arenaCount); - if (destAllocIx == dest.length) return; + if (destAllocIx == dest.length) { + return; + } + // Try to allocate memory if we haven't allocated all the way to maxSize yet; very rare. + destAllocIx = allocateWithExpand(dest, destAllocIx, freeListIx, allocationSize, arenaCount); + if (destAllocIx == dest.length) { + return; + } + + int forceEvictAttempt = 0; + long totalForceEvictedBytes = 0; + long currentEvicted; + int startArenaIx; + int emptyAttempt = 0; + + // We called reserveMemory so we know that there's memory waiting for us somewhere. + // But that can mean that the reserved memory is fragmented thus unusable + // or we have a common class of rare race conditions related to the order of locking/checking of + // different allocation areas this is due to the fact that Allocations arrive in a burst fashion. + // To mitigate that: + // - First we try again (fast path): + // - Second try to push on the memoryManger/evictor to evict more. + // - Third by pass the memory manager and use discards method to brute force evict if needed. + while (totalForceEvictedBytes < maxForcedEvictionSize && emptyAttempt < MAX_DISCARD_ATTEMPTS) { + // make sure we hit a different start on each new attempt + startArenaIx = (int) ((threadId + forceEvictAttempt) % arenaCount); + destAllocIx = + allocateFast(dest, null, destAllocIx, dest.length, freeListIx, allocationSize, startArenaIx, arenaCount); + if (destAllocIx == dest.length) { + return; + } + destAllocIx = + allocateWithSplit(dest, + null, + destAllocIx, + dest.length, + freeListIx, + allocationSize, + startArenaIx, + arenaCount, + -1); + if (destAllocIx == dest.length) { + return; + } + + if (forceEvictAttempt >= MAX_FAST_ATTEMPT) { Review comment: Seems that the forceEvictAttempt is really more an allocationAttempt because unless >= MAX_FAST_ATTEMPT, there isn't any eviction at all.... The variable name is somehow misleading. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 241290) Time Spent: 1h 20m (was: 1h 10m) > Brute Force eviction can lead to a random uncontrolled eviction pattern. > ------------------------------------------------------------------------ > > Key: HIVE-21686 > URL: https://issues.apache.org/jira/browse/HIVE-21686 > Project: Hive > Issue Type: Bug > Reporter: slim bouguerra > Assignee: slim bouguerra > Priority: Major > Labels: pull-request-available > Attachments: Cache_hitrate_improvement.csv, HIVE-21686.2.patch, > HIVE-21686.patch > > Time Spent: 1h 20m > Remaining Estimate: 0h > > Current logic used by brute force eviction can lead to a perpetual random > eviction pattern. > For instance if the cache build a small pocket of free memory where the total > size is greater than incoming allocation request, the allocator will randomly > evict block that fits a particular size. > This can happen over and over therefore all the eviction will be random. > In Addition this random eviction will lead a leak in the linked list > maintained by the policy since it does not know anymore about what is evicted > and what not. > The improvement of this patch is very substantial to TPC-DS benchmark. I > have tested it with 10TB scale 9 llap nodes and 32GB cache size per node. > The patch has showed very noticeable difference in the Hit rate for raw > number [^Cache_hitrate_improvement.csv] -- This message was sent by Atlassian JIRA (v7.6.3#76005)