Package io.netty.channel.uring
Class IoUringBufferRing
- java.lang.Object
-
- io.netty.channel.uring.IoUringBufferRing
-
final class IoUringBufferRing extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classIoUringBufferRing.RingConsumer
-
Field Summary
Fields Modifier and Type Field Description private intallocatedBuffersprivate IoUringBufferRingAllocatorallocatorprivate booleanbatchAllocationprivate intbatchSizeprivate shortbufferGroupIdprivate ByteBuf[]buffersprivate booleanclosedprivate booleancorruptedprivate shortentriesprivate IoUringBufferRingExhaustedEventexhaustedEventprivate booleanincrementalprivate java.nio.ByteBufferioUringBufRingprivate shortlastGeneratedBidprivate shortmaskprivate booleanneedExpandprivate IoUringBufferRing.RingConsumerringConsumerprivate intringFdprivate static VarHandleSHORT_HANDLEprivate inttailFieldPositionprivate intusableBuffers
-
Constructor Summary
Constructors Constructor Description IoUringBufferRing(int ringFd, java.nio.ByteBuffer ioUringBufRing, short entries, int batchSize, short bufferGroupId, boolean incremental, IoUringBufferRingAllocator allocator, boolean batchAllocation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) intallocatedBuffers()The number of buffers that are currently allocated (and so posted) in this buffer ring.(package private) intattemptedBytesRead(short bid)Return the amount of bytes that we attempted to read for the given id.(package private) shortbufferGroupId()The group id that is assigned to this buffer ring.private intcalculateNextBufferBatch()(package private) voidclose()Close thisIoUringBufferRing, using it after this method is called will lead to undefined behaviour.(package private) booleanexpand()Try to expand by adding more buffers to the ring if there is any space left, this will be done lazy.private voidfill(short bid)private voidfill(short startBid, int buffers)(package private) IoUringBufferRingExhaustedEventgetExhaustedEvent()(package private) voidinitialize()(package private) booleanisUsable()(package private) shortnextBid(short bid, int allocatedBuffers)Return the next buffer id that followsbidin ring order, wrapping around afterallocatedBuffersids.(package private) ByteBufuseBuffer(short bid, int read, boolean more)Use the buffer for the given buffer id.
-
-
-
Field Detail
-
SHORT_HANDLE
private static final VarHandle SHORT_HANDLE
-
ioUringBufRing
private final java.nio.ByteBuffer ioUringBufRing
-
tailFieldPosition
private final int tailFieldPosition
-
entries
private final short entries
-
mask
private final short mask
-
bufferGroupId
private final short bufferGroupId
-
ringFd
private final int ringFd
-
buffers
private final ByteBuf[] buffers
-
allocator
private final IoUringBufferRingAllocator allocator
-
batchAllocation
private final boolean batchAllocation
-
exhaustedEvent
private final IoUringBufferRingExhaustedEvent exhaustedEvent
-
ringConsumer
private final IoUringBufferRing.RingConsumer ringConsumer
-
incremental
private final boolean incremental
-
batchSize
private final int batchSize
-
corrupted
private boolean corrupted
-
closed
private boolean closed
-
usableBuffers
private int usableBuffers
-
allocatedBuffers
private int allocatedBuffers
-
needExpand
private boolean needExpand
-
lastGeneratedBid
private short lastGeneratedBid
-
-
Constructor Detail
-
IoUringBufferRing
IoUringBufferRing(int ringFd, java.nio.ByteBuffer ioUringBufRing, short entries, int batchSize, short bufferGroupId, boolean incremental, IoUringBufferRingAllocator allocator, boolean batchAllocation)
-
-
Method Detail
-
isUsable
boolean isUsable()
-
initialize
void initialize()
-
expand
boolean expand()
Try to expand by adding more buffers to the ring if there is any space left, this will be done lazy.- Returns:
trueif we can expand the number of buffers in the ring,falseotherwise.
-
fill
private void fill(short startBid, int buffers)
-
fill
private void fill(short bid)
-
getExhaustedEvent
IoUringBufferRingExhaustedEvent getExhaustedEvent()
- Returns:
- the
IoUringBufferRingExhaustedEventthat should be used to signal that there were no buffers left for this buffer ring.
-
attemptedBytesRead
int attemptedBytesRead(short bid)
Return the amount of bytes that we attempted to read for the given id. This method must be called beforeuseBuffer(short, int, boolean).- Parameters:
bid- the id of the buffer.- Returns:
- the attempted bytes.
-
calculateNextBufferBatch
private int calculateNextBufferBatch()
-
useBuffer
ByteBuf useBuffer(short bid, int read, boolean more)
Use the buffer for the given buffer id. The returnedByteBufmust be released once not used anymore.- Parameters:
bid- the id of the bufferread- the number of bytes that could be read. This value might be larger then what a singleByteBufcan hold. Because of this, the caller should call
-
allocatedBuffers
int allocatedBuffers()
The number of buffers that are currently allocated (and so posted) in this buffer ring. This value can change every timeuseBuffer(short, int, boolean)is called as it might grow the ring. Because of this, callers that need to walk a sequence of consecutive buffer ids that belong to the same completion (for example aIORING_RECVSEND_BUNDLEcompletion) must capture this value before callinguseBuffer(short, int, boolean)and pass it tonextBid(short, int)afterwards, so the wrap-around is computed using the size of the ring as the kernel observed it when it produced the bundle, not the (possibly already grown) size afterwards.- Returns:
- the number of allocated buffers.
-
nextBid
short nextBid(short bid, int allocatedBuffers)Return the next buffer id that followsbidin ring order, wrapping around afterallocatedBuffersids.- Parameters:
bid- the current buffer id.allocatedBuffers- the number of allocated buffers to use for the wrap-around computation. This should be a value obtained fromallocatedBuffers()before the correspondinguseBuffer(short, int, boolean)call forbid, as that call might have grown the ring already.- Returns:
- the next buffer id.
-
bufferGroupId
short bufferGroupId()
The group id that is assigned to this buffer ring.- Returns:
- group id.
-
close
void close()
Close thisIoUringBufferRing, using it after this method is called will lead to undefined behaviour.
-
-