diff options
author | Arnaldo Carvalho de Melo <acme@ghostprotocols.net> | 2005-06-19 01:46:52 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2005-06-19 01:46:52 -0400 |
commit | 2e6599cb899ba4b133f42cbf9d2b1883d2dc583a (patch) | |
tree | b5d4fcca4d2a515fc3d3d20cefaaeebd8dbf661f /include/net | |
parent | 1944972d3bb651474a5021c9da8d0166ae19f1eb (diff) |
[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>
Diffstat (limited to 'include/net')
-rw-r--r-- | include/net/request_sock.h | 77 | ||||
-rw-r--r-- | include/net/sock.h | 4 | ||||
-rw-r--r-- | include/net/tcp.h | 87 | ||||
-rw-r--r-- | include/net/tcp_ecn.h | 7 |
4 files changed, 96 insertions, 79 deletions
diff --git a/include/net/request_sock.h b/include/net/request_sock.h new file mode 100644 index 000000000000..9502f5587931 --- /dev/null +++ b/include/net/request_sock.h | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | * NET Generic infrastructure for Network protocols. | ||
3 | * | ||
4 | * Definitions for request_sock | ||
5 | * | ||
6 | * Authors: Arnaldo Carvalho de Melo <acme@conectiva.com.br> | ||
7 | * | ||
8 | * From code originally in include/net/tcp.h | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version | ||
13 | * 2 of the License, or (at your option) any later version. | ||
14 | */ | ||
15 | #ifndef _REQUEST_SOCK_H | ||
16 | #define _REQUEST_SOCK_H | ||
17 | |||
18 | #include <linux/slab.h> | ||
19 | #include <linux/types.h> | ||
20 | #include <net/sock.h> | ||
21 | |||
22 | struct open_request; | ||
23 | struct sk_buff; | ||
24 | struct dst_entry; | ||
25 | struct proto; | ||
26 | |||
27 | struct or_calltable { | ||
28 | int family; | ||
29 | kmem_cache_t *slab; | ||
30 | int obj_size; | ||
31 | int (*rtx_syn_ack)(struct sock *sk, | ||
32 | struct open_request *req, | ||
33 | struct dst_entry *dst); | ||
34 | void (*send_ack)(struct sk_buff *skb, | ||
35 | struct open_request *req); | ||
36 | void (*send_reset)(struct sk_buff *skb); | ||
37 | void (*destructor)(struct open_request *req); | ||
38 | }; | ||
39 | |||
40 | /* struct open_request - mini sock to represent a connection request | ||
41 | */ | ||
42 | struct open_request { | ||
43 | struct open_request *dl_next; /* Must be first member! */ | ||
44 | u16 mss; | ||
45 | u8 retrans; | ||
46 | u8 __pad; | ||
47 | /* The following two fields can be easily recomputed I think -AK */ | ||
48 | u32 window_clamp; /* window clamp at creation time */ | ||
49 | u32 rcv_wnd; /* rcv_wnd offered first time */ | ||
50 | u32 ts_recent; | ||
51 | unsigned long expires; | ||
52 | struct or_calltable *class; | ||
53 | struct sock *sk; | ||
54 | }; | ||
55 | |||
56 | static inline struct open_request *tcp_openreq_alloc(struct or_calltable *class) | ||
57 | { | ||
58 | struct open_request *req = kmem_cache_alloc(class->slab, SLAB_ATOMIC); | ||
59 | |||
60 | if (req != NULL) | ||
61 | req->class = class; | ||
62 | |||
63 | return req; | ||
64 | } | ||
65 | |||
66 | static inline void tcp_openreq_fastfree(struct open_request *req) | ||
67 | { | ||
68 | kmem_cache_free(req->class->slab, req); | ||
69 | } | ||
70 | |||
71 | static inline void tcp_openreq_free(struct open_request *req) | ||
72 | { | ||
73 | req->class->destructor(req); | ||
74 | tcp_openreq_fastfree(req); | ||
75 | } | ||
76 | |||
77 | #endif /* _REQUEST_SOCK_H */ | ||
diff --git a/include/net/sock.h b/include/net/sock.h index a9ef3a6a13f3..6919276af8af 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
@@ -484,6 +484,8 @@ extern void sk_stream_kill_queues(struct sock *sk); | |||
484 | 484 | ||
485 | extern int sk_wait_data(struct sock *sk, long *timeo); | 485 | extern int sk_wait_data(struct sock *sk, long *timeo); |
486 | 486 | ||
487 | struct or_calltable; | ||
488 | |||
487 | /* Networking protocol blocks we attach to sockets. | 489 | /* Networking protocol blocks we attach to sockets. |
488 | * socket layer -> transport layer interface | 490 | * socket layer -> transport layer interface |
489 | * transport -> network interface is defined by struct inet_proto | 491 | * transport -> network interface is defined by struct inet_proto |
@@ -547,6 +549,8 @@ struct proto { | |||
547 | kmem_cache_t *slab; | 549 | kmem_cache_t *slab; |
548 | unsigned int obj_size; | 550 | unsigned int obj_size; |
549 | 551 | ||
552 | struct or_calltable *rsk_prot; | ||
553 | |||
550 | struct module *owner; | 554 | struct module *owner; |
551 | 555 | ||
552 | char name[32]; | 556 | char name[32]; |
diff --git a/include/net/tcp.h b/include/net/tcp.h index e71f8ba3e101..d438ba566b89 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/cache.h> | 31 | #include <linux/cache.h> |
32 | #include <linux/percpu.h> | 32 | #include <linux/percpu.h> |
33 | #include <net/checksum.h> | 33 | #include <net/checksum.h> |
34 | #include <net/request_sock.h> | ||
34 | #include <net/sock.h> | 35 | #include <net/sock.h> |
35 | #include <net/snmp.h> | 36 | #include <net/snmp.h> |
36 | #include <net/ip.h> | 37 | #include <net/ip.h> |
@@ -613,74 +614,6 @@ extern atomic_t tcp_memory_allocated; | |||
613 | extern atomic_t tcp_sockets_allocated; | 614 | extern atomic_t tcp_sockets_allocated; |
614 | extern int tcp_memory_pressure; | 615 | extern int tcp_memory_pressure; |
615 | 616 | ||
616 | struct open_request; | ||
617 | |||
618 | struct or_calltable { | ||
619 | int family; | ||
620 | int (*rtx_syn_ack) (struct sock *sk, struct open_request *req, struct dst_entry*); | ||
621 | void (*send_ack) (struct sk_buff *skb, struct open_request *req); | ||
622 | void (*destructor) (struct open_request *req); | ||
623 | void (*send_reset) (struct sk_buff *skb); | ||
624 | }; | ||
625 | |||
626 | struct tcp_v4_open_req { | ||
627 | __u32 loc_addr; | ||
628 | __u32 rmt_addr; | ||
629 | struct ip_options *opt; | ||
630 | }; | ||
631 | |||
632 | #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) | ||
633 | struct tcp_v6_open_req { | ||
634 | struct in6_addr loc_addr; | ||
635 | struct in6_addr rmt_addr; | ||
636 | struct sk_buff *pktopts; | ||
637 | int iif; | ||
638 | }; | ||
639 | #endif | ||
640 | |||
641 | /* this structure is too big */ | ||
642 | struct open_request { | ||
643 | struct open_request *dl_next; /* Must be first member! */ | ||
644 | __u32 rcv_isn; | ||
645 | __u32 snt_isn; | ||
646 | __u16 rmt_port; | ||
647 | __u16 mss; | ||
648 | __u8 retrans; | ||
649 | __u8 __pad; | ||
650 | __u16 snd_wscale : 4, | ||
651 | rcv_wscale : 4, | ||
652 | tstamp_ok : 1, | ||
653 | sack_ok : 1, | ||
654 | wscale_ok : 1, | ||
655 | ecn_ok : 1, | ||
656 | acked : 1; | ||
657 | /* The following two fields can be easily recomputed I think -AK */ | ||
658 | __u32 window_clamp; /* window clamp at creation time */ | ||
659 | __u32 rcv_wnd; /* rcv_wnd offered first time */ | ||
660 | __u32 ts_recent; | ||
661 | unsigned long expires; | ||
662 | struct or_calltable *class; | ||
663 | struct sock *sk; | ||
664 | union { | ||
665 | struct tcp_v4_open_req v4_req; | ||
666 | #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) | ||
667 | struct tcp_v6_open_req v6_req; | ||
668 | #endif | ||
669 | } af; | ||
670 | }; | ||
671 | |||
672 | /* SLAB cache for open requests. */ | ||
673 | extern kmem_cache_t *tcp_openreq_cachep; | ||
674 | |||
675 | #define tcp_openreq_alloc() kmem_cache_alloc(tcp_openreq_cachep, SLAB_ATOMIC) | ||
676 | #define tcp_openreq_fastfree(req) kmem_cache_free(tcp_openreq_cachep, req) | ||
677 | |||
678 | static inline void tcp_openreq_free(struct open_request *req) | ||
679 | { | ||
680 | req->class->destructor(req); | ||
681 | tcp_openreq_fastfree(req); | ||
682 | } | ||
683 | |||
684 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | 617 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
685 | #define TCP_INET_FAMILY(fam) ((fam) == AF_INET) | 618 | #define TCP_INET_FAMILY(fam) ((fam) == AF_INET) |
686 | #else | 619 | #else |
@@ -1832,17 +1765,19 @@ static __inline__ void tcp_openreq_init(struct open_request *req, | |||
1832 | struct tcp_options_received *rx_opt, | 1765 | struct tcp_options_received *rx_opt, |
1833 | struct sk_buff *skb) | 1766 | struct sk_buff *skb) |
1834 | { | 1767 | { |
1768 | struct inet_request_sock *ireq = inet_rsk(req); | ||
1769 | |||
1835 | req->rcv_wnd = 0; /* So that tcp_send_synack() knows! */ | 1770 | req->rcv_wnd = 0; /* So that tcp_send_synack() knows! */ |
1836 | req->rcv_isn = TCP_SKB_CB(skb)->seq; | 1771 | tcp_rsk(req)->rcv_isn = TCP_SKB_CB(skb)->seq; |
1837 | req->mss = rx_opt->mss_clamp; | 1772 | req->mss = rx_opt->mss_clamp; |
1838 | req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0; | 1773 | req->ts_recent = rx_opt->saw_tstamp ? rx_opt->rcv_tsval : 0; |
1839 | req->tstamp_ok = rx_opt->tstamp_ok; | 1774 | ireq->tstamp_ok = rx_opt->tstamp_ok; |
1840 | req->sack_ok = rx_opt->sack_ok; | 1775 | ireq->sack_ok = rx_opt->sack_ok; |
1841 | req->snd_wscale = rx_opt->snd_wscale; | 1776 | ireq->snd_wscale = rx_opt->snd_wscale; |
1842 | req->wscale_ok = rx_opt->wscale_ok; | 1777 | ireq->wscale_ok = rx_opt->wscale_ok; |
1843 | req->acked = 0; | 1778 | ireq->acked = 0; |
1844 | req->ecn_ok = 0; | 1779 | ireq->ecn_ok = 0; |
1845 | req->rmt_port = skb->h.th->source; | 1780 | ireq->rmt_port = skb->h.th->source; |
1846 | } | 1781 | } |
1847 | 1782 | ||
1848 | extern void tcp_enter_memory_pressure(void); | 1783 | extern void tcp_enter_memory_pressure(void); |
diff --git a/include/net/tcp_ecn.h b/include/net/tcp_ecn.h index dc1456389a97..94ad970e844a 100644 --- a/include/net/tcp_ecn.h +++ b/include/net/tcp_ecn.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define _NET_TCP_ECN_H_ 1 | 2 | #define _NET_TCP_ECN_H_ 1 |
3 | 3 | ||
4 | #include <net/inet_ecn.h> | 4 | #include <net/inet_ecn.h> |
5 | #include <net/request_sock.h> | ||
5 | 6 | ||
6 | #define TCP_HP_BITS (~(TCP_RESERVED_BITS|TCP_FLAG_PSH)) | 7 | #define TCP_HP_BITS (~(TCP_RESERVED_BITS|TCP_FLAG_PSH)) |
7 | 8 | ||
@@ -40,7 +41,7 @@ static inline void TCP_ECN_send_syn(struct sock *sk, struct tcp_sock *tp, | |||
40 | static __inline__ void | 41 | static __inline__ void |
41 | TCP_ECN_make_synack(struct open_request *req, struct tcphdr *th) | 42 | TCP_ECN_make_synack(struct open_request *req, struct tcphdr *th) |
42 | { | 43 | { |
43 | if (req->ecn_ok) | 44 | if (inet_rsk(req)->ecn_ok) |
44 | th->ece = 1; | 45 | th->ece = 1; |
45 | } | 46 | } |
46 | 47 | ||
@@ -113,14 +114,14 @@ static inline int TCP_ECN_rcv_ecn_echo(struct tcp_sock *tp, struct tcphdr *th) | |||
113 | static inline void TCP_ECN_openreq_child(struct tcp_sock *tp, | 114 | static inline void TCP_ECN_openreq_child(struct tcp_sock *tp, |
114 | struct open_request *req) | 115 | struct open_request *req) |
115 | { | 116 | { |
116 | tp->ecn_flags = req->ecn_ok ? TCP_ECN_OK : 0; | 117 | tp->ecn_flags = inet_rsk(req)->ecn_ok ? TCP_ECN_OK : 0; |
117 | } | 118 | } |
118 | 119 | ||
119 | static __inline__ void | 120 | static __inline__ void |
120 | TCP_ECN_create_request(struct open_request *req, struct tcphdr *th) | 121 | TCP_ECN_create_request(struct open_request *req, struct tcphdr *th) |
121 | { | 122 | { |
122 | if (sysctl_tcp_ecn && th->ece && th->cwr) | 123 | if (sysctl_tcp_ecn && th->ece && th->cwr) |
123 | req->ecn_ok = 1; | 124 | inet_rsk(req)->ecn_ok = 1; |
124 | } | 125 | } |
125 | 126 | ||
126 | #endif | 127 | #endif |