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