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;