[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
/*
|
|
|
|
* NET Generic infrastructure for Network protocols.
|
|
|
|
*
|
2016-12-28 12:52:33 +03:00
|
|
|
* Definitions for request_sock
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
*
|
|
|
|
* Authors: Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
*
|
|
|
|
* From code originally in include/net/tcp.h
|
|
|
|
*
|
|
|
|
* 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 _REQUEST_SOCK_H
|
|
|
|
#define _REQUEST_SOCK_H
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
2005-06-19 09:47:59 +04:00
|
|
|
#include <linux/spinlock.h>
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
#include <linux/types.h>
|
2008-07-26 08:43:18 +04:00
|
|
|
#include <linux/bug.h>
|
2017-06-30 13:08:01 +03:00
|
|
|
#include <linux/refcount.h>
|
2005-06-19 09:47:59 +04:00
|
|
|
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
#include <net/sock.h>
|
|
|
|
|
2005-06-19 09:47:21 +04:00
|
|
|
struct request_sock;
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
struct sk_buff;
|
|
|
|
struct dst_entry;
|
|
|
|
struct proto;
|
|
|
|
|
2005-06-19 09:47:21 +04:00
|
|
|
struct request_sock_ops {
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
int family;
|
2017-05-23 00:21:39 +03:00
|
|
|
unsigned int obj_size;
|
2006-12-07 07:33:20 +03:00
|
|
|
struct kmem_cache *slab;
|
2008-11-22 03:45:22 +03:00
|
|
|
char *slab_name;
|
2015-09-25 17:39:23 +03:00
|
|
|
int (*rtx_syn_ack)(const struct sock *sk,
|
2013-03-17 12:23:34 +04:00
|
|
|
struct request_sock *req);
|
2015-09-29 17:42:39 +03:00
|
|
|
void (*send_ack)(const struct sock *sk, struct sk_buff *skb,
|
2005-06-19 09:47:21 +04:00
|
|
|
struct request_sock *req);
|
2015-09-29 17:42:39 +03:00
|
|
|
void (*send_reset)(const struct sock *sk,
|
2006-11-15 06:07:45 +03:00
|
|
|
struct sk_buff *skb);
|
2005-06-19 09:47:21 +04:00
|
|
|
void (*destructor)(struct request_sock *req);
|
2015-03-22 20:22:19 +03:00
|
|
|
void (*syn_ack_timeout)(const struct request_sock *req);
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
};
|
|
|
|
|
2015-09-25 17:39:24 +03:00
|
|
|
int inet_rtx_syn_ack(const struct sock *parent, struct request_sock *req);
|
2012-10-28 03:16:46 +04:00
|
|
|
|
2005-06-19 09:47:21 +04:00
|
|
|
/* struct request_sock - mini sock to represent a connection request
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
*/
|
2005-06-19 09:47:21 +04:00
|
|
|
struct request_sock {
|
2013-10-10 02:21:29 +04:00
|
|
|
struct sock_common __req_common;
|
2015-03-13 02:44:06 +03:00
|
|
|
#define rsk_refcnt __req_common.skc_refcnt
|
2015-03-20 05:04:19 +03:00
|
|
|
#define rsk_hash __req_common.skc_hash
|
2015-10-09 05:33:22 +03:00
|
|
|
#define rsk_listener __req_common.skc_listener
|
2015-10-09 05:33:23 +03:00
|
|
|
#define rsk_window_clamp __req_common.skc_window_clamp
|
|
|
|
#define rsk_rcv_wnd __req_common.skc_rcv_wnd
|
2015-03-13 02:44:06 +03:00
|
|
|
|
2013-04-20 01:29:25 +04:00
|
|
|
struct request_sock *dl_next;
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
u16 mss;
|
2012-10-28 03:16:46 +04:00
|
|
|
u8 num_retrans; /* number of retransmits */
|
|
|
|
u8 cookie_ts:1; /* syncookie: encode tcpopts in timestamp */
|
|
|
|
u8 num_timeout:7; /* number of timeouts */
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
u32 ts_recent;
|
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 05:04:20 +03:00
|
|
|
struct timer_list rsk_timer;
|
2006-11-16 13:30:37 +03:00
|
|
|
const struct request_sock_ops *rsk_ops;
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
struct sock *sk;
|
2015-05-04 07:34:46 +03:00
|
|
|
u32 *saved_syn;
|
2006-07-25 10:32:50 +04:00
|
|
|
u32 secid;
|
2006-11-09 02:04:09 +03:00
|
|
|
u32 peer_secid;
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
};
|
|
|
|
|
2015-12-21 23:29:24 +03:00
|
|
|
static inline struct request_sock *inet_reqsk(const struct sock *sk)
|
2015-10-02 21:43:27 +03:00
|
|
|
{
|
|
|
|
return (struct request_sock *)sk;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct sock *req_to_sk(struct request_sock *req)
|
|
|
|
{
|
|
|
|
return (struct sock *)req;
|
|
|
|
}
|
|
|
|
|
2015-03-18 04:32:28 +03:00
|
|
|
static inline struct request_sock *
|
2015-10-05 07:08:11 +03:00
|
|
|
reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener,
|
|
|
|
bool attach_listener)
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
{
|
2015-10-03 16:27:28 +03:00
|
|
|
struct request_sock *req;
|
|
|
|
|
|
|
|
req = kmem_cache_alloc(ops->slab, GFP_ATOMIC | __GFP_NOWARN);
|
2016-04-01 18:52:16 +03:00
|
|
|
if (!req)
|
|
|
|
return NULL;
|
|
|
|
req->rsk_listener = NULL;
|
|
|
|
if (attach_listener) {
|
2017-06-30 13:08:01 +03:00
|
|
|
if (unlikely(!refcount_inc_not_zero(&sk_listener->sk_refcnt))) {
|
2016-04-01 18:52:16 +03:00
|
|
|
kmem_cache_free(ops->slab, req);
|
|
|
|
return NULL;
|
2015-10-05 07:08:11 +03:00
|
|
|
}
|
2016-04-01 18:52:16 +03:00
|
|
|
req->rsk_listener = sk_listener;
|
2015-03-18 04:32:28 +03:00
|
|
|
}
|
2016-04-01 18:52:16 +03:00
|
|
|
req->rsk_ops = ops;
|
|
|
|
req_to_sk(req)->sk_prot = sk_listener->sk_prot;
|
|
|
|
sk_node_init(&req_to_sk(req)->sk_node);
|
|
|
|
sk_tx_queue_clear(req_to_sk(req));
|
|
|
|
req->saved_syn = NULL;
|
2017-06-30 13:08:01 +03:00
|
|
|
refcount_set(&req->rsk_refcnt, 0);
|
2016-04-01 18:52:16 +03:00
|
|
|
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2005-06-19 09:47:21 +04:00
|
|
|
static inline void reqsk_free(struct request_sock *req)
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
{
|
2017-06-30 13:08:01 +03:00
|
|
|
WARN_ON_ONCE(refcount_read(&req->rsk_refcnt) != 0);
|
2015-03-16 07:12:16 +03:00
|
|
|
|
2005-06-19 09:47:21 +04:00
|
|
|
req->rsk_ops->destructor(req);
|
2015-03-18 04:32:28 +03:00
|
|
|
if (req->rsk_listener)
|
|
|
|
sock_put(req->rsk_listener);
|
2015-05-04 07:34:46 +03:00
|
|
|
kfree(req->saved_syn);
|
2015-03-16 07:12:16 +03:00
|
|
|
kmem_cache_free(req->rsk_ops->slab, req);
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
}
|
|
|
|
|
2015-03-13 02:44:06 +03:00
|
|
|
static inline void reqsk_put(struct request_sock *req)
|
|
|
|
{
|
2017-06-30 13:08:01 +03:00
|
|
|
if (refcount_dec_and_test(&req->rsk_refcnt))
|
2015-03-13 02:44:06 +03:00
|
|
|
reqsk_free(req);
|
|
|
|
}
|
|
|
|
|
2012-08-31 16:29:11 +04:00
|
|
|
/*
|
|
|
|
* For a TCP Fast Open listener -
|
|
|
|
* lock - protects the access to all the reqsk, which is co-owned by
|
|
|
|
* the listener and the child socket.
|
|
|
|
* qlen - pending TFO requests (still in TCP_SYN_RECV).
|
|
|
|
* max_qlen - max TFO reqs allowed before TFO is disabled.
|
|
|
|
*
|
|
|
|
* XXX (TFO) - ideally these fields can be made as part of "listen_sock"
|
|
|
|
* structure above. But there is some implementation difficulty due to
|
|
|
|
* listen_sock being part of request_sock_queue hence will be freed when
|
|
|
|
* a listener is stopped. But TFO related fields may continue to be
|
|
|
|
* accessed even after a listener is closed, until its sk_refcnt drops
|
|
|
|
* to 0 implying no more outstanding TFO reqs. One solution is to keep
|
|
|
|
* listen_opt around until sk_refcnt drops to 0. But there is some other
|
|
|
|
* complexity that needs to be resolved. E.g., a listener can be disabled
|
|
|
|
* temporarily through shutdown()->tcp_disconnect(), and re-enabled later.
|
|
|
|
*/
|
|
|
|
struct fastopen_queue {
|
|
|
|
struct request_sock *rskq_rst_head; /* Keep track of past TFO */
|
|
|
|
struct request_sock *rskq_rst_tail; /* requests that caused RST.
|
|
|
|
* This is part of the defense
|
|
|
|
* against spoofing attack.
|
|
|
|
*/
|
|
|
|
spinlock_t lock;
|
|
|
|
int qlen; /* # of pending (TCP_SYN_RECV) reqs */
|
|
|
|
int max_qlen; /* != 0 iff TFO is currently enabled */
|
2017-10-18 21:22:51 +03:00
|
|
|
|
|
|
|
struct tcp_fastopen_context __rcu *ctx; /* cipher context for cookie */
|
2012-08-31 16:29:11 +04:00
|
|
|
};
|
|
|
|
|
2005-06-19 09:47:59 +04:00
|
|
|
/** struct request_sock_queue - queue of request_socks
|
|
|
|
*
|
|
|
|
* @rskq_accept_head - FIFO head of established children
|
|
|
|
* @rskq_accept_tail - FIFO tail of established children
|
2005-08-10 07:11:56 +04:00
|
|
|
* @rskq_defer_accept - User waits for some data after accept()
|
2005-06-19 09:47:59 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct request_sock_queue {
|
2015-10-02 21:43:23 +03:00
|
|
|
spinlock_t rskq_lock;
|
|
|
|
u8 rskq_defer_accept;
|
2015-10-02 21:43:37 +03:00
|
|
|
|
2015-10-02 21:43:25 +03:00
|
|
|
u32 synflood_warned;
|
2015-10-02 21:43:24 +03:00
|
|
|
atomic_t qlen;
|
|
|
|
atomic_t young;
|
|
|
|
|
2005-06-19 09:47:59 +04:00
|
|
|
struct request_sock *rskq_accept_head;
|
|
|
|
struct request_sock *rskq_accept_tail;
|
2015-09-29 17:42:52 +03:00
|
|
|
struct fastopen_queue fastopenq; /* Check max_qlen != 0 to determine
|
|
|
|
* if TFO is enabled.
|
2012-08-31 16:29:11 +04:00
|
|
|
*/
|
2005-06-19 09:47:59 +04:00
|
|
|
};
|
|
|
|
|
2015-10-02 21:43:37 +03:00
|
|
|
void reqsk_queue_alloc(struct request_sock_queue *queue);
|
2005-06-19 09:47:59 +04:00
|
|
|
|
2013-09-22 21:32:20 +04:00
|
|
|
void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
|
|
|
|
bool reset);
|
2005-08-10 06:33:31 +04:00
|
|
|
|
2015-10-02 21:43:23 +03:00
|
|
|
static inline bool reqsk_queue_empty(const struct request_sock_queue *queue)
|
2005-06-19 09:47:59 +04:00
|
|
|
{
|
|
|
|
return queue->rskq_accept_head == NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-02 21:43:23 +03:00
|
|
|
static inline struct request_sock *reqsk_queue_remove(struct request_sock_queue *queue,
|
|
|
|
struct sock *parent)
|
2005-06-19 09:47:59 +04:00
|
|
|
{
|
2015-10-02 21:43:23 +03:00
|
|
|
struct request_sock *req;
|
2005-06-19 09:47:59 +04:00
|
|
|
|
2015-10-02 21:43:23 +03:00
|
|
|
spin_lock_bh(&queue->rskq_lock);
|
|
|
|
req = queue->rskq_accept_head;
|
|
|
|
if (req) {
|
|
|
|
sk_acceptq_removed(parent);
|
|
|
|
queue->rskq_accept_head = req->dl_next;
|
|
|
|
if (queue->rskq_accept_head == NULL)
|
|
|
|
queue->rskq_accept_tail = NULL;
|
|
|
|
}
|
|
|
|
spin_unlock_bh(&queue->rskq_lock);
|
2005-06-19 09:47:59 +04:00
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
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 05:04:20 +03:00
|
|
|
static inline void reqsk_queue_removed(struct request_sock_queue *queue,
|
|
|
|
const struct request_sock *req)
|
2005-06-19 09:47:59 +04:00
|
|
|
{
|
2012-10-28 03:16:46 +04:00
|
|
|
if (req->num_timeout == 0)
|
2015-10-02 21:43:24 +03:00
|
|
|
atomic_dec(&queue->young);
|
|
|
|
atomic_dec(&queue->qlen);
|
2005-06-19 09:47:59 +04: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 05:04:20 +03:00
|
|
|
static inline void reqsk_queue_added(struct request_sock_queue *queue)
|
2005-06-19 09:47:59 +04:00
|
|
|
{
|
2015-10-02 21:43:24 +03:00
|
|
|
atomic_inc(&queue->young);
|
|
|
|
atomic_inc(&queue->qlen);
|
2005-06-19 09:47:59 +04: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 05:04:20 +03:00
|
|
|
static inline int reqsk_queue_len(const struct request_sock_queue *queue)
|
2005-06-19 09:47:59 +04:00
|
|
|
{
|
2015-10-02 21:43:24 +03:00
|
|
|
return atomic_read(&queue->qlen);
|
2005-06-19 09:47:59 +04: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 05:04:20 +03:00
|
|
|
static inline int reqsk_queue_len_young(const struct request_sock_queue *queue)
|
2005-06-19 09:47:59 +04:00
|
|
|
{
|
2015-10-02 21:43:24 +03:00
|
|
|
return atomic_read(&queue->young);
|
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 05:04:20 +03:00
|
|
|
}
|
2015-03-18 04:32:31 +03:00
|
|
|
|
[NET] Generalise TCP's struct open_request minisock infrastructure
Kept this first changeset minimal, without changing existing names to
ease peer review.
Basicaly tcp_openreq_alloc now receives the or_calltable, that in turn
has two new members:
->slab, that replaces tcp_openreq_cachep
->obj_size, to inform the size of the openreq descendant for
a specific protocol
The protocol specific fields in struct open_request were moved to a
class hierarchy, with the things that are common to all connection
oriented PF_INET protocols in struct inet_request_sock, the TCP ones
in tcp_request_sock, that is an inet_request_sock, that is an
open_request.
I.e. this uses the same approach used for the struct sock class
hierarchy, with sk_prot indicating if the protocol wants to use the
open_request infrastructure by filling in sk_prot->rsk_prot with an
or_calltable.
Results? Performance is improved and TCP v4 now uses only 64 bytes per
open request minisock, down from 96 without this patch :-)
Next changeset will rename some of the structs, fields and functions
mentioned above, struct or_calltable is way unclear, better name it
struct request_sock_ops, s/struct open_request/struct request_sock/g,
etc.
Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2005-06-19 09:46:52 +04:00
|
|
|
#endif /* _REQUEST_SOCK_H */
|