Commit 1fd180ca authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

sockets: don't double buffer size for sockets

SO_SNDBUF and SO_RCVBUF sets a double input value, because
"Linux reserves half of te socket buffer for metadata."

So if a process is suspended/restored many times, a socket buffer
size is doubled on each iteration and in a one moment it is overflowed.
Very likely the program hangs in such situation, because the socket with
negative buffer size is unusable.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 14f98abf
...@@ -315,8 +315,13 @@ int restore_socket_opts(int sk, SkOptsEntry *soe) ...@@ -315,8 +315,13 @@ int restore_socket_opts(int sk, SkOptsEntry *soe)
struct timeval tv; struct timeval tv;
pr_info("%d restore sndbuf %d rcv buf %d\n", sk, soe->so_sndbuf, soe->so_rcvbuf); pr_info("%d restore sndbuf %d rcv buf %d\n", sk, soe->so_sndbuf, soe->so_rcvbuf);
ret |= restore_opt(sk, SOL_SOCKET, SO_SNDBUFFORCE, &soe->so_sndbuf);
ret |= restore_opt(sk, SOL_SOCKET, SO_RCVBUFFORCE, &soe->so_rcvbuf); /* setsockopt() multiplies the input values by 2 */
val = soe->so_sndbuf / 2;
ret |= restore_opt(sk, SOL_SOCKET, SO_SNDBUFFORCE, &val);
val = soe->so_rcvbuf / 2;
ret |= restore_opt(sk, SOL_SOCKET, SO_RCVBUFFORCE, &val);
if (soe->has_so_priority) { if (soe->has_so_priority) {
pr_debug("\trestore priority %d for socket\n", soe->so_priority); pr_debug("\trestore priority %d for socket\n", soe->so_priority);
ret |= restore_opt(sk, SOL_SOCKET, SO_PRIORITY, &soe->so_priority); ret |= restore_opt(sk, SOL_SOCKET, SO_PRIORITY, &soe->so_priority);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment