@@ -93,20 +93,15 @@ void purgeReturnsNullWhenNoChunkHasCapacity(boolean threadLocal) { |
93 | 93 |
|
94 | 94 | // --- purge: epoch aging and eviction (both caches) --- |
95 | 95 |
|
96 | | - @ParameterizedTest |
97 | | - @ValueSource(booleans = {true, false}) |
98 | | - void fullChunkAgesEachPurgeAndIsEvictedPastThreshold(boolean threadLocal) { |
99 | | - SizeClassedChunkCache cache = SizeClassedChunkCache.create(threadLocal); |
| 96 | + @Test |
| 97 | + void fullChunkAgesEachPurgeAndIsEvictedPastThreshold_threadLocal() { |
| 98 | + SizeClassedChunkCache cache = SizeClassedChunkCache.create(true); |
100 | 99 |
|
101 | | - // Pad above retention floor so eviction is allowed |
102 | 100 | for (int i = 0; i < AdaptivePoolingAllocator.CHUNK_REUSE_QUEUE; i++) { |
103 | 101 | cache.offerChunk(chunkWithoutCapacity()); |
104 | 102 | } |
105 | | - |
106 | | - // Working-set chunk absorbs scan picks — non-full, epoch=0 at head after partition |
107 | 103 | SizeClassedChunk workingSet = chunkWithCapacity(); |
108 | 104 | cache.offerChunk(workingSet); |
109 | | - |
110 | 105 | SizeClassedChunk idle = fullChunk(); |
111 | 106 | cache.offerChunk(idle); |
112 | 107 |
|
@@ -117,12 +112,33 @@ void fullChunkAgesEachPurgeAndIsEvictedPastThreshold(boolean threadLocal) { |
117 | 112 | assertEquals(i + 1, idle.purgeEpoch); |
118 | 113 | verify(idle, never()).markToDeallocate(); |
119 | 114 | } |
120 | | - |
121 | 115 | SizeClassedChunk polled = cache.forcePurge(); |
122 | 116 | assertSame(workingSet, polled); |
123 | 117 | verify(idle).markToDeallocate(); |
124 | 118 | } |
125 | 119 |
|
| 120 | + @Test |
| 121 | + void fullChunkAgesAndIsEventuallyEvicted_shared() { |
| 122 | + SizeClassedChunkCache cache = SizeClassedChunkCache.create(false); |
| 123 | + |
| 124 | + for (int i = 0; i < AdaptivePoolingAllocator.CHUNK_REUSE_QUEUE; i++) { |
| 125 | + cache.offerChunk(chunkWithoutCapacity()); |
| 126 | + } |
| 127 | + SizeClassedChunk workingSet = chunkWithCapacity(); |
| 128 | + cache.offerChunk(workingSet); |
| 129 | + SizeClassedChunk idle = fullChunk(); |
| 130 | + cache.offerChunk(idle); |
| 131 | + |
| 132 | + int maxCycles = (AdaptivePoolingAllocator.CHUNK_PURGE_THRESHOLD + 1) * 3; |
| 133 | + for (int i = 0; i < maxCycles; i++) { |
| 134 | + SizeClassedChunk polled = cache.forcePurge(); |
| 135 | + if (polled != null) { |
| 136 | + cache.offerChunk(polled); |
| 137 | + } |
| 138 | + } |
| 139 | + verify(idle, atLeastOnce()).markToDeallocate(); |
| 140 | + } |
| 141 | + |
126 | 142 | @ParameterizedTest |
127 | 143 | @ValueSource(booleans = {true, false}) |
128 | 144 | void purgeResetsEpochForNonIdleChunks(boolean threadLocal) { |
@@ -261,32 +277,25 @@ void purgeHandlesWrappedRingCorrectly() { |
261 | 277 |
|
262 | 278 | // --- bursty traffic: idle chunks are eventually evicted --- |
263 | 279 |
|
264 | | - @ParameterizedTest |
265 | | - @ValueSource(booleans = {true, false}) |
266 | | - void cacheSettlesAtRetentionFloorAfterBurst(boolean threadLocal) { |
267 | | - SizeClassedChunkCache cache = SizeClassedChunkCache.create(threadLocal); |
| 280 | + @Test |
| 281 | + void cacheSettlesAtRetentionFloorAfterBurst_threadLocal() { |
| 282 | + SizeClassedChunkCache cache = SizeClassedChunkCache.create(true); |
268 | 283 |
|
269 | 284 | int floor = AdaptivePoolingAllocator.CHUNK_REUSE_QUEUE; |
270 | 285 | int excess = 10; |
271 | 286 |
|
272 | | - // Working-set chunk absorbs scan picks |
273 | 287 | SizeClassedChunk workingSet = chunkWithCapacity(); |
274 | 288 | cache.offerChunk(workingSet); |
275 | | - |
276 | | - // Retention floor padding |
277 | 289 | for (int i = 0; i < floor - 1; i++) { |
278 | 290 | cache.offerChunk(chunkWithoutCapacity()); |
279 | 291 | } |
280 | | - |
281 | | - // Excess full chunks — should age and be evicted |
282 | 292 | SizeClassedChunk[] excessChunks = new SizeClassedChunk[excess]; |
283 | 293 | for (int i = 0; i < excess; i++) { |
284 | 294 | excessChunks[i] = fullChunk(); |
285 | 295 | cache.offerChunk(excessChunks[i]); |
286 | 296 | } |
287 | 297 |
|
288 | | - int purgesNeeded = AdaptivePoolingAllocator.CHUNK_PURGE_THRESHOLD + 1; |
289 | | - for (int i = 0; i < purgesNeeded; i++) { |
| 298 | + for (int i = 0; i < AdaptivePoolingAllocator.CHUNK_PURGE_THRESHOLD + 1; i++) { |
290 | 299 | SizeClassedChunk polled = cache.forcePurge(); |
291 | 300 | assertSame(workingSet, polled); |
292 | 301 | cache.offerChunk(workingSet); |
@@ -298,29 +307,49 @@ void cacheSettlesAtRetentionFloorAfterBurst(boolean threadLocal) { |
298 | 307 | verify(workingSet, never()).markToDeallocate(); |
299 | 308 | } |
300 | 309 |
|
| 310 | + @Test |
| 311 | + void cacheSettlesAfterBurst_shared() { |
| 312 | + SizeClassedChunkCache cache = SizeClassedChunkCache.create(false); |
| 313 | + |
| 314 | + int excess = 10; |
| 315 | + SizeClassedChunk workingSet = chunkWithCapacity(); |
| 316 | + cache.offerChunk(workingSet); |
| 317 | + for (int i = 0; i < AdaptivePoolingAllocator.CHUNK_REUSE_QUEUE - 1; i++) { |
| 318 | + cache.offerChunk(chunkWithoutCapacity()); |
| 319 | + } |
| 320 | + SizeClassedChunk[] excessChunks = new SizeClassedChunk[excess]; |
| 321 | + for (int i = 0; i < excess; i++) { |
| 322 | + excessChunks[i] = fullChunk(); |
| 323 | + cache.offerChunk(excessChunks[i]); |
| 324 | + } |
| 325 | + |
| 326 | + int maxCycles = (AdaptivePoolingAllocator.CHUNK_PURGE_THRESHOLD + 1) * 3; |
| 327 | + for (int i = 0; i < maxCycles; i++) { |
| 328 | + SizeClassedChunk polled = cache.forcePurge(); |
| 329 | + if (polled != null) { |
| 330 | + cache.offerChunk(polled); |
| 331 | + } |
| 332 | + } |
| 333 | + |
| 334 | + for (SizeClassedChunk chunk : excessChunks) { |
| 335 | + verify(chunk, atLeastOnce()).markToDeallocate(); |
| 336 | + } |
| 337 | + } |
| 338 | + |
301 | 339 | // --- epoch aging with working set --- |
302 | 340 | // Scan resets epoch on pick (the chunk is being used). Partition sub-ordering puts |
303 | 341 | // epoch=0 (recently used) at head, epoch>0 (idle) behind. Scan prefers head, so |
304 | 342 | // idle chunks age undisturbed behind the working set. |
305 | 343 |
|
306 | | - @ParameterizedTest |
307 | | - @ValueSource(booleans = {true, false}) |
308 | | - void excessFullChunksAgeWhileWorkingSetIsPreferred(boolean threadLocal) { |
309 | | - SizeClassedChunkCache cache = SizeClassedChunkCache.create(threadLocal); |
| 344 | + @Test |
| 345 | + void excessFullChunksAgeWhileWorkingSetIsPreferred_threadLocal() { |
| 346 | + SizeClassedChunkCache cache = SizeClassedChunkCache.create(true); |
310 | 347 |
|
311 | | - // Pad to retention floor |
312 | 348 | for (int i = 0; i < AdaptivePoolingAllocator.CHUNK_REUSE_QUEUE; i++) { |
313 | 349 | cache.offerChunk(chunkWithoutCapacity()); |
314 | 350 | } |
315 | | - |
316 | | - // Working-set chunk: non-full (remaining != capacity), has capacity. |
317 | | - // Purge resets its epoch to 0. Partition puts it at head. Scan picks it. |
318 | 351 | SizeClassedChunk workingSet = chunkWithCapacity(); |
319 | 352 | cache.offerChunk(workingSet); |
320 | | - |
321 | | - // Excess full chunks: remaining == capacity, has capacity. |
322 | | - // Purge ages them. Partition puts them behind working-set (epoch>0). |
323 | | - // Scan doesn't reach them — working-set absorbs the pick. |
324 | 353 | int excess = 3; |
325 | 354 | SizeClassedChunk[] idleChunks = new SizeClassedChunk[excess]; |
326 | 355 | for (int i = 0; i < excess; i++) { |
@@ -340,6 +369,35 @@ void excessFullChunksAgeWhileWorkingSetIsPreferred(boolean threadLocal) { |
340 | 369 | verify(workingSet, never()).markToDeallocate(); |
341 | 370 | } |
342 | 371 |
|
| 372 | + @Test |
| 373 | + void excessFullChunksEventuallyEvicted_shared() { |
| 374 | + SizeClassedChunkCache cache = SizeClassedChunkCache.create(false); |
| 375 | + |
| 376 | + for (int i = 0; i < AdaptivePoolingAllocator.CHUNK_REUSE_QUEUE; i++) { |
| 377 | + cache.offerChunk(chunkWithoutCapacity()); |
| 378 | + } |
| 379 | + SizeClassedChunk workingSet = chunkWithCapacity(); |
| 380 | + cache.offerChunk(workingSet); |
| 381 | + int excess = 3; |
| 382 | + SizeClassedChunk[] idleChunks = new SizeClassedChunk[excess]; |
| 383 | + for (int i = 0; i < excess; i++) { |
| 384 | + idleChunks[i] = fullChunk(); |
| 385 | + cache.offerChunk(idleChunks[i]); |
| 386 | + } |
| 387 | + |
| 388 | + int maxCycles = (AdaptivePoolingAllocator.CHUNK_PURGE_THRESHOLD + 1) * 3; |
| 389 | + for (int i = 0; i < maxCycles; i++) { |
| 390 | + SizeClassedChunk polled = cache.forcePurge(); |
| 391 | + if (polled != null) { |
| 392 | + cache.offerChunk(polled); |
| 393 | + } |
| 394 | + } |
| 395 | + |
| 396 | + for (SizeClassedChunk idle : idleChunks) { |
| 397 | + verify(idle, atLeastOnce()).markToDeallocate(); |
| 398 | + } |
| 399 | + } |
| 400 | + |
343 | 401 | // --- full-but-active chunk must not be prematurely evicted --- |
344 | 402 | // A chunk that is polled every purge cycle but whose buffers are short-lived |
345 | 403 | // (all segments return before next purge) looks "full" (remaining == capacity) |
|