tillrohrmann commented on a change in pull request #11109: 
[FLINK-15758][MemManager] Release segment and its unsafe memory in GC Cleaner
URL: https://github.com/apache/flink/pull/11109#discussion_r410258640
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/memory/MemoryManager.java
 ##########
 @@ -240,7 +234,8 @@ public void allocatePages(
                        Set<MemorySegment> segmentsForOwner = 
currentSegmentsForOwner == null ?
                                new HashSet<>(numberOfPages) : 
currentSegmentsForOwner;
                        for (long i = numberOfPages; i > 0; i--) {
-                               MemorySegment segment = 
allocateOffHeapUnsafeMemory(getPageSize(), owner);
+                               int size = getPageSize();
+                               MemorySegment segment = 
allocateOffHeapUnsafeMemory(size, owner, () -> 
memoryBudget.releaseMemory(size));
 
 Review comment:
   If `getPageSize()` is constant, then I would suggest to create a single `() 
-> memoryBudget.releaseMemory(size)` instance. One could even have a method 
`releasePageSize() { memoryBudget.releaseMemory(getPageSize()); }` and then 
define outside of the loop a `Runnable releasePageSize = this::releasePageSize` 
and then pass `releasePageSize` to `allocateOffHeapUnsafeMemory`.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to