protected long seekUnusedDevice ( Long threadId , Integer deviceId , Aggressiveness aggressiveness ) { AtomicLong freeSpace = new AtomicLong ( 0 ) ; // int initialSize = allocations.size(); // these 2 variables will contain jvm-wise memory access frequencies float shortAverage = deviceShort . getAverage ( ) ; float longAverage = deviceLong . getAverage ( ) ; // threshold is calculated based on agressiveness specified via configuration float shortThreshold = shortAverage / ( Aggressiveness . values ( ) . length - aggressiveness . ordinal ( ) ) ; float longThreshold = longAverage / ( Aggressiveness . values ( ) . length - aggressiveness . ordinal ( ) ) ; AtomicInteger elementsDropped = new AtomicInteger ( 0 ) ; AtomicInteger elementsMoved = new AtomicInteger ( 0 ) ; AtomicInteger elementsSurvived = new AtomicInteger ( 0 ) ; for ( Long object : memoryHandler . getDeviceTrackingPoints ( deviceId ) ) { AllocationPoint point = getAllocationPoint ( object ) ; // if (point.getAccessState().isToeAvailable()) { // point.getAccessState().requestToe(); /* Check if memory points to non-existant buffer, using externals. If externals don't have specified buffer - delete reference. */ if ( point . getBuffer ( ) == null ) { if ( point . getAllocationStatus ( ) == AllocationStatus . DEVICE ) { // we deallocate device memory purgeDeviceObject ( threadId , deviceId , object , point , false ) ; freeSpace . addAndGet ( AllocationUtils . getRequiredMemory ( point . getShape ( ) ) ) ; // and we deallocate host memory, since object is dereferenced purgeZeroObject ( point . getBucketId ( ) , object , point , false ) ; elementsDropped . incrementAndGet ( ) ; continue ; } ; } else { elementsSurvived . incrementAndGet ( ) ; } /* Check, if memory can be removed from allocation. To check it, we just compare average rates for few tens of latest calls */ /* long millisecondsTTL = configuration.getMinimumTTLMilliseconds(); if (point.getRealDeviceAccessTime() < System.currentTimeMillis() - millisecondsTTL) { // we could remove device allocation ONLY if it's older then minimum TTL if (point.getTimerLong().getFrequencyOfEvents() < longThreshold && point.getTimerShort().getFrequencyOfEvents() < shortThreshold) { //log.info("Removing object: " + object); purgeDeviceObject(threadId, deviceId, object, point, true); freeSpace.addAndGet(AllocationUtils.getRequiredMemory(point.getShape())); elementsMoved.incrementAndGet(); //purgeDeviceObject(threadId, deviceId, object, point, true); } } */ // point.getAccessState().releaseToe(); //} } log . debug ( "Thread/Device [" + threadId + "/" + deviceId + "] elements purged: [" + elementsDropped . get ( ) + "]; Relocated: [" + elementsMoved . get ( ) + "]; Survivors: [" + elementsSurvived . get ( ) + "]" ) ; return freeSpace . get ( ) ; }
This method seeks for unused device memory allocations for specified thread and device