sctp: implement automatic buffer tuning
Subsystems (2)
PATCH 1/1 sctp: implement automatic buffer tuning
The purpose of this patch is to keep the send and receive buffers closer to their optimal values, without having to allocate large buffers for all sockets. Connections with large bandwidth delay products are given larger buffers, while connections with small bandwidth delay products get buffers at or close to the default values.
sk_sndbuf is maintained at twice the size of the largest congestion window for the socket. The value is never decreased automatically.
We continually monitor the amount of data delivered to user space over the course of one RTT for each socket. sk_rcvbuf is maintained at twice this amount. The value is never decreased automatically.
--- include/net/sctp/sctp.h | 4 ++ include/net/sctp/structs.h | 15 +++++++ net/sctp/associola.c | 11 ++++- net/sctp/protocol.c | 4 +- net/sctp/sm_make_chunk.c | 2 +- net/sctp/socket.c | 92 +++++++++++++++++++++++++++++++++++++++++++- net/sctp/transport.c | 4 +- net/sctp/ulpevent.c | 5 +- 8 files changed, 127 insertions(+), 10 deletions(-)
include/net/sctp/sctp.h +4 -0
@@ -128,6 +128,10 @@ extern int sctp_register_pf(struct sctp_pf *, sa_family_t);int sctp_backlog_rcv (struct sock *sk,struct sk_buff *skb);int sctp_inet_listen (struct socket *sock,int backlog);void sctp_write_space (struct sock *sk); +int sctp_raise_sndbuf (struct sctp_transport *transport); +int sctp_raise_rcvbuf (struct sctp_association *asoc,int rcvmem); +unsigned int sctp_rcvbuf_adjust (struct sctp_association *asoc, +unsigned int len);void sctp_data_ready (struct sock *sk,int len);unsigned int sctp_poll (struct file *file,struct socket *sock,poll_table *wait);
include/net/sctp/structs.h +15 -0
@@ -272,6 +272,10 @@ extern struct sctp_globals {#define sctp_checksum_disable (sctp_globals.checksum_disable)#define sctp_rwnd_upd_shift (sctp_globals.rwnd_update_shift) +extern long sysctl_sctp_mem[3 ]; +extern int sysctl_sctp_rmem[3 ]; +extern int sysctl_sctp_wmem[3 ]; +/* SCTP Socket type: UDP or TCP style. */ typedef enum { SCTP_SOCKET_UDP = 0,
@@ -1752,6 +1756,17 @@ struct sctp_association {*/ __u32 rwnd_press; +/* Timer used for calculating the appropriate receive buffer space. */ +struct { +/* The starting time of the current measurement period. */ +unsigned long start_time; + +/* The number of bytes delivered to user space in the current +* measurement period. +*/ +int delivered; + } rcvq_space; +/* This is the sndbuf size in use for the association. * This corresponds to the sndbuf size for the association, * as specified in the sk->sndbuf.
net/sctp/associola.c +9 -2
@@ -1462,7 +1462,9 @@ void sctp_assoc_rwnd_increase(struct sctp_association *asoc, unsigned len)/* Decrease asoc's rwnd by len. */ void sctp_assoc_rwnd_decrease (struct sctp_association *asoc,unsigned len) { +struct sock *sk = asoc->base.sk;int rx_count; +int rcvmem;int over =0 ;SCTP_ASSERT (asoc->rwnd,"rwnd zero" , return);
@@ -1471,14 +1473,19 @@ void sctp_assoc_rwnd_decrease(struct sctp_association *asoc, unsigned len)if (asoc->ep->rcvbuf_policy) rx_count =atomic_read (&asoc->rmem_alloc);else - rx_count =atomic_read (&asoc->base.sk->sk_rmem_alloc); + rx_count =atomic_read (&sk->sk_rmem_alloc); + +if (rx_count >= sk->sk_rcvbuf) { + rcvmem =min_t (int, rx_count + len, sysctl_sctp_rmem[2 ]); +sctp_raise_rcvbuf (asoc, rcvmem); + }/* If we've reached or overflowed our receive buffer, announce * a 0 rwnd if rwnd would still be positive. Store the * the pottential pressure overflow so that the window can be restored * back to original value. */ -if (rx_count >= asoc->base.sk->sk_rcvbuf) +if (rx_count >= sk->sk_rcvbuf) over =1 ;if (asoc->rwnd >= len) {
net/sctp/protocol.c +2 -2
@@ -1184,8 +1184,8 @@ SCTP_STATIC __init int sctp_init(void) sysctl_sctp_rmem[2 ] =max (sysctl_sctp_rmem[1 ], max_share); sysctl_sctp_wmem[0 ] =SK_MEM_QUANTUM ; - sysctl_sctp_wmem[1 ] =16 *1024 ; - sysctl_sctp_wmem[2 ] =max (64 *1024 , max_share); + sysctl_sctp_wmem[1 ] =120 *1024 ; + sysctl_sctp_wmem[2 ] =max (sysctl_sctp_wmem[1 ], max_share);/* Size and allocate the association hash table. * The methodology is similar to that of the tcp hash tables.
net/sctp/sm_make_chunk.c +1 -1
@@ -2352,7 +2352,7 @@ int sctp_process_init(struct sctp_association *asoc, sctp_cid_t cid,*/ list_for_each_entry (transport, &asoc->peer.transport_addr_list, transports) { - transport->ssthresh = asoc->peer.i.a_rwnd; + transport->ssthresh = sysctl_sctp_wmem[2 ] /2 ; }/* Set up the TSN tracking pieces. */
net/sctp/socket.c +90 -2
116 lines not on this page · raw message
net/sctp/transport.c +3 -1
@@ -466,6 +466,8 @@ void sctp_transport_raise_cwnd(struct sctp_transport *transport, transport->cwnd = cwnd; transport->partial_bytes_acked = pba; + +sctp_raise_sndbuf (transport); }/* This routine is used to lower the transport's cwnd when congestion is
@@ -621,7 +623,7 @@ void sctp_transport_reset(struct sctp_transport *t)*/ t->cwnd =min (4 *asoc->pathmtu,max_t (__u32,2 *asoc->pathmtu,4380 )); t->burst_limited =0 ; - t->ssthresh = asoc->peer.i.a_rwnd; + t->ssthresh = sysctl_sctp_wmem[2 ] /2 ; t->rto = asoc->rto_initial; t->rtt =0 ; t->srtt =0 ;
net/sctp/ulpevent.c +3 -2
@@ -987,7 +987,7 @@ static void sctp_ulpevent_receive_data(struct sctp_ulpevent *event,static void sctp_ulpevent_release_data (struct sctp_ulpevent *event) {struct sk_buff *skb, *frag; -unsigned int len; +unsigned int len, rcvbuf_increment;/* Current stack structures assume that the rcv buffer is * per socket. For UDP style sockets this is not true as
@@ -1012,7 +1012,8 @@ static void sctp_ulpevent_release_data(struct sctp_ulpevent *event) } done: -sctp_assoc_rwnd_increase (event->asoc, len); + rcvbuf_increment =sctp_rcvbuf_adjust (event->asoc, len); +sctp_assoc_rwnd_increase (event->asoc, len + rcvbuf_increment);sctp_ulpevent_release_owner (event); }