[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 13:46:52 +08:00
|
|
|
/*
|
|
|
|
* NET Generic infrastructure for Network protocols.
|
|
|
|
*
|
2016-12-28 17:52:33 +08: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 13:46:52 +08: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 13:47:59 +08: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 13:46:52 +08:00
|
|
|
#include <linux/types.h>
|
2008-07-26 12:43:18 +08:00
|
|
|
#include <linux/bug.h>
|
2005-06-19 13:47:59 +08: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 13:46:52 +08:00
|
|
|
#include <net/sock.h>
|
|
|
|
|
2005-06-19 13:47:21 +08: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 13:46:52 +08:00
|
|
|
struct sk_buff;
|
|
|
|
struct dst_entry;
|
|
|
|
struct proto;
|
|
|
|
|
2005-06-19 13:47:21 +08: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 13:46:52 +08:00
|
|
|
int family;
|
2017-05-23 05:21:39 +08:00
|
|
|
unsigned int obj_size;
|
2006-12-07 12:33:20 +08:00
|
|
|
struct kmem_cache *slab;
|
2008-11-22 08:45:22 +08:00
|
|
|
char *slab_name;
|
2015-09-25 22:39:23 +08:00
|
|
|
int (*rtx_syn_ack)(const struct sock *sk,
|
2013-03-17 16:23:34 +08:00
|
|
|
struct request_sock *req);
|
2015-09-29 22:42:39 +08:00
|
|
|
void (*send_ack)(const struct sock *sk, struct sk_buff *skb,
|
2005-06-19 13:47:21 +08:00
|
|
|
struct request_sock *req);
|
2015-09-29 22:42:39 +08:00
|
|
|
void (*send_reset)(const struct sock *sk,
|
2006-11-15 11:07:45 +08:00
|
|
|
struct sk_buff *skb);
|
2005-06-19 13:47:21 +08:00
|
|
|
void (*destructor)(struct request_sock *req);
|
2015-03-23 01:22:19 +08: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 13:46:52 +08:00
|
|
|
};
|
|
|
|
|
2015-09-25 22:39:24 +08:00
|
|
|
int inet_rtx_syn_ack(const struct sock *parent, struct request_sock *req);
|
2012-10-28 07:16:46 +08:00
|
|
|
|
2005-06-19 13:47:21 +08: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 13:46:52 +08:00
|
|
|
*/
|
2005-06-19 13:47:21 +08:00
|
|
|
struct request_sock {
|
2013-10-10 06:21:29 +08:00
|
|
|
struct sock_common __req_common;
|
2015-03-13 07:44:06 +08:00
|
|
|
#define rsk_refcnt __req_common.skc_refcnt
|
2015-03-20 10:04:19 +08:00
|
|
|
#define rsk_hash __req_common.skc_hash
|
2015-10-09 10:33:22 +08:00
|
|
|
#define rsk_listener __req_common.skc_listener
|
2015-10-09 10:33:23 +08:00
|
|
|
#define rsk_window_clamp __req_common.skc_window_clamp
|
|
|
|
#define rsk_rcv_wnd __req_common.skc_rcv_wnd
|
2015-03-13 07:44:06 +08:00
|
|
|
|
2013-04-20 05:29:25 +08: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 13:46:52 +08:00
|
|
|
u16 mss;
|
2012-10-28 07:16:46 +08: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 13:46:52 +08: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 10:04:20 +08:00
|
|
|
struct timer_list rsk_timer;
|
2006-11-16 18:30:37 +08: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 13:46:52 +08:00
|
|
|
struct sock *sk;
|
2015-05-04 12:34:46 +08:00
|
|
|
u32 *saved_syn;
|
2006-07-25 14:32:50 +08:00
|
|
|
u32 secid;
|
2006-11-09 07:04:09 +08: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 13:46:52 +08:00
|
|
|
};
|
|
|
|
|
2015-12-22 04:29:24 +08:00
|
|
|
static inline struct request_sock *inet_reqsk(const struct sock *sk)
|
2015-10-03 02:43:27 +08:00
|
|
|
{
|
|
|
|
return (struct request_sock *)sk;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct sock *req_to_sk(struct request_sock *req)
|
|
|
|
{
|
|
|
|
return (struct sock *)req;
|
|
|
|
}
|
|
|
|
|
2015-03-18 09:32:28 +08:00
|
|
|
static inline struct request_sock *
|
2015-10-05 12:08:11 +08: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 13:46:52 +08:00
|
|
|
{
|
2015-10-03 21:27:28 +08:00
|
|
|
struct request_sock *req;
|
|
|
|
|
|
|
|
req = kmem_cache_alloc(ops->slab, GFP_ATOMIC | __GFP_NOWARN);
|
2016-04-01 23:52:16 +08:00
|
|
|
if (!req)
|
|
|
|
return NULL;
|
|
|
|
req->rsk_listener = NULL;
|
|
|
|
if (attach_listener) {
|
|
|
|
if (unlikely(!atomic_inc_not_zero(&sk_listener->sk_refcnt))) {
|
|
|
|
kmem_cache_free(ops->slab, req);
|
|
|
|
return NULL;
|
2015-10-05 12:08:11 +08:00
|
|
|
}
|
2016-04-01 23:52:16 +08:00
|
|
|
req->rsk_listener = sk_listener;
|
2015-03-18 09:32:28 +08:00
|
|
|
}
|
2016-04-01 23:52:16 +08: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;
|
|
|
|
atomic_set(&req->rsk_refcnt, 0);
|
|
|
|
|
[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 13:46:52 +08:00
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
2005-06-19 13:47:21 +08: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 13:46:52 +08:00
|
|
|
{
|
2015-03-16 12:12:16 +08:00
|
|
|
/* temporary debugging */
|
|
|
|
WARN_ON_ONCE(atomic_read(&req->rsk_refcnt) != 0);
|
|
|
|
|
2005-06-19 13:47:21 +08:00
|
|
|
req->rsk_ops->destructor(req);
|
2015-03-18 09:32:28 +08:00
|
|
|
if (req->rsk_listener)
|
|
|
|
sock_put(req->rsk_listener);
|
2015-05-04 12:34:46 +08:00
|
|
|
kfree(req->saved_syn);
|
2015-03-16 12:12:16 +08: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 13:46:52 +08:00
|
|
|
}
|
|
|
|
|
2015-03-13 07:44:06 +08:00
|
|
|
static inline void reqsk_put(struct request_sock *req)
|
|
|
|
{
|
|
|
|
if (atomic_dec_and_test(&req->rsk_refcnt))
|
|
|
|
reqsk_free(req);
|
|
|
|
}
|
|
|
|
|
2012-08-31 20:29:11 +08: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 */
|
|
|
|
};
|
|
|
|
|
2005-06-19 13:47:59 +08: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 11:11:56 +08:00
|
|
|
* @rskq_defer_accept - User waits for some data after accept()
|
2005-06-19 13:47:59 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct request_sock_queue {
|
2015-10-03 02:43:23 +08:00
|
|
|
spinlock_t rskq_lock;
|
|
|
|
u8 rskq_defer_accept;
|
2015-10-03 02:43:37 +08:00
|
|
|
|
2015-10-03 02:43:25 +08:00
|
|
|
u32 synflood_warned;
|
2015-10-03 02:43:24 +08:00
|
|
|
atomic_t qlen;
|
|
|
|
atomic_t young;
|
|
|
|
|
2005-06-19 13:47:59 +08:00
|
|
|
struct request_sock *rskq_accept_head;
|
|
|
|
struct request_sock *rskq_accept_tail;
|
2015-09-29 22:42:52 +08:00
|
|
|
struct fastopen_queue fastopenq; /* Check max_qlen != 0 to determine
|
|
|
|
* if TFO is enabled.
|
2012-08-31 20:29:11 +08:00
|
|
|
*/
|
2005-06-19 13:47:59 +08:00
|
|
|
};
|
|
|
|
|
2015-10-03 02:43:37 +08:00
|
|
|
void reqsk_queue_alloc(struct request_sock_queue *queue);
|
2005-06-19 13:47:59 +08:00
|
|
|
|
2013-09-23 01:32:20 +08:00
|
|
|
void reqsk_fastopen_remove(struct sock *sk, struct request_sock *req,
|
|
|
|
bool reset);
|
2005-08-10 10:33:31 +08:00
|
|
|
|
2015-10-03 02:43:23 +08:00
|
|
|
static inline bool reqsk_queue_empty(const struct request_sock_queue *queue)
|
2005-06-19 13:47:59 +08:00
|
|
|
{
|
|
|
|
return queue->rskq_accept_head == NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-03 02:43:23 +08:00
|
|
|
static inline struct request_sock *reqsk_queue_remove(struct request_sock_queue *queue,
|
|
|
|
struct sock *parent)
|
2005-06-19 13:47:59 +08:00
|
|
|
{
|
2015-10-03 02:43:23 +08:00
|
|
|
struct request_sock *req;
|
2005-06-19 13:47:59 +08:00
|
|
|
|
2015-10-03 02:43:23 +08: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 13:47:59 +08: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 10:04:20 +08:00
|
|
|
static inline void reqsk_queue_removed(struct request_sock_queue *queue,
|
|
|
|
const struct request_sock *req)
|
2005-06-19 13:47:59 +08:00
|
|
|
{
|
2012-10-28 07:16:46 +08:00
|
|
|
if (req->num_timeout == 0)
|
2015-10-03 02:43:24 +08:00
|
|
|
atomic_dec(&queue->young);
|
|
|
|
atomic_dec(&queue->qlen);
|
2005-06-19 13:47:59 +08: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 10:04:20 +08:00
|
|
|
static inline void reqsk_queue_added(struct request_sock_queue *queue)
|
2005-06-19 13:47:59 +08:00
|
|
|
{
|
2015-10-03 02:43:24 +08:00
|
|
|
atomic_inc(&queue->young);
|
|
|
|
atomic_inc(&queue->qlen);
|
2005-06-19 13:47:59 +08: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 10:04:20 +08:00
|
|
|
static inline int reqsk_queue_len(const struct request_sock_queue *queue)
|
2005-06-19 13:47:59 +08:00
|
|
|
{
|
2015-10-03 02:43:24 +08:00
|
|
|
return atomic_read(&queue->qlen);
|
2005-06-19 13:47:59 +08: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 10:04:20 +08:00
|
|
|
static inline int reqsk_queue_len_young(const struct request_sock_queue *queue)
|
2005-06-19 13:47:59 +08:00
|
|
|
{
|
2015-10-03 02:43:24 +08: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 10:04:20 +08:00
|
|
|
}
|
2015-03-18 09:32:31 +08: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 13:46:52 +08:00
|
|
|
#endif /* _REQUEST_SOCK_H */
|