2005-08-10 03:10:42 +00:00
|
|
|
/*
|
|
|
|
* NET Generic infrastructure for INET connection oriented protocols.
|
|
|
|
*
|
|
|
|
* Definitions for inet_connection_sock
|
|
|
|
*
|
|
|
|
* Authors: Many people, see the TCP sources
|
|
|
|
*
|
|
|
|
* From code originally in TCP
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
#ifndef _INET_CONNECTION_SOCK_H
|
|
|
|
#define _INET_CONNECTION_SOCK_H
|
|
|
|
|
2005-12-14 07:15:52 +00:00
|
|
|
#include <linux/compiler.h>
|
2005-08-10 03:11:08 +00:00
|
|
|
#include <linux/string.h>
|
2005-08-10 03:10:42 +00:00
|
|
|
#include <linux/timer.h>
|
2006-10-19 21:23:57 +00:00
|
|
|
#include <linux/poll.h>
|
2005-12-27 04:43:12 +00:00
|
|
|
|
|
|
|
#include <net/inet_sock.h>
|
2005-08-10 03:10:42 +00:00
|
|
|
#include <net/request_sock.h>
|
|
|
|
|
2005-08-10 03:11:08 +00:00
|
|
|
#define INET_CSK_DEBUG 1
|
|
|
|
|
|
|
|
/* Cancel timers, when they are not required. */
|
|
|
|
#undef INET_CSK_CLEAR_TIMERS
|
|
|
|
|
2005-08-10 03:10:42 +00:00
|
|
|
struct inet_bind_bucket;
|
2005-08-10 07:03:31 +00:00
|
|
|
struct tcp_congestion_ops;
|
2005-08-10 03:10:42 +00:00
|
|
|
|
2005-12-14 07:15:52 +00:00
|
|
|
/*
|
|
|
|
* Pointers to address related TCP functions
|
|
|
|
* (i.e. things that depend on the address family)
|
|
|
|
*/
|
|
|
|
struct inet_connection_sock_af_ops {
|
2014-04-15 16:58:34 +00:00
|
|
|
int (*queue_xmit)(struct sock *sk, struct sk_buff *skb, struct flowi *fl);
|
2010-04-11 02:15:55 +00:00
|
|
|
void (*send_check)(struct sock *sk, struct sk_buff *skb);
|
2005-12-14 07:15:52 +00:00
|
|
|
int (*rebuild_header)(struct sock *sk);
|
2012-08-06 05:09:33 +00:00
|
|
|
void (*sk_rx_dst_set)(struct sock *sk, const struct sk_buff *skb);
|
2005-12-14 07:15:52 +00:00
|
|
|
int (*conn_request)(struct sock *sk, struct sk_buff *skb);
|
2015-09-29 14:42:48 +00:00
|
|
|
struct sock *(*syn_recv_sock)(const struct sock *sk, struct sk_buff *skb,
|
2005-12-14 07:15:52 +00:00
|
|
|
struct request_sock *req,
|
2015-10-22 15:20:46 +00:00
|
|
|
struct dst_entry *dst,
|
|
|
|
struct request_sock *req_unhash,
|
|
|
|
bool *own_req);
|
[INET_CONNECTION_SOCK]: Pack struct inet_connection_sock_af_ops
We have a hole in:
[acme@newtoy net-2.6.20]$ pahole net/ipv6/tcp_ipv6.o inet_connection_sock_af_ops
/* /pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/inet_connection_sock.h:38 */
struct inet_connection_sock_af_ops {
int (*queue_xmit)(); /* 0 4 */
void (*send_check)(); /* 4 4 */
int (*rebuild_header)(); /* 8 4 */
int (*conn_request)(); /* 12 4 */
struct sock * (*syn_recv_sock)(); /* 16 4 */
int (*remember_stamp)(); /* 20 4 */
__u16 net_header_len; /* 24 2 */
/* XXX 2 bytes hole, try to pack */
int (*setsockopt)(); /* 28 4 */
int (*getsockopt)(); /* 32 4 */
int (*compat_setsockopt)(); /* 36 4 */
int (*compat_getsockopt)(); /* 40 4 */
void (*addr2sockaddr)(); /* 44 4 */
int sockaddr_len; /* 48 4 */
}; /* size: 52, sum members: 50, holes: 1, sum holes: 2 */
But we don't need sockaddr_len to be an int:
[acme@newtoy net-2.6.20]$ find net -name "*.[ch]" | xargs grep '\.sockaddr_len.\+=' | sort -u
net/dccp/ipv4.c: .sockaddr_len = sizeof(struct sockaddr_in),
net/dccp/ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/ipv4/tcp_ipv4.c: .sockaddr_len = sizeof(struct sockaddr_in),
net/ipv6/tcp_ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/sctp/ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/sctp/protocol.c: .sockaddr_len = sizeof(struct sockaddr_in),
[acme@newtoy net-2.6.20]$ pahole --sizes net/ipv6/tcp_ipv6.o | grep sockaddr_in
struct sockaddr_in: 16 0
struct sockaddr_in6: 28 0
[acme@newtoy net-2.6.20]$
So I turned sockaddr_len a 'u16', and now:
[acme@newtoy net-2.6.20]$ pahole net/ipv6/tcp_ipv6.o inet_connection_sock_af_ops
/* /pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/inet_connection_sock.h:38 */
struct inet_connection_sock_af_ops {
int (*queue_xmit)(); /* 0 4 */
void (*send_check)(); /* 4 4 */
int (*rebuild_header)(); /* 8 4 */
int (*conn_request)(); /* 12 4 */
struct sock * (*syn_recv_sock)(); /* 16 4 */
int (*remember_stamp)(); /* 20 4 */
u16 net_header_len; /* 24 2 */
u16 sockaddr_len; /* 26 2 */
int (*setsockopt)(); /* 28 4 */
int (*getsockopt)(); /* 32 4 */
int (*compat_setsockopt)(); /* 36 4 */
int (*compat_getsockopt)(); /* 40 4 */
void (*addr2sockaddr)(); /* 44 4 */
}; /* size: 48 */
So we've saved 4 bytes:
[acme@newtoy net-2.6.20]$ codiff -sV /tmp/tcp_ipv6.o.before net/ipv6/tcp_ipv6.o
/pub/scm/linux/kernel/git/acme/net-2.6.20/net/ipv6/tcp_ipv6.c:
struct inet_connection_sock_af_ops | -4
net_header_len;
from: __u16 /* 24(0) 2(0) */
to: u16 /* 24(0) 2(0) */
sockaddr_len;
from: int /* 48(0) 4(0) */
to: u16 /* 26(0) 2(0) */
1 struct changed
[acme@newtoy net-2.6.20]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-27 19:56:43 +00:00
|
|
|
u16 net_header_len;
|
ipv6: RTAX_FEATURE_ALLFRAG causes inefficient TCP segment sizing
Quoting Tore Anderson from :
https://bugzilla.kernel.org/show_bug.cgi?id=42572
When RTAX_FEATURE_ALLFRAG is set on a route, the effective TCP segment
size does not take into account the size of the IPv6 Fragmentation
header that needs to be included in outbound packets, causing every
transmitted TCP segment to be fragmented across two IPv6 packets, the
latter of which will only contain 8 bytes of actual payload.
RTAX_FEATURE_ALLFRAG is typically set on a route in response to
receving a ICMPv6 Packet Too Big message indicating a Path MTU of less
than 1280 bytes. 1280 bytes is the minimum IPv6 MTU, however ICMPv6
PTBs with MTU < 1280 are still valid, in particular when an IPv6
packet is sent to an IPv4 destination through a stateless translator.
Any ICMPv4 Need To Fragment packets originated from the IPv4 part of
the path will be translated to ICMPv6 PTB which may then indicate an
MTU of less than 1280.
The Linux kernel refuses to reduce the effective MTU to anything below
1280 bytes, instead it sets it to exactly 1280 bytes, and
RTAX_FEATURE_ALLFRAG is also set. However, the TCP segment size appears
to be set to 1240 bytes (1280 Path MTU - 40 bytes of IPv6 header),
instead of 1232 (additionally taking into account the 8 bytes required
by the IPv6 Fragmentation extension header).
This in turn results in rather inefficient transmission, as every
transmitted TCP segment now is split in two fragments containing
1232+8 bytes of payload.
After this patch, all the outgoing packets that includes a
Fragmentation header all are "atomic" or "non-fragmented" fragments,
i.e., they both have Offset=0 and More Fragments=0.
With help from David S. Miller
Reported-by: Tore Anderson <tore@fud.no>
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Maciej Żenczykowski <maze@google.com>
Cc: Tom Herbert <therbert@google.com>
Tested-by: Tore Anderson <tore@fud.no>
Signed-off-by: David S. Miller <davem@davemloft.net>
2012-04-24 07:37:38 +00:00
|
|
|
u16 net_frag_header_len;
|
[INET_CONNECTION_SOCK]: Pack struct inet_connection_sock_af_ops
We have a hole in:
[acme@newtoy net-2.6.20]$ pahole net/ipv6/tcp_ipv6.o inet_connection_sock_af_ops
/* /pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/inet_connection_sock.h:38 */
struct inet_connection_sock_af_ops {
int (*queue_xmit)(); /* 0 4 */
void (*send_check)(); /* 4 4 */
int (*rebuild_header)(); /* 8 4 */
int (*conn_request)(); /* 12 4 */
struct sock * (*syn_recv_sock)(); /* 16 4 */
int (*remember_stamp)(); /* 20 4 */
__u16 net_header_len; /* 24 2 */
/* XXX 2 bytes hole, try to pack */
int (*setsockopt)(); /* 28 4 */
int (*getsockopt)(); /* 32 4 */
int (*compat_setsockopt)(); /* 36 4 */
int (*compat_getsockopt)(); /* 40 4 */
void (*addr2sockaddr)(); /* 44 4 */
int sockaddr_len; /* 48 4 */
}; /* size: 52, sum members: 50, holes: 1, sum holes: 2 */
But we don't need sockaddr_len to be an int:
[acme@newtoy net-2.6.20]$ find net -name "*.[ch]" | xargs grep '\.sockaddr_len.\+=' | sort -u
net/dccp/ipv4.c: .sockaddr_len = sizeof(struct sockaddr_in),
net/dccp/ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/ipv4/tcp_ipv4.c: .sockaddr_len = sizeof(struct sockaddr_in),
net/ipv6/tcp_ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/sctp/ipv6.c: .sockaddr_len = sizeof(struct sockaddr_in6),
net/sctp/protocol.c: .sockaddr_len = sizeof(struct sockaddr_in),
[acme@newtoy net-2.6.20]$ pahole --sizes net/ipv6/tcp_ipv6.o | grep sockaddr_in
struct sockaddr_in: 16 0
struct sockaddr_in6: 28 0
[acme@newtoy net-2.6.20]$
So I turned sockaddr_len a 'u16', and now:
[acme@newtoy net-2.6.20]$ pahole net/ipv6/tcp_ipv6.o inet_connection_sock_af_ops
/* /pub/scm/linux/kernel/git/acme/net-2.6.20/include/net/inet_connection_sock.h:38 */
struct inet_connection_sock_af_ops {
int (*queue_xmit)(); /* 0 4 */
void (*send_check)(); /* 4 4 */
int (*rebuild_header)(); /* 8 4 */
int (*conn_request)(); /* 12 4 */
struct sock * (*syn_recv_sock)(); /* 16 4 */
int (*remember_stamp)(); /* 20 4 */
u16 net_header_len; /* 24 2 */
u16 sockaddr_len; /* 26 2 */
int (*setsockopt)(); /* 28 4 */
int (*getsockopt)(); /* 32 4 */
int (*compat_setsockopt)(); /* 36 4 */
int (*compat_getsockopt)(); /* 40 4 */
void (*addr2sockaddr)(); /* 44 4 */
}; /* size: 48 */
So we've saved 4 bytes:
[acme@newtoy net-2.6.20]$ codiff -sV /tmp/tcp_ipv6.o.before net/ipv6/tcp_ipv6.o
/pub/scm/linux/kernel/git/acme/net-2.6.20/net/ipv6/tcp_ipv6.c:
struct inet_connection_sock_af_ops | -4
net_header_len;
from: __u16 /* 24(0) 2(0) */
to: u16 /* 24(0) 2(0) */
sockaddr_len;
from: int /* 48(0) 4(0) */
to: u16 /* 26(0) 2(0) */
1 struct changed
[acme@newtoy net-2.6.20]$
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
2006-11-27 19:56:43 +00:00
|
|
|
u16 sockaddr_len;
|
2005-12-14 07:15:52 +00:00
|
|
|
int (*setsockopt)(struct sock *sk, int level, int optname,
|
2009-09-30 23:12:20 +00:00
|
|
|
char __user *optval, unsigned int optlen);
|
2005-12-14 07:15:52 +00:00
|
|
|
int (*getsockopt)(struct sock *sk, int level, int optname,
|
|
|
|
char __user *optval, int __user *optlen);
|
2008-08-28 09:53:51 +00:00
|
|
|
#ifdef CONFIG_COMPAT
|
2006-03-21 06:45:21 +00:00
|
|
|
int (*compat_setsockopt)(struct sock *sk,
|
|
|
|
int level, int optname,
|
2009-09-30 23:12:20 +00:00
|
|
|
char __user *optval, unsigned int optlen);
|
2006-03-21 06:45:21 +00:00
|
|
|
int (*compat_getsockopt)(struct sock *sk,
|
|
|
|
int level, int optname,
|
|
|
|
char __user *optval, int __user *optlen);
|
2008-08-28 09:53:51 +00:00
|
|
|
#endif
|
2005-12-14 07:15:52 +00:00
|
|
|
void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
|
2014-08-14 16:40:05 +00:00
|
|
|
void (*mtu_reduced)(struct sock *sk);
|
2005-12-14 07:15:52 +00:00
|
|
|
};
|
|
|
|
|
2005-08-10 03:10:42 +00:00
|
|
|
/** inet_connection_sock - INET connection oriented sock
|
|
|
|
*
|
|
|
|
* @icsk_accept_queue: FIFO of established children
|
|
|
|
* @icsk_bind_hash: Bind node
|
|
|
|
* @icsk_timeout: Timeout
|
|
|
|
* @icsk_retransmit_timer: Resend (no ack)
|
|
|
|
* @icsk_rto: Retransmit timeout
|
2005-12-14 07:26:10 +00:00
|
|
|
* @icsk_pmtu_cookie Last pmtu seen by socket
|
2005-08-10 07:03:31 +00:00
|
|
|
* @icsk_ca_ops Pluggable congestion control hook
|
2005-12-14 07:15:52 +00:00
|
|
|
* @icsk_af_ops Operations which are AF_INET{4,6} specific
|
2017-06-14 18:37:14 +00:00
|
|
|
* @icsk_ulp_ops Pluggable ULP control hook
|
|
|
|
* @icsk_ulp_data ULP private data
|
2017-12-01 20:52:31 +00:00
|
|
|
* @icsk_listen_portaddr_node hash to the portaddr listener hashtable
|
2005-08-10 07:03:31 +00:00
|
|
|
* @icsk_ca_state: Congestion control state
|
2005-08-10 03:10:42 +00:00
|
|
|
* @icsk_retransmits: Number of unrecovered [RTO] timeouts
|
|
|
|
* @icsk_pending: Scheduled timer event
|
|
|
|
* @icsk_backoff: Backoff
|
|
|
|
* @icsk_syn_retries: Number of allowed SYN (or equivalent) retries
|
2005-08-10 07:03:31 +00:00
|
|
|
* @icsk_probes_out: unanswered 0 window probes
|
2005-12-14 07:26:10 +00:00
|
|
|
* @icsk_ext_hdr_len: Network protocol overhead (IP/IPv6 options)
|
2005-08-10 03:10:42 +00:00
|
|
|
* @icsk_ack: Delayed ACK control data
|
2006-03-21 01:53:41 +00:00
|
|
|
* @icsk_mtup; MTU probing control data
|
2005-08-10 03:10:42 +00:00
|
|
|
*/
|
|
|
|
struct inet_connection_sock {
|
|
|
|
/* inet_sock has to be the first member! */
|
|
|
|
struct inet_sock icsk_inet;
|
|
|
|
struct request_sock_queue icsk_accept_queue;
|
|
|
|
struct inet_bind_bucket *icsk_bind_hash;
|
|
|
|
unsigned long icsk_timeout;
|
|
|
|
struct timer_list icsk_retransmit_timer;
|
|
|
|
struct timer_list icsk_delack_timer;
|
|
|
|
__u32 icsk_rto;
|
2005-12-14 07:26:10 +00:00
|
|
|
__u32 icsk_pmtu_cookie;
|
2006-01-09 23:56:09 +00:00
|
|
|
const struct tcp_congestion_ops *icsk_ca_ops;
|
|
|
|
const struct inet_connection_sock_af_ops *icsk_af_ops;
|
2017-06-14 18:37:14 +00:00
|
|
|
const struct tcp_ulp_ops *icsk_ulp_ops;
|
|
|
|
void *icsk_ulp_data;
|
2017-12-01 20:52:31 +00:00
|
|
|
struct hlist_node icsk_listen_portaddr_node;
|
2005-12-14 07:26:10 +00:00
|
|
|
unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu);
|
2015-05-29 17:47:07 +00:00
|
|
|
__u8 icsk_ca_state:6,
|
|
|
|
icsk_ca_setsockopt:1,
|
net: tcp: add key management to congestion control
This patch adds necessary infrastructure to the congestion control
framework for later per route congestion control support.
For a per route congestion control possibility, our aim is to store
a unique u32 key identifier into dst metrics, which can then be
mapped into a tcp_congestion_ops struct. We argue that having a
RTAX key entry is the most simple, generic and easy way to manage,
and also keeps the memory footprint of dst entries lower on 64 bit
than with storing a pointer directly, for example. Having a unique
key id also allows for decoupling actual TCP congestion control
module management from the FIB layer, i.e. we don't have to care
about expensive module refcounting inside the FIB at this point.
We first thought of using an IDR store for the realization, which
takes over dynamic assignment of unused key space and also performs
the key to pointer mapping in RCU. While doing so, we stumbled upon
the issue that due to the nature of dynamic key distribution, it
just so happens, arguably in very rare occasions, that excessive
module loads and unloads can lead to a possible reuse of previously
used key space. Thus, previously stale keys in the dst metric are
now being reassigned to a different congestion control algorithm,
which might lead to unexpected behaviour. One way to resolve this
would have been to walk FIBs on the actually rare occasion of a
module unload and reset the metric keys for each FIB in each netns,
but that's just very costly.
Therefore, we argue a better solution is to reuse the unique
congestion control algorithm name member and map that into u32 key
space through jhash. For that, we split the flags attribute (as it
currently uses 2 bits only anyway) into two u32 attributes, flags
and key, so that we can keep the cacheline boundary of 2 cachelines
on x86_64 and cache the precalculated key at registration time for
the fast path. On average we might expect 2 - 4 modules being loaded
worst case perhaps 15, so a key collision possibility is extremely
low, and guaranteed collision-free on LE/BE for all in-tree modules.
Overall this results in much simpler code, and all without the
overhead of an IDR. Due to the deterministic nature, modules can
now be unloaded, the congestion control algorithm for a specific
but unloaded key will fall back to the default one, and on module
reload time it will switch back to the expected algorithm
transparently.
Joint work with Florian Westphal.
Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-01-05 22:57:46 +00:00
|
|
|
icsk_ca_dst_locked:1;
|
2005-08-10 03:10:42 +00:00
|
|
|
__u8 icsk_retransmits;
|
|
|
|
__u8 icsk_pending;
|
|
|
|
__u8 icsk_backoff;
|
|
|
|
__u8 icsk_syn_retries;
|
2005-08-10 07:03:31 +00:00
|
|
|
__u8 icsk_probes_out;
|
2005-12-14 07:26:10 +00:00
|
|
|
__u16 icsk_ext_hdr_len;
|
2005-08-10 03:10:42 +00:00
|
|
|
struct {
|
|
|
|
__u8 pending; /* ACK is pending */
|
|
|
|
__u8 quick; /* Scheduled number of quick acks */
|
|
|
|
__u8 pingpong; /* The session is interactive */
|
|
|
|
__u8 blocked; /* Delayed ACK was blocked by socket lock */
|
|
|
|
__u32 ato; /* Predicted tick of soft clock */
|
|
|
|
unsigned long timeout; /* Currently scheduled timeout */
|
|
|
|
__u32 lrcvtime; /* timestamp of last received data packet */
|
|
|
|
__u16 last_seg_size; /* Size of last incoming segment */
|
|
|
|
__u16 rcv_mss; /* MSS used for delayed ACK decisions */
|
|
|
|
} icsk_ack;
|
2006-03-21 01:53:41 +00:00
|
|
|
struct {
|
|
|
|
int enabled;
|
|
|
|
|
|
|
|
/* Range of MTUs to search */
|
|
|
|
int search_high;
|
|
|
|
int search_low;
|
|
|
|
|
|
|
|
/* Information on the current probe. */
|
|
|
|
int probe_size;
|
2015-03-06 03:18:24 +00:00
|
|
|
|
|
|
|
u32 probe_timestamp;
|
2006-03-21 01:53:41 +00:00
|
|
|
} icsk_mtup;
|
tcp: Add TCP_USER_TIMEOUT socket option.
This patch provides a "user timeout" support as described in RFC793. The
socket option is also needed for the the local half of RFC5482 "TCP User
Timeout Option".
TCP_USER_TIMEOUT is a TCP level socket option that takes an unsigned int,
when > 0, to specify the maximum amount of time in ms that transmitted
data may remain unacknowledged before TCP will forcefully close the
corresponding connection and return ETIMEDOUT to the application. If
0 is given, TCP will continue to use the system default.
Increasing the user timeouts allows a TCP connection to survive extended
periods without end-to-end connectivity. Decreasing the user timeouts
allows applications to "fail fast" if so desired. Otherwise it may take
upto 20 minutes with the current system defaults in a normal WAN
environment.
The socket option can be made during any state of a TCP connection, but
is only effective during the synchronized states of a connection
(ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, CLOSE-WAIT, CLOSING, or LAST-ACK).
Moreover, when used with the TCP keepalive (SO_KEEPALIVE) option,
TCP_USER_TIMEOUT will overtake keepalive to determine when to close a
connection due to keepalive failure.
The option does not change in anyway when TCP retransmits a packet, nor
when a keepalive probe will be sent.
This option, like many others, will be inherited by an acceptor from its
listener.
Signed-off-by: H.K. Jerry Chu <hkchu@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-08-27 19:13:28 +00:00
|
|
|
u32 icsk_user_timeout;
|
2015-05-19 00:06:14 +00:00
|
|
|
|
2016-09-20 03:39:22 +00:00
|
|
|
u64 icsk_ca_priv[88 / sizeof(u64)];
|
|
|
|
#define ICSK_CA_PRIV_SIZE (11 * sizeof(u64))
|
2005-08-10 03:10:42 +00:00
|
|
|
};
|
|
|
|
|
2005-08-10 03:11:08 +00:00
|
|
|
#define ICSK_TIME_RETRANS 1 /* Retransmit timer */
|
|
|
|
#define ICSK_TIME_DACK 2 /* Delayed ack timer */
|
|
|
|
#define ICSK_TIME_PROBE0 3 /* Zero window probe timer */
|
tcp: Tail loss probe (TLP)
This patch series implement the Tail loss probe (TLP) algorithm described
in http://tools.ietf.org/html/draft-dukkipati-tcpm-tcp-loss-probe-01. The
first patch implements the basic algorithm.
TLP's goal is to reduce tail latency of short transactions. It achieves
this by converting retransmission timeouts (RTOs) occuring due
to tail losses (losses at end of transactions) into fast recovery.
TLP transmits one packet in two round-trips when a connection is in
Open state and isn't receiving any ACKs. The transmitted packet, aka
loss probe, can be either new or a retransmission. When there is tail
loss, the ACK from a loss probe triggers FACK/early-retransmit based
fast recovery, thus avoiding a costly RTO. In the absence of loss,
there is no change in the connection state.
PTO stands for probe timeout. It is a timer event indicating
that an ACK is overdue and triggers a loss probe packet. The PTO value
is set to max(2*SRTT, 10ms) and is adjusted to account for delayed
ACK timer when there is only one oustanding packet.
TLP Algorithm
On transmission of new data in Open state:
-> packets_out > 1: schedule PTO in max(2*SRTT, 10ms).
-> packets_out == 1: schedule PTO in max(2*RTT, 1.5*RTT + 200ms)
-> PTO = min(PTO, RTO)
Conditions for scheduling PTO:
-> Connection is in Open state.
-> Connection is either cwnd limited or no new data to send.
-> Number of probes per tail loss episode is limited to one.
-> Connection is SACK enabled.
When PTO fires:
new_segment_exists:
-> transmit new segment.
-> packets_out++. cwnd remains same.
no_new_packet:
-> retransmit the last segment.
Its ACK triggers FACK or early retransmit based recovery.
ACK path:
-> rearm RTO at start of ACK processing.
-> reschedule PTO if need be.
In addition, the patch includes a small variation to the Early Retransmit
(ER) algorithm, such that ER and TLP together can in principle recover any
N-degree of tail loss through fast recovery. TLP is controlled by the same
sysctl as ER, tcp_early_retrans sysctl.
tcp_early_retrans==0; disables TLP and ER.
==1; enables RFC5827 ER.
==2; delayed ER.
==3; TLP and delayed ER. [DEFAULT]
==4; TLP only.
The TLP patch series have been extensively tested on Google Web servers.
It is most effective for short Web trasactions, where it reduced RTOs by 15%
and improved HTTP response time (average by 6%, 99th percentile by 10%).
The transmitted probes account for <0.5% of the overall transmissions.
Signed-off-by: Nandita Dukkipati <nanditad@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-03-11 10:00:43 +00:00
|
|
|
#define ICSK_TIME_EARLY_RETRANS 4 /* Early retransmit timer */
|
|
|
|
#define ICSK_TIME_LOSS_PROBE 5 /* Tail loss probe timer */
|
2017-01-13 06:11:33 +00:00
|
|
|
#define ICSK_TIME_REO_TIMEOUT 6 /* Reordering timer */
|
2005-08-10 03:11:08 +00:00
|
|
|
|
2005-08-10 03:10:42 +00:00
|
|
|
static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return (struct inet_connection_sock *)sk;
|
|
|
|
}
|
|
|
|
|
2005-08-10 07:03:31 +00:00
|
|
|
static inline void *inet_csk_ca(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return (void *)inet_csk(sk)->icsk_ca_priv;
|
|
|
|
}
|
|
|
|
|
2013-09-21 17:22:41 +00:00
|
|
|
struct sock *inet_csk_clone_lock(const struct sock *sk,
|
|
|
|
const struct request_sock *req,
|
|
|
|
const gfp_t priority);
|
2005-08-10 03:11:24 +00:00
|
|
|
|
2005-08-10 03:11:08 +00:00
|
|
|
enum inet_csk_ack_state_t {
|
|
|
|
ICSK_ACK_SCHED = 1,
|
|
|
|
ICSK_ACK_TIMER = 2,
|
2006-09-19 19:52:50 +00:00
|
|
|
ICSK_ACK_PUSHED = 4,
|
|
|
|
ICSK_ACK_PUSHED2 = 8
|
2005-08-10 03:11:08 +00:00
|
|
|
};
|
|
|
|
|
2013-09-21 17:22:41 +00:00
|
|
|
void inet_csk_init_xmit_timers(struct sock *sk,
|
2017-10-17 00:29:19 +00:00
|
|
|
void (*retransmit_handler)(struct timer_list *),
|
|
|
|
void (*delack_handler)(struct timer_list *),
|
|
|
|
void (*keepalive_handler)(struct timer_list *));
|
2013-09-21 17:22:41 +00:00
|
|
|
void inet_csk_clear_xmit_timers(struct sock *sk);
|
2005-08-10 03:10:42 +00:00
|
|
|
|
2005-08-10 03:11:08 +00:00
|
|
|
static inline void inet_csk_schedule_ack(struct sock *sk)
|
|
|
|
{
|
|
|
|
inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_SCHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int inet_csk_ack_scheduled(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return inet_csk(sk)->icsk_ack.pending & ICSK_ACK_SCHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void inet_csk_delack_init(struct sock *sk)
|
|
|
|
{
|
|
|
|
memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack));
|
|
|
|
}
|
|
|
|
|
2013-09-21 17:22:41 +00:00
|
|
|
void inet_csk_delete_keepalive_timer(struct sock *sk);
|
|
|
|
void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long timeout);
|
2005-08-10 03:11:08 +00:00
|
|
|
|
|
|
|
#ifdef INET_CSK_DEBUG
|
|
|
|
extern const char inet_csk_timer_bug_msg[];
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)
|
|
|
|
{
|
|
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
|
|
|
|
|
|
if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
|
|
|
|
icsk->icsk_pending = 0;
|
|
|
|
#ifdef INET_CSK_CLEAR_TIMERS
|
|
|
|
sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
|
|
|
|
#endif
|
|
|
|
} else if (what == ICSK_TIME_DACK) {
|
|
|
|
icsk->icsk_ack.blocked = icsk->icsk_ack.pending = 0;
|
|
|
|
#ifdef INET_CSK_CLEAR_TIMERS
|
|
|
|
sk_stop_timer(sk, &icsk->icsk_delack_timer);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef INET_CSK_DEBUG
|
|
|
|
else {
|
2005-08-30 05:51:28 +00:00
|
|
|
pr_debug("%s", inet_csk_timer_bug_msg);
|
2005-08-10 03:11:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset the retransmission timer
|
|
|
|
*/
|
|
|
|
static inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what,
|
|
|
|
unsigned long when,
|
|
|
|
const unsigned long max_when)
|
|
|
|
{
|
|
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
|
|
|
|
|
|
if (when > max_when) {
|
|
|
|
#ifdef INET_CSK_DEBUG
|
|
|
|
pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",
|
|
|
|
sk, what, when, current_text_addr());
|
|
|
|
#endif
|
|
|
|
when = max_when;
|
|
|
|
}
|
|
|
|
|
tcp: Tail loss probe (TLP)
This patch series implement the Tail loss probe (TLP) algorithm described
in http://tools.ietf.org/html/draft-dukkipati-tcpm-tcp-loss-probe-01. The
first patch implements the basic algorithm.
TLP's goal is to reduce tail latency of short transactions. It achieves
this by converting retransmission timeouts (RTOs) occuring due
to tail losses (losses at end of transactions) into fast recovery.
TLP transmits one packet in two round-trips when a connection is in
Open state and isn't receiving any ACKs. The transmitted packet, aka
loss probe, can be either new or a retransmission. When there is tail
loss, the ACK from a loss probe triggers FACK/early-retransmit based
fast recovery, thus avoiding a costly RTO. In the absence of loss,
there is no change in the connection state.
PTO stands for probe timeout. It is a timer event indicating
that an ACK is overdue and triggers a loss probe packet. The PTO value
is set to max(2*SRTT, 10ms) and is adjusted to account for delayed
ACK timer when there is only one oustanding packet.
TLP Algorithm
On transmission of new data in Open state:
-> packets_out > 1: schedule PTO in max(2*SRTT, 10ms).
-> packets_out == 1: schedule PTO in max(2*RTT, 1.5*RTT + 200ms)
-> PTO = min(PTO, RTO)
Conditions for scheduling PTO:
-> Connection is in Open state.
-> Connection is either cwnd limited or no new data to send.
-> Number of probes per tail loss episode is limited to one.
-> Connection is SACK enabled.
When PTO fires:
new_segment_exists:
-> transmit new segment.
-> packets_out++. cwnd remains same.
no_new_packet:
-> retransmit the last segment.
Its ACK triggers FACK or early retransmit based recovery.
ACK path:
-> rearm RTO at start of ACK processing.
-> reschedule PTO if need be.
In addition, the patch includes a small variation to the Early Retransmit
(ER) algorithm, such that ER and TLP together can in principle recover any
N-degree of tail loss through fast recovery. TLP is controlled by the same
sysctl as ER, tcp_early_retrans sysctl.
tcp_early_retrans==0; disables TLP and ER.
==1; enables RFC5827 ER.
==2; delayed ER.
==3; TLP and delayed ER. [DEFAULT]
==4; TLP only.
The TLP patch series have been extensively tested on Google Web servers.
It is most effective for short Web trasactions, where it reduced RTOs by 15%
and improved HTTP response time (average by 6%, 99th percentile by 10%).
The transmitted probes account for <0.5% of the overall transmissions.
Signed-off-by: Nandita Dukkipati <nanditad@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-03-11 10:00:43 +00:00
|
|
|
if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0 ||
|
2017-01-13 06:11:33 +00:00
|
|
|
what == ICSK_TIME_EARLY_RETRANS || what == ICSK_TIME_LOSS_PROBE ||
|
|
|
|
what == ICSK_TIME_REO_TIMEOUT) {
|
2005-08-10 03:11:08 +00:00
|
|
|
icsk->icsk_pending = what;
|
|
|
|
icsk->icsk_timeout = jiffies + when;
|
|
|
|
sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
|
|
|
|
} else if (what == ICSK_TIME_DACK) {
|
|
|
|
icsk->icsk_ack.pending |= ICSK_ACK_TIMER;
|
|
|
|
icsk->icsk_ack.timeout = jiffies + when;
|
|
|
|
sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);
|
|
|
|
}
|
|
|
|
#ifdef INET_CSK_DEBUG
|
|
|
|
else {
|
2005-08-30 05:51:28 +00:00
|
|
|
pr_debug("%s", inet_csk_timer_bug_msg);
|
2005-08-10 03:11:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-09-22 20:19:44 +00:00
|
|
|
static inline unsigned long
|
|
|
|
inet_csk_rto_backoff(const struct inet_connection_sock *icsk,
|
|
|
|
unsigned long max_when)
|
|
|
|
{
|
|
|
|
u64 when = (u64)icsk->icsk_rto << icsk->icsk_backoff;
|
|
|
|
|
|
|
|
return (unsigned long)min_t(u64, when, max_when);
|
|
|
|
}
|
|
|
|
|
2017-03-09 08:09:05 +00:00
|
|
|
struct sock *inet_csk_accept(struct sock *sk, int flags, int *err, bool kern);
|
2005-08-10 03:11:08 +00:00
|
|
|
|
2013-09-21 17:22:41 +00:00
|
|
|
int inet_csk_get_port(struct sock *sk, unsigned short snum);
|
2005-08-10 03:10:42 +00:00
|
|
|
|
2015-09-25 14:39:11 +00:00
|
|
|
struct dst_entry *inet_csk_route_req(const struct sock *sk, struct flowi4 *fl4,
|
2013-09-21 17:22:41 +00:00
|
|
|
const struct request_sock *req);
|
2015-09-29 14:42:43 +00:00
|
|
|
struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,
|
|
|
|
struct sock *newsk,
|
2012-07-17 21:02:46 +00:00
|
|
|
const struct request_sock *req);
|
2005-08-10 03:10:42 +00:00
|
|
|
|
2016-02-18 13:39:18 +00:00
|
|
|
struct sock *inet_csk_reqsk_queue_add(struct sock *sk,
|
|
|
|
struct request_sock *req,
|
|
|
|
struct sock *child);
|
2013-09-21 17:22:41 +00:00
|
|
|
void inet_csk_reqsk_queue_hash_add(struct sock *sk, struct request_sock *req,
|
|
|
|
unsigned long timeout);
|
2015-10-22 15:20:46 +00:00
|
|
|
struct sock *inet_csk_complete_hashdance(struct sock *sk, struct sock *child,
|
|
|
|
struct request_sock *req,
|
|
|
|
bool own_req);
|
2005-08-10 03:11:08 +00:00
|
|
|
|
2015-10-02 18:43:31 +00:00
|
|
|
static inline void inet_csk_reqsk_queue_added(struct sock *sk)
|
2005-08-10 03:11:08 +00:00
|
|
|
{
|
inet: get rid of central tcp/dccp listener timer
One of the major issue for TCP is the SYNACK rtx handling,
done by inet_csk_reqsk_queue_prune(), fired by the keepalive
timer of a TCP_LISTEN socket.
This function runs for awful long times, with socket lock held,
meaning that other cpus needing this lock have to spin for hundred of ms.
SYNACK are sent in huge bursts, likely to cause severe drops anyway.
This model was OK 15 years ago when memory was very tight.
We now can afford to have a timer per request sock.
Timer invocations no longer need to lock the listener,
and can be run from all cpus in parallel.
With following patch increasing somaxconn width to 32 bits,
I tested a listener with more than 4 million active request sockets,
and a steady SYNFLOOD of ~200,000 SYN per second.
Host was sending ~830,000 SYNACK per second.
This is ~100 times more what we could achieve before this patch.
Later, we will get rid of the listener hash and use ehash instead.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2015-03-20 02:04:20 +00:00
|
|
|
reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue);
|
2005-08-10 03:11:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int inet_csk_reqsk_queue_len(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
|
|
|
|
{
|
2015-10-02 18:43:37 +00:00
|
|
|
return inet_csk_reqsk_queue_len(sk) >= sk->sk_max_ack_backlog;
|
2005-08-10 03:11:08 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 01:03:44 +00:00
|
|
|
void inet_csk_reqsk_queue_drop(struct sock *sk, struct request_sock *req);
|
2015-10-14 18:16:27 +00:00
|
|
|
void inet_csk_reqsk_queue_drop_and_put(struct sock *sk, struct request_sock *req);
|
2005-08-10 03:11:08 +00:00
|
|
|
|
2013-09-21 17:22:41 +00:00
|
|
|
void inet_csk_destroy_sock(struct sock *sk);
|
|
|
|
void inet_csk_prepare_forced_close(struct sock *sk);
|
2005-08-24 04:52:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LISTEN is a special case for poll..
|
|
|
|
*/
|
|
|
|
static inline unsigned int inet_csk_listen_poll(const struct sock *sk)
|
|
|
|
{
|
|
|
|
return !reqsk_queue_empty(&inet_csk(sk)->icsk_accept_queue) ?
|
|
|
|
(POLLIN | POLLRDNORM) : 0;
|
|
|
|
}
|
|
|
|
|
2015-10-14 13:16:49 +00:00
|
|
|
int inet_csk_listen_start(struct sock *sk, int backlog);
|
2013-09-21 17:22:41 +00:00
|
|
|
void inet_csk_listen_stop(struct sock *sk);
|
2005-08-10 03:11:56 +00:00
|
|
|
|
2013-09-21 17:22:41 +00:00
|
|
|
void inet_csk_addr2sockaddr(struct sock *sk, struct sockaddr *uaddr);
|
2005-12-14 07:16:04 +00:00
|
|
|
|
2013-09-21 17:22:41 +00:00
|
|
|
int inet_csk_compat_getsockopt(struct sock *sk, int level, int optname,
|
|
|
|
char __user *optval, int __user *optlen);
|
|
|
|
int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname,
|
|
|
|
char __user *optval, unsigned int optlen);
|
2012-07-16 10:28:06 +00:00
|
|
|
|
2013-09-21 17:22:41 +00:00
|
|
|
struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu);
|
2005-08-10 03:10:42 +00:00
|
|
|
#endif /* _INET_CONNECTION_SOCK_H */
|