@ VisibleForTesting public static long calculateNewNetworkBufferMemory ( Configuration config , long maxJvmHeapMemory ) { // The maximum heap memory has been adjusted as in TaskManagerServices#calculateHeapSizeMB // and we need to invert these calculations. final long jvmHeapNoNet ; final MemoryType memoryType = ConfigurationParserUtils . getMemoryType ( config ) ; if ( memoryType == MemoryType . HEAP ) { jvmHeapNoNet = maxJvmHeapMemory ; } else if ( memoryType == MemoryType . OFF_HEAP ) { long configuredMemory = ConfigurationParserUtils . getManagedMemorySize ( config ) << 20 ; // megabytes to bytes if ( configuredMemory > 0 ) { // The maximum heap memory has been adjusted according to configuredMemory, i.e. // maxJvmHeap = jvmHeapNoNet - configuredMemory jvmHeapNoNet = maxJvmHeapMemory + configuredMemory ; } else { // The maximum heap memory has been adjusted according to the fraction, i.e. // maxJvmHeap = jvmHeapNoNet - jvmHeapNoNet * managedFraction = jvmHeapNoNet * (1 - managedFraction) jvmHeapNoNet = ( long ) ( maxJvmHeapMemory / ( 1.0 - ConfigurationParserUtils . getManagedMemoryFraction ( config ) ) ) ; } } else { throw new RuntimeException ( "No supported memory type detected." ) ; } // finally extract the network buffer memory size again from: // jvmHeapNoNet = jvmHeap - networkBufBytes // = jvmHeap - Math.min(networkBufMax, Math.max(networkBufMin, jvmHeap * netFraction) // jvmHeap = jvmHeapNoNet / (1.0 - networkBufFraction) float networkBufFraction = config . getFloat ( TaskManagerOptions . NETWORK_BUFFERS_MEMORY_FRACTION ) ; long networkBufSize = ( long ) ( jvmHeapNoNet / ( 1.0 - networkBufFraction ) * networkBufFraction ) ; return calculateNewNetworkBufferMemory ( config , networkBufSize , maxJvmHeapMemory ) ; }
Calculates the amount of memory used for network buffers inside the current JVM instance based on the available heap or the max heap size and the according configuration parameters .