From a9d361b4be7d6329bedd7b37d454c1abf4f27233 Mon Sep 17 00:00:00 2001 From: Lukas Larsson Date: Thu, 21 Jun 2018 11:00:25 +0200 Subject: erts: Limit the automatic max buffer for UDP to 2^16 There is no reason to have a larger buffer than this as the recvmsg call will never return more data. OTP-15206 --- lib/kernel/doc/src/inet.xml | 19 ++++++++++--------- lib/kernel/test/gen_udp_SUITE.erl | 12 ++++++++++-- 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index e6a7962c5a..f281d61459 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -734,22 +734,23 @@ get_tcpi_sacked(Sock) -> {buffer, Size} -

The size of the user-level software buffer used by - the driver. - Not to be confused with options sndbuf +

The size of the user-level buffer used by + the driver. Not to be confused with options sndbuf and recbuf, which correspond to the - Kernel socket buffers. It is recommended - to have val(buffer) >= max(val(sndbuf),val(recbuf)) to + Kernel socket buffers. For TCP it is recommended + to have val(buffer) >= val(recbuf) to avoid performance issues because of unnecessary copying. + For UDP the same recommendation applies, but the max should + not be larger than the MTU of the network path. val(buffer) is automatically set to the above - maximum when values sndbuf or recbuf are set. - However, as the sizes set for sndbuf and recbuf + maximum when recbuf is set. + However, as the size set for recbuf usually become larger, you are encouraged to use getopts/2 to analyze the behavior of your operating system.

Note that this is also the maximum amount of data that can be - received from a single recv call. If you are using higher than - normal MTU consider setting buffer higher.

+ received from a single recv call. If you are using higher than + normal MTU consider setting buffer higher.

{delay_send, Boolean} diff --git a/lib/kernel/test/gen_udp_SUITE.erl b/lib/kernel/test/gen_udp_SUITE.erl index b39399b18a..3acfff929e 100644 --- a/lib/kernel/test/gen_udp_SUITE.erl +++ b/lib/kernel/test/gen_udp_SUITE.erl @@ -34,7 +34,7 @@ -export([init_per_testcase/2, end_per_testcase/2]). -export([send_to_closed/1, active_n/1, - buffer_size/1, binary_passive_recv/1, bad_address/1, + buffer_size/1, binary_passive_recv/1, max_buffer_size/1, bad_address/1, read_packets/1, open_fd/1, connect/1, implicit_inet6/1, local_basic/1, local_unbound/1, local_fdopen/1, local_fdopen_unbound/1, local_abstract/1]). @@ -44,7 +44,7 @@ suite() -> {timetrap,{minutes,1}}]. all() -> - [send_to_closed, buffer_size, binary_passive_recv, + [send_to_closed, buffer_size, binary_passive_recv, max_buffer_size, bad_address, read_packets, open_fd, connect, implicit_inet6, active_n, {group, local}]. @@ -237,6 +237,14 @@ buffer_size_server_recv(Socket, IP, Port, Cnt) -> end. +%%------------------------------------------------------------- +%% OTP-15206: Keep buffer small for udp +%%------------------------------------------------------------- +max_buffer_size(Config) when is_list(Config) -> + {ok, Socket} = gen_udp:open(0, [binary]), + ok = inet:setopts(Socket,[{recbuf, 1 bsl 20}]), + {ok, [{buffer, 65536}]} = inet:getopts(Socket,[buffer]), + gen_udp:close(Socket). %%------------------------------------------------------------- %% OTP-3823 gen_udp:recv does not return address in binary mode -- cgit v1.2.3