Repository navigation
TUN inbound: Read large TCP segments straight into Xray-core's buffers on Linux - #7179
Conversation
|
@Fangliding 你来给他解释吧, |
|
啥东西 |
|
@Fangliding added a commit: with offload the read loop acked about every second segment, and each ack written to the tun also makes the kernel send what it frees. now it acks at a quarter of the window, and against main one upload stream is +18% and eight +21%, with 14-18% less CPU per GB |
|
@4RH1T3CT0R7 我的意思是能不能比如说先用一两块 buf 接收 TCP/IP header,然后直接用 Xray buf 接收 TCP payload |
|
@RPRX it reads close to that now: readv puts the virtio_net_hdr in a small array of its own and the packet in eight xray buffers, the ip and tcp headers at the start of the first. a segment that stays is not copied, the first buffer just starts after the headers and the others are taken as they are, so the payload is in xray buffers after one readv for up to 64 KiB. a buffer of their own for the ip and tcp headers would need their size before the read, and it is 20 or 40 and more for ip and 20 to 60 for tcp. copied are only segments under 4 KiB, onto the end of the buffer before them, and those out of order |
|
|
On a link that takes large segments (XTLS#7179), a large in-order TCP payload stays in the buffers the stack read it into and is queued without a copy. A segment put together from IP fragments, or joined to verify its checksum, is in a buffer of its own; keeping it queued the buffer of the last fragment instead, so the connection read other bytes than were sent while rcvNxt moved past them. Such a segment is now copied. Found by Greptile on #59.
As RPRX asked in #7130 and #7156. on linux the tun is opened with offload, so one read gives up to 64 KiB of one TCP stream. that is now read with readv into eight 8 KiB buffers of xray, and a segment of 4 KiB or more that comes in order stays in them and goes on with the headers trimmed, nothing copied. smaller and out of order segments, UDP and ICMP are copied as before. the second commit is about acks: with offload a connection has a 1 MiB window, but the read loop still acked every 64 KiB that the reader had not taken, about every second segment, and each ack written to the tun also makes the kernel send what it frees. now that waits for a quarter of the window, also for WireGuard and MASQUE, which have the same window
on a veth pair with 1500 MTU, 15 samples each, main vs this: one upload stream 3730 to 4385 MB/s (+18%), eight 3374 to 4080 (+21%), CPU of xray per GB of upload 14% and 18% lower, acks 9.3 to 4.6 per MB. downloads are the same, and so are links of 100 Mbit/s with 50 ms and of 50 Mbit/s with 1% loss