@@ -71,23 +71,28 @@ def test_cleanup(self):
7171 # Now run the full stack to warm up internal caches/pools
7272 LARGE_COLUMN_SIZE = 1024 * 1024 * 63
7373 self .stress_with_col_size (cluster , node1 , LARGE_COLUMN_SIZE )
74- # Generational ZGC (JDK 21) only processes PhantomReferences during major collections
75- # which may not run during short tests. Force a GC; sleep lets the async Cleaner
76- # thread finish decrementing TOTAL_CAPACITY before we measure.
77- subprocess .check_call (['jcmd' , str (node1 .pid ), 'GC.run' ])
78- time .sleep (1 )
79- after1stLargeStress = self .directbytes (node1 )
74+ after1stLargeStress = self .directbytes_post_gc (node1 )
8075 logger .info ("After 1st large column stress, direct memory: {0}" .format (after1stLargeStress ))
8176
8277 # Now run the full stack to see how much memory is allocated for the second "large" columns request
8378 self .stress_with_col_size (cluster , node1 , LARGE_COLUMN_SIZE )
84- subprocess .check_call (['jcmd' , str (node1 .pid ), 'GC.run' ])
85- time .sleep (1 )
86- after2ndLargeStress = self .directbytes (node1 )
79+ after2ndLargeStress = self .directbytes_post_gc (node1 )
8780 logger .info ("After 2nd large column stress, direct memory: {0}" .format (after2ndLargeStress ))
8881
8982 # We may allocate direct memory proportional to size of a request
9083 # but we want to ensure that when we do subsequent calls the used direct memory is not growing
91- diff = int ( after2ndLargeStress ) - int ( after1stLargeStress )
84+ diff = after2ndLargeStress - after1stLargeStress
9285 logger .info ("Direct memory delta: {0}" .format (diff ))
9386 assert diff < LARGE_COLUMN_SIZE
87+
88+ def directbytes_post_gc (self , node ):
89+ """Trigger GC and wait for the Cleaner thread to release DirectByteBuffers.
90+
91+ Generational ZGC (JDK 21) only processes PhantomReferences during major
92+ collections which may not run during short tests. After GC, the Cleaner
93+ daemon thread decrements TOTAL_CAPACITY asynchronously, so we sleep to
94+ allow it to complete.
95+ """
96+ subprocess .check_call (['jcmd' , str (node .pid ), 'GC.run' ])
97+ time .sleep (3 )
98+ return int (self .directbytes (node ))
0 commit comments