From 76d4b180d016d6bab10602e8b47100bc4bc0e6fd Mon Sep 17 00:00:00 2001 From: Ruihan Li Date: Mon, 30 Sep 2024 16:03:46 +0800 Subject: [PATCH] Increase the TCP socket buffer length --- .../libs/aster-bigtcp/src/socket/unbound.rs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/kernel/libs/aster-bigtcp/src/socket/unbound.rs b/kernel/libs/aster-bigtcp/src/socket/unbound.rs index 97de13c6e..b79f60bba 100644 --- a/kernel/libs/aster-bigtcp/src/socket/unbound.rs +++ b/kernel/libs/aster-bigtcp/src/socket/unbound.rs @@ -53,11 +53,23 @@ impl UnboundSocket { } } -// For TCP -pub const TCP_RECV_BUF_LEN: usize = 65536; -pub const TCP_SEND_BUF_LEN: usize = 65536; +// TCP socket buffer sizes: +// +// According to +// +// and +// , +// it seems that the socket buffer should be 256 packets * 256 bytes/packet = 65536 bytes by +// default. However, the loopback MTU is also 65536 bytes, and having the same size for the socket +// buffer and the MTU will cause the implementation of Nagle's algorithm in smoltcp to behave +// abnormally (see ). So the socket buffer size +// is increased from 64K to 128K. +// +// TODO: Consider allowing user programs to set the socket buffer length via `setsockopt` system calls. +pub const TCP_RECV_BUF_LEN: usize = 65536 * 2; +pub const TCP_SEND_BUF_LEN: usize = 65536 * 2; -// For UDP +// UDP socket buffer sizes: pub const UDP_SEND_PAYLOAD_LEN: usize = 65536; pub const UDP_RECV_PAYLOAD_LEN: usize = 65536; const UDP_METADATA_LEN: usize = 256;