tx_queue 和 rx_queue 的单位 /proc/net/tcp

Units of tx_queue & rx_queue in /proc/net/tcp

在 Linux 2.6.32 上,我正在查看 /proc/net/tcp 并想知道 tx_queuerx_queue 的单位是什么。

我在 https://www.kernel.org/doc/Documentation/networking/proc_net_tcp.txt

中找不到关于 receive-queuetransmit-queue 的信息

Nor in man 5 proc 仅显示:

The "tx_queue" and "rx_queue" are the outgoing and incoming data queue in terms of kernel memory usage.

是字节吗?或缓冲区数量?或许我错过了关于此的精彩文档?

谢谢

简答 - 这些计数字节。通过 运行 netperf TCP_RR 使用不同的大小,您可以看到 1 计数的确切值(在给定时间内只有 1 个数据包在空中)。该值将始终显示数据包大小。

更多信息:

根据这个post:

tx_queue:rx_queue

The size of the transmit and receive queues.

这是每个插槽。对于 TCP,值在 get_tcp4_sock() 函数中更新。 2.6.32和4.14有点不同,但是思路是一样的。根据套接字状态,rx_queue 值更新为 sk->sk_ack_backlog 或 tp->rcv_nxt - tp->copied_seq。第二个值可能为负,如果是,则在以后的内核中固定为 0。 sk_ack_backlog 计算未确认的段,这有点奇怪,因为这似乎不是以字节为单位。可能这里遗漏了什么。

来自tcp.h:

struct tcp_sock {
    ...
    u32 rcv_nxt;    /* What we want to receive next     */
    u32 copied_seq; /* Head of yet unread data      */

两者都以字节计数,因此 tp->rcv_nxt - tp->copied_seq 正在计算传入数据包接收缓冲区中的待处理字节数。 tx_queue 设置为 tp->write_seq - tp->snd_una。再次来自 tcp.h:

struct tcp_sock {
...
    u32 snd_una;    /* First byte we want an ack for    */
    u32 write_seq;  /* Tail(+1) of data held in tcp send buffer */

这里更清楚的看到计数是以字节为单位的。 对于 UDP,它更简单。值在 udp4_format_sock():

中更新
static void udp4_format_sock(struct sock *sp, struct seq_file *f,
        int bucket)
{
    ...

    seq_printf(f, "%5d: %08X:%04X %08X:%04X"
        " %02X %08X:%08X %02X:%08lX %08X %5u %8d %lu %d %pK %d",
        bucket, src, srcp, dest, destp, sp->sk_state,
        sk_wmem_alloc_get(sp),
        sk_rmem_alloc_get(sp),

sk_wmem_alloca_get和sk_rmem_alloc_getreturn分别是sk_wmem_alloc和sk_rmem_alloc,都是字节。

希望对您有所帮助。