You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/02/05 13:32:37 UTC

[GitHub] [flink] tillrohrmann commented on a change in pull request #11025: [FLINK-15919][core][mem] MemoryManager shouldn't allow releasing more memory than reserved

tillrohrmann commented on a change in pull request #11025: [FLINK-15919][core][mem] MemoryManager shouldn't allow releasing more memory than reserved
URL: https://github.com/apache/flink/pull/11025#discussion_r375248142
 
 

 ##########
 File path: flink-runtime/src/test/java/org/apache/flink/runtime/memory/MemoryManagerTest.java
 ##########
 @@ -264,6 +265,30 @@ public void testMemoryReservation() throws MemoryReservationException {
 		memoryManager.releaseAllMemory(owner, MemoryType.OFF_HEAP);
 	}
 
+	@Test
+	public void testMemoryReleaseMoreThanReserved() throws MemoryReservationException {
+		Object owner = new Object();
+		Object owner2 = new Object();
+		long totalHeapMemorySize = memoryManager.availableMemory(MemoryType.HEAP);
+		// to prevent memory size exceeding the maximum, reserve some memory from another owner.
+		memoryManager.reserveMemory(owner2, MemoryType.HEAP, PAGE_SIZE);
+
+		// test reserve once and release multiple times
+		memoryManager.reserveMemory(owner, MemoryType.HEAP, PAGE_SIZE);
+		memoryManager.releaseMemory(owner, MemoryType.HEAP, PAGE_SIZE);
+		memoryManager.releaseMemory(owner, MemoryType.HEAP, PAGE_SIZE);
+		long heapMemoryLeft = memoryManager.availableMemory(MemoryType.HEAP);
+		assertEquals("Memory leak happens", totalHeapMemorySize - PAGE_SIZE, heapMemoryLeft);
+
+		// test release more than the left reserved size
+		memoryManager.reserveMemory(owner, MemoryType.HEAP, PAGE_SIZE);
+		memoryManager.releaseMemory(owner, MemoryType.HEAP, PAGE_SIZE / 2);
+		memoryManager.releaseMemory(owner, MemoryType.HEAP, PAGE_SIZE);
+		heapMemoryLeft = memoryManager.availableMemory(MemoryType.HEAP);
+		assertEquals("Memory leak happens", totalHeapMemorySize - PAGE_SIZE, heapMemoryLeft);
+		memoryManager.releaseAllMemory(owner2, MemoryType.HEAP);
 
 Review comment:
   I'd suggest to create a separate test for this part.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services