Caused by: io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 16777216byte(s) of direct memory(used: 7532970287, max: 7549747200) at io.netty.util.internal.PlatformDependent.incrementMemoryCounter(PlatformDependent.java:618) at io.netty.util.internal.PlatformDependent.allocateDirectNoCleaner(PlatformDependent.java:572) at io.netty.buffer.PoolArena$DirectArena.allocateDirect(PoolArena.java:764) at io.netty.buffer.PoolArena$DirectArena.newChunk(PoolArena.java:740) at io.netty.buffer.PoolArena.allocateNormal(PoolArena.java:244) at io.netty.buffer.PoolArena.allocate(PoolArena.java:226) at io.netty.buffer.PoolArena.allocate(PoolArena.java:146) at io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:324) at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:181) at io.netty.buffer.AbstractByteBufAllocator.buffer(AbstractByteBufAllocator.java:117)
/** * Allocate a new {@link ByteBuffer} with the given {@code capacity}. {@link ByteBuffer}s allocated with * this method <strong>MUST</strong> be deallocated via {@link #freeDirectNoCleaner(ByteBuffer)}. */ publicstatic ByteBuffer allocateDirectNoCleaner(int capacity){ assert USE_DIRECT_BUFFER_NO_CLEANER;
// Here is how the system property is used: // // * < 0 - Don't use cleaner, and inherit max direct memory from java. In this case the // "practical max direct memory" would be 2 * max memory as defined by the JDK. // * == 0 - Use cleaner, Netty will not enforce max memory, and instead will defer to JDK. // * > 0 - Don't use cleaner. This will limit Netty's total direct memory // (note: that JDK's direct memory limit is independent of this). // 默认未设置,所以maxDirectMemory值为-1 long maxDirectMemory = SystemPropertyUtil.getLong("io.netty.maxDirectMemory", -1);
@SuppressWarnings("unchecked") List<String> vmArgs = (List<String>) runtimeClass.getDeclaredMethod("getInputArguments").invoke(runtime); for (int i = vmArgs.size() - 1; i >= 0; i --) { Matcher m = MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN.matcher(vmArgs.get(i)); if (!m.matches()) { continue; }
/** * Returns the maximum amount of memory that the Java virtual machine will * attempt to use. If there is no inherent limit then the value {@link * java.lang.Long#MAX_VALUE} will be returned. * * @return the maximum amount of memory that the virtual machine will * attempt to use, measured in bytes * @since 1.4 */ publicnativelongmaxMemory();
linux 下 locked-in-memory size 的默认大小通常是 64 K,这对于 io_uring 来说是不够用的。
io_uring accounts memory it needs under the rlimit memlocked option, which can be quite low on some setups (64K). The default is usually enough for most use cases, but bigger rings or things like registered buffers deplete it quickly.