Skip to contentSkip to conversation

Per socket value for max datagram queue length

PATCH In review Dan Ballard 4 participants 5 messages Jan 22, 2014

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Per socket value for max datagram queue length

Provides a new option for setsockopt SO_MAX_DGRAM_QLEN that sets and gets a socket specific max datagram queue length. Currently each socket has one but it's only ever initialized from /proc/sys/net/unix/max_dgram_qlen and then never adjustable later. Now each socket can have it individually tweaked during it's life.

---
 include/uapi/asm-generic/socket.h |    2 ++
 net/core/sock.c                   |    7 +++++++
 2 files changed, 9 insertions(+)
include/uapi/asm-generic/socket.h +2 -0
index 38f14d0..f8c3e6b 100644
@@ -80,4 +80,6 @@
 
 #define SO_MAX_PACING_RATE     47
 
+#define SO_MAX_DGRAM_QLEN      48
+
 #endif /* __ASM_GENERIC_SOCKET_H */
net/core/sock.c +7 -0
index 5393b4b..1ff69d1 100644
@@ -915,6 +915,10 @@ set_rcvbuf:
                                         sk->sk_max_pacing_rate);
                break;
 
+       case SO_MAX_DGRAM_QLEN:
+               sk->sk_max_ack_backlog = val;
+               break;
+
        default:
                ret = -ENOPROTOOPT;
                break;
@@ -1182,6 +1186,9 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
                v.val = sk->sk_max_pacing_rate;
                break;
 
+       case SO_MAX_DGRAM_QLEN:
+               v.val = sk->sk_max_ack_backlog;
+               break;
        default:
                return -ENOPROTOOPT;
        }
Signature · 1 line
1.7.10.4
#1 lore raw

net/core/sock.c set_rcvbuf: · line 921

Quoted 12 lines · Dan Ballard
net/core/sock.c +4 -0
index 5393b4b..1ff69d1 100644
@@ -915,6 +915,10 @@ set_rcvbuf:
                                         sk->sk_max_pacing_rate);
                break;
 
+       case SO_MAX_DGRAM_QLEN:
+               sk->sk_max_ack_backlog = val;
+               break;
+

Shouldn't the backlog be capped for unprivileged users to some configurable value? I even think that max_dgram_qlen should be the upper bound.

I guess it is not that serious as socket read accounting does account all packets which sit in the backlog queue.

Greetings,

Hannes

#2 lore raw
Quoted 17 lines · Hannes Frederic Sowa

net/core/sock.c set_rcvbuf: · line 921

Quoted 12 lines · Dan Ballard
net/core/sock.c +4 -0
index 5393b4b..1ff69d1 100644
@@ -915,6 +915,10 @@ set_rcvbuf:
                                         sk->sk_max_pacing_rate);
                break;
 
+       case SO_MAX_DGRAM_QLEN:
+               sk->sk_max_ack_backlog = val;
+               break;
+

Shouldn't the backlog be capped for unprivileged users to some configurable value? I even think that max_dgram_qlen should be the upper bound.

Quoted 2 lines

I guess it is not that serious as socket read accounting does account all packets which sit in the backlog queue.

Just a follow-up:

sk_max_ack_backlog is also responsible for limiting the af_unix dgram queues. Currently there is no socket accounting for the read side of those unix dgram sockets. I tried to fix this once here,
http://patchwork.ozlabs.org/patch/231032/, but until that is done we depend on max_dgram_qlen to limit those queues at all.

I hope I can get back to this patch anytime soon, as it solves the problem that a bidirectional protocol ping-ponging with a dgram server socket and not fetching its messages from the backlog queue can bring a server to halt because it doesn't have any send space on the socket anymore.

Greetings,

Hannes

#3 lore raw
In reply to Dan Ballard
Quoted 6 lines · Dan Ballard

Provides a new option for setsockopt SO_MAX_DGRAM_QLEN that sets and gets a socket specific max datagram queue length. Currently each socket has one but it's only ever initialized from /proc/sys/net/unix/max_dgram_qlen and then never adjustable later. Now each socket can have it individually tweaked during it's life.

Your patch suffers from many problems.

It breaks listen()

It doesn't compile on a lot of arches.

sk_max_ack_backlog is an unsigned short.

max_dgram_qlen is used, but only for Unix sockets at this time Try : "git grep -n max_dgram_qlen" for details

Quoted 44 lines
---
  include/uapi/asm-generic/socket.h |    2 ++
  net/core/sock.c                   |    7 +++++++
  2 files changed, 9 insertions(+)
include/uapi/asm-generic/socket.h +2 -0
index 38f14d0..f8c3e6b 100644
@@ -80,4 +80,6 @@
 
  #define SO_MAX_PACING_RATE     47
 
+#define SO_MAX_DGRAM_QLEN      48
+
  #endif /* __ASM_GENERIC_SOCKET_H */
net/core/sock.c +7 -0
index 5393b4b..1ff69d1 100644
@@ -915,6 +915,10 @@ set_rcvbuf:
                                          sk->sk_max_pacing_rate);
                 break;
 
+       case SO_MAX_DGRAM_QLEN:
+               sk->sk_max_ack_backlog = val;
+               break;
+
         default:
                 ret = -ENOPROTOOPT;
                 break;
@@ -1182,6 +1186,9 @@ int sock_getsockopt(struct socket *sock, int 
 level, int optname,
                 v.val = sk->sk_max_pacing_rate;
                 break;
 
+       case SO_MAX_DGRAM_QLEN:
+               v.val = sk->sk_max_ack_backlog;
+               break;
         default:
                 return -ENOPROTOOPT;
         }
#4 lore raw
In reply to Dan Ballard
Quoted 17 lines · Dan Ballard

Provides a new option for setsockopt SO_MAX_DGRAM_QLEN that sets and gets a socket specific max datagram queue length. Currently each socket has one but it's only ever initialized from /proc/sys/net/unix/max_dgram_qlen and then never adjustable later. Now each socket can have it individually tweaked during it's life.

---
  include/uapi/asm-generic/socket.h |    2 ++
  net/core/sock.c                   |    7 +++++++
  2 files changed, 9 insertions(+)
include/uapi/asm-generic/socket.h +0 -0
index 38f14d0..f8c3e6b 100644

include/uapi/asm-generic/socket.h line 84

Quoted 5 lines
include/uapi/asm-generic/socket.h +2 -0
@@ -80,4 +80,6 @@
 
  #define SO_MAX_PACING_RATE     47
 
+#define SO_MAX_DGRAM_QLEN      48
+

This needs to be added in more than just asm-generic, e.g. have a look at SO_MAX_PACING_RATE or SO_BPF_EXTENSIONS.

Also you might need to rebase to current net-next head and maybe describe use cases more in-depth; next to what Hannes just commented.

Quoted 26 lines
include/uapi/asm-generic/socket.h +0 -0
  #endif /* __ASM_GENERIC_SOCKET_H */
net/core/sock.c +7 -0
index 5393b4b..1ff69d1 100644
@@ -915,6 +915,10 @@ set_rcvbuf:
                                          sk->sk_max_pacing_rate);
                 break;
 
+       case SO_MAX_DGRAM_QLEN:
+               sk->sk_max_ack_backlog = val;
+               break;
+
         default:
                 ret = -ENOPROTOOPT;
                 break;
@@ -1182,6 +1186,9 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
                 v.val = sk->sk_max_pacing_rate;
                 break;
 
+       case SO_MAX_DGRAM_QLEN:
+               v.val = sk->sk_max_ack_backlog;
+               break;
         default:
                 return -ENOPROTOOPT;
         }