#17632·netty

io_uring: zero-copy write splits a flush into WRITEV + SEND_ZC across two iterations

Author: franz1981Created Sep 25, 2026Updated Sep 26, 2026

With IO_URING_WRITE_ZERO_COPY_THRESHOLD set, a flush whose first entry is below the threshold and a later entry at or above it is sent as two operations in two event-loop iterations instead of one.

IoUringSocketChannel.scheduleWriteMultiple decides zero-copy from the first flushed entry only (shouldWriteZeroCopy(((ByteBuf) in.current()).readableBytes()), IoUringSocketChannel.java:129-130). For an HTTP/1.1 response that is the ~208-byte header, so it takes the WRITEV path; that path's filterWriteMultiple stops the iovec at the first buffer >= threshold (:193-205), so the WRITEV carries the header alone. When its CQE drains it, numOutstandingWrites reaches 0 and the write is rescheduled (AbstractIoUringChannel.java:1034-1039); now msgCount == 1, scheduleWriteSingle issues SEND_ZC for the body (IoUringSocketChannel.java:98-117). Per response: 2 SQEs across two iterations, 3 CQEs (WRITEV, SEND_ZC with F_MORE, the NOTIF), one retain/release pair, and the body buffer held until the notification. The SENDMSG_ZC gather path (:131-176) is unreachable whenever the first entry is small, which for HTTP/1.1 and HTTP/2 (9-byte frame header first) is always.

Measured on a0c8ddc066, kernel 7.1.13, HttpSnoopServer with a 4 KiB body, 64 connections, 8 loops, buffer ring on, 20 s, one run per cell:

transport req/s
nio 176,761
io_uring, zero-copy off 174,336
io_uring, threshold 4096 126,602

bpftrace on io_uring:io_uring_submit_req over 6 s of the threshold-4096 run: SEND_ZC 750,727, WRITEV 750,731. Same numbers on 035d76e3f4, so this predates the recent io_uring changes.

Part of the loss is expected: the kernel documents MSG_ZEROCOPY as effective only above ~10 KB. The split is not; a 4 KiB body that qualifies for zero-copy should not turn one gathering write into a serialized WRITEV + SEND_ZC. Two possible shapes: gate on the largest entry (or the total flushed bytes) rather than in.current(), and take the SENDMSG_ZC gather so header and body go out in one SQE; or decline zero-copy for a flush whose non-zero-copy prefix is non-empty.

cc @dreamlike-ocean (#15491, #16130) @normanmaurer