GeezerVison is showing github.com — Fix direct memory OOM on low-core containers · netty/netty@cc1fdf1
File tree
Expand file treeCollapse file tree
Open diff view settings
main/java/io/netty/buffer test/java/io/netty/buffer
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
84 | 84 | @UnstableApi |
85 | 85 | final class AdaptivePoolingAllocator { |
86 | 86 | private static final int LOW_MEM_THRESHOLD = 512 * 1024 * 1024; |
87 | | - private static final boolean IS_LOW_MEM = Runtime.getRuntime().maxMemory() <= LOW_MEM_THRESHOLD; |
| 87 | + private static final boolean IS_LOW_MEM = SystemPropertyUtil.getBoolean( |
| 88 | + "io.netty.allocator.lowMemory", |
| 89 | + Runtime.getRuntime().maxMemory() <= LOW_MEM_THRESHOLD); |
88 | 90 |
|
89 | 91 | /** |
90 | 92 | * Whether the IS_LOW_MEM setting should disable thread-local magazines. |
@@ -884,7 +886,7 @@ public boolean isEmpty() { |
884 | 886 | static final class SharedSizeClassedChunkCache extends SizeClassedChunkCache { |
885 | 887 | // Must exceed CHUNK_REUSE_QUEUE (the retention floor) to leave room for burst absorption. |
886 | 888 | // TODO replace with an unbounded concurrent collection once available. |
887 | | - private static final int SHARED_CACHE_CAPACITY = Math.max(128, CHUNK_REUSE_QUEUE * 2); |
| 889 | + private static final int SHARED_CACHE_CAPACITY = Math.max(16, CHUNK_REUSE_QUEUE * 2); |
888 | 890 | private final Queue<SizeClassedChunk> queue; |
889 | 891 | private final AtomicLong purgeBudget; |
890 | 892 | private final ArrayList<SizeClassedChunk> deferredBuffer = new ArrayList<>(); |
|
Collapse file
Copy file name to clipboardExpand all lines: buffer/src/test/java/io/netty/buffer/SizeClassedChunkCacheTest.java +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -352,16 +352,19 @@ void cacheSettlesAtRetentionFloorAfterBurstThreadLocal() { |
352 | 352 | void cacheSettlesAfterBurstShared() { |
353 | 353 | SizeClassedChunkCache cache = SizeClassedChunkCache.create(false); |
354 | 354 |
|
355 | | - int excess = 10; |
| 355 | + int crq = AdaptivePoolingAllocator.CHUNK_REUSE_QUEUE; |
| 356 | + int capacity = Math.max(16, crq * 2); |
| 357 | + int excess = Math.min(10, capacity - crq); |
| 358 | + assertTrue(excess > 0, "excess must be positive for the test to be meaningful"); |
356 | 359 | SizeClassedChunk workingSet = chunkWithCapacity(); |
357 | 360 | cache.offerChunk(workingSet); |
358 | | - for (int i = 0; i < AdaptivePoolingAllocator.CHUNK_REUSE_QUEUE - 1; i++) { |
| 361 | + for (int i = 0; i < crq - 1; i++) { |
359 | 362 | cache.offerChunk(chunkWithoutCapacity()); |
360 | 363 | } |
361 | 364 | SizeClassedChunk[] excessChunks = new SizeClassedChunk[excess]; |
362 | 365 | for (int i = 0; i < excess; i++) { |
363 | 366 | excessChunks[i] = fullChunk(); |
364 | | - cache.offerChunk(excessChunks[i]); |
| 367 | + assertTrue(cache.offerChunk(excessChunks[i]), "all excess chunks must be accepted by the queue"); |
365 | 368 | } |
366 | 369 |
|
367 | 370 | int maxCycles = (AdaptivePoolingAllocator.CHUNK_PURGE_THRESHOLD + 1) * 3; |
|