diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2007-04-19 23:29:13 -0400 |
|---|---|---|
| committer | David S. Miller <davem@sunset.davemloft.net> | 2007-04-26 01:26:28 -0400 |
| commit | 27a884dc3cb63b93c2b3b643f5b31eed5f8a4d26 (patch) | |
| tree | 5a267e40f9b94014be38dad5de0a52b6628834e0 /include | |
| parent | be8bd86321fa7f06359d866ef61fb4d2f3e9dce9 (diff) | |
[SK_BUFF]: Convert skb->tail to sk_buff_data_t
So that it is also an offset from skb->head, reduces its size from 8 to 4 bytes
on 64bit architectures, allowing us to combine the 4 bytes hole left by the
layer headers conversion, reducing struct sk_buff size to 256 bytes, i.e. 4
64byte cachelines, and since the sk_buff slab cache is SLAB_HWCACHE_ALIGN...
:-)
Many calculations that previously required that skb->{transport,network,
mac}_header be first converted to a pointer now can be done directly, being
meaningful as offsets or pointers.
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/netfilter/nfnetlink.h | 4 | ||||
| -rw-r--r-- | include/linux/netlink.h | 2 | ||||
| -rw-r--r-- | include/linux/rtnetlink.h | 6 | ||||
| -rw-r--r-- | include/linux/skbuff.h | 57 | ||||
| -rw-r--r-- | include/net/inet_ecn.h | 6 | ||||
| -rw-r--r-- | include/net/netlink.h | 8 | ||||
| -rw-r--r-- | include/net/pkt_cls.h | 2 |
7 files changed, 58 insertions, 27 deletions
diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h index 6179648a014e..e1ea5dfbbbd4 100644 --- a/include/linux/netfilter/nfnetlink.h +++ b/include/linux/netfilter/nfnetlink.h | |||
| @@ -62,11 +62,11 @@ struct nfattr | |||
| 62 | #define NFA_DATA(nfa) ((void *)(((char *)(nfa)) + NFA_LENGTH(0))) | 62 | #define NFA_DATA(nfa) ((void *)(((char *)(nfa)) + NFA_LENGTH(0))) |
| 63 | #define NFA_PAYLOAD(nfa) ((int)((nfa)->nfa_len) - NFA_LENGTH(0)) | 63 | #define NFA_PAYLOAD(nfa) ((int)((nfa)->nfa_len) - NFA_LENGTH(0)) |
| 64 | #define NFA_NEST(skb, type) \ | 64 | #define NFA_NEST(skb, type) \ |
| 65 | ({ struct nfattr *__start = (struct nfattr *) (skb)->tail; \ | 65 | ({ struct nfattr *__start = (struct nfattr *)skb_tail_pointer(skb); \ |
| 66 | NFA_PUT(skb, (NFNL_NFA_NEST | type), 0, NULL); \ | 66 | NFA_PUT(skb, (NFNL_NFA_NEST | type), 0, NULL); \ |
| 67 | __start; }) | 67 | __start; }) |
| 68 | #define NFA_NEST_END(skb, start) \ | 68 | #define NFA_NEST_END(skb, start) \ |
| 69 | ({ (start)->nfa_len = ((skb)->tail - (unsigned char *) (start)); \ | 69 | ({ (start)->nfa_len = skb_tail_pointer(skb) - (unsigned char *)(start); \ |
| 70 | (skb)->len; }) | 70 | (skb)->len; }) |
| 71 | #define NFA_NEST_CANCEL(skb, start) \ | 71 | #define NFA_NEST_CANCEL(skb, start) \ |
| 72 | ({ if (start) \ | 72 | ({ if (start) \ |
diff --git a/include/linux/netlink.h b/include/linux/netlink.h index a9d3ad5bc80f..68a632b372ec 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h | |||
| @@ -229,7 +229,7 @@ __nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len, int flags) | |||
| 229 | (cb)->nlh->nlmsg_seq, type, len, flags) | 229 | (cb)->nlh->nlmsg_seq, type, len, flags) |
| 230 | 230 | ||
| 231 | #define NLMSG_END(skb, nlh) \ | 231 | #define NLMSG_END(skb, nlh) \ |
| 232 | ({ (nlh)->nlmsg_len = (skb)->tail - (unsigned char *) (nlh); \ | 232 | ({ (nlh)->nlmsg_len = skb_tail_pointer(skb) - (unsigned char *)(nlh); \ |
| 233 | (skb)->len; }) | 233 | (skb)->len; }) |
| 234 | 234 | ||
| 235 | #define NLMSG_CANCEL(skb, nlh) \ | 235 | #define NLMSG_CANCEL(skb, nlh) \ |
diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h index 4a629ea70cc4..3a4cb242ecd2 100644 --- a/include/linux/rtnetlink.h +++ b/include/linux/rtnetlink.h | |||
| @@ -605,7 +605,7 @@ extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const voi | |||
| 605 | 605 | ||
| 606 | #define RTA_PUT_NOHDR(skb, attrlen, data) \ | 606 | #define RTA_PUT_NOHDR(skb, attrlen, data) \ |
| 607 | ({ RTA_APPEND(skb, RTA_ALIGN(attrlen), data); \ | 607 | ({ RTA_APPEND(skb, RTA_ALIGN(attrlen), data); \ |
| 608 | memset(skb->tail - (RTA_ALIGN(attrlen) - attrlen), 0, \ | 608 | memset(skb_tail_pointer(skb) - (RTA_ALIGN(attrlen) - attrlen), 0, \ |
| 609 | RTA_ALIGN(attrlen) - attrlen); }) | 609 | RTA_ALIGN(attrlen) - attrlen); }) |
| 610 | 610 | ||
| 611 | #define RTA_PUT_U8(skb, attrtype, value) \ | 611 | #define RTA_PUT_U8(skb, attrtype, value) \ |
| @@ -637,12 +637,12 @@ extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const voi | |||
| 637 | RTA_PUT(skb, attrtype, 0, NULL); | 637 | RTA_PUT(skb, attrtype, 0, NULL); |
| 638 | 638 | ||
| 639 | #define RTA_NEST(skb, type) \ | 639 | #define RTA_NEST(skb, type) \ |
| 640 | ({ struct rtattr *__start = (struct rtattr *) (skb)->tail; \ | 640 | ({ struct rtattr *__start = (struct rtattr *)skb_tail_pointer(skb); \ |
| 641 | RTA_PUT(skb, type, 0, NULL); \ | 641 | RTA_PUT(skb, type, 0, NULL); \ |
| 642 | __start; }) | 642 | __start; }) |
| 643 | 643 | ||
| 644 | #define RTA_NEST_END(skb, start) \ | 644 | #define RTA_NEST_END(skb, start) \ |
| 645 | ({ (start)->rta_len = ((skb)->tail - (unsigned char *) (start)); \ | 645 | ({ (start)->rta_len = skb_tail_pointer(skb) - (unsigned char *)(start); \ |
| 646 | (skb)->len; }) | 646 | (skb)->len; }) |
| 647 | 647 | ||
| 648 | #define RTA_NEST_CANCEL(skb, start) \ | 648 | #define RTA_NEST_CANCEL(skb, start) \ |
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 2e7405500626..e1c2392ecb56 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h | |||
| @@ -246,9 +246,6 @@ struct sk_buff { | |||
| 246 | int iif; | 246 | int iif; |
| 247 | /* 4 byte hole on 64 bit*/ | 247 | /* 4 byte hole on 64 bit*/ |
| 248 | 248 | ||
| 249 | sk_buff_data_t transport_header; | ||
| 250 | sk_buff_data_t network_header; | ||
| 251 | sk_buff_data_t mac_header; | ||
| 252 | struct dst_entry *dst; | 249 | struct dst_entry *dst; |
| 253 | struct sec_path *sp; | 250 | struct sec_path *sp; |
| 254 | 251 | ||
| @@ -303,13 +300,16 @@ struct sk_buff { | |||
| 303 | 300 | ||
| 304 | __u32 mark; | 301 | __u32 mark; |
| 305 | 302 | ||
| 303 | sk_buff_data_t transport_header; | ||
| 304 | sk_buff_data_t network_header; | ||
| 305 | sk_buff_data_t mac_header; | ||
| 306 | /* These elements must be at the end, see alloc_skb() for details. */ | 306 | /* These elements must be at the end, see alloc_skb() for details. */ |
| 307 | unsigned int truesize; | 307 | sk_buff_data_t tail; |
| 308 | atomic_t users; | ||
| 309 | unsigned char *head, | 308 | unsigned char *head, |
| 310 | *data, | 309 | *data, |
| 311 | *tail, | ||
| 312 | *end; | 310 | *end; |
| 311 | unsigned int truesize; | ||
| 312 | atomic_t users; | ||
| 313 | }; | 313 | }; |
| 314 | 314 | ||
| 315 | #ifdef __KERNEL__ | 315 | #ifdef __KERNEL__ |
| @@ -812,12 +812,45 @@ static inline void skb_fill_page_desc(struct sk_buff *skb, int i, | |||
| 812 | #define SKB_FRAG_ASSERT(skb) BUG_ON(skb_shinfo(skb)->frag_list) | 812 | #define SKB_FRAG_ASSERT(skb) BUG_ON(skb_shinfo(skb)->frag_list) |
| 813 | #define SKB_LINEAR_ASSERT(skb) BUG_ON(skb_is_nonlinear(skb)) | 813 | #define SKB_LINEAR_ASSERT(skb) BUG_ON(skb_is_nonlinear(skb)) |
| 814 | 814 | ||
| 815 | #ifdef NET_SKBUFF_DATA_USES_OFFSET | ||
| 816 | static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb) | ||
| 817 | { | ||
| 818 | return skb->head + skb->tail; | ||
| 819 | } | ||
| 820 | |||
| 821 | static inline void skb_reset_tail_pointer(struct sk_buff *skb) | ||
| 822 | { | ||
| 823 | skb->tail = skb->data - skb->head; | ||
| 824 | } | ||
| 825 | |||
| 826 | static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset) | ||
| 827 | { | ||
| 828 | skb_reset_tail_pointer(skb); | ||
| 829 | skb->tail += offset; | ||
| 830 | } | ||
| 831 | #else /* NET_SKBUFF_DATA_USES_OFFSET */ | ||
| 832 | static inline unsigned char *skb_tail_pointer(const struct sk_buff *skb) | ||
| 833 | { | ||
| 834 | return skb->tail; | ||
| 835 | } | ||
| 836 | |||
| 837 | static inline void skb_reset_tail_pointer(struct sk_buff *skb) | ||
| 838 | { | ||
| 839 | skb->tail = skb->data; | ||
| 840 | } | ||
| 841 | |||
| 842 | static inline void skb_set_tail_pointer(struct sk_buff *skb, const int offset) | ||
| 843 | { | ||
| 844 | skb->tail = skb->data + offset; | ||
| 845 | } | ||
| 846 | #endif /* NET_SKBUFF_DATA_USES_OFFSET */ | ||
| 847 | |||
| 815 | /* | 848 | /* |
| 816 | * Add data to an sk_buff | 849 | * Add data to an sk_buff |
| 817 | */ | 850 | */ |
| 818 | static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len) | 851 | static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len) |
| 819 | { | 852 | { |
| 820 | unsigned char *tmp = skb->tail; | 853 | unsigned char *tmp = skb_tail_pointer(skb); |
| 821 | SKB_LINEAR_ASSERT(skb); | 854 | SKB_LINEAR_ASSERT(skb); |
| 822 | skb->tail += len; | 855 | skb->tail += len; |
| 823 | skb->len += len; | 856 | skb->len += len; |
| @@ -835,11 +868,11 @@ static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len) | |||
| 835 | */ | 868 | */ |
| 836 | static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len) | 869 | static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len) |
| 837 | { | 870 | { |
| 838 | unsigned char *tmp = skb->tail; | 871 | unsigned char *tmp = skb_tail_pointer(skb); |
| 839 | SKB_LINEAR_ASSERT(skb); | 872 | SKB_LINEAR_ASSERT(skb); |
| 840 | skb->tail += len; | 873 | skb->tail += len; |
| 841 | skb->len += len; | 874 | skb->len += len; |
| 842 | if (unlikely(skb->tail>skb->end)) | 875 | if (unlikely(skb_tail_pointer(skb) > skb->end)) |
| 843 | skb_over_panic(skb, len, current_text_addr()); | 876 | skb_over_panic(skb, len, current_text_addr()); |
| 844 | return tmp; | 877 | return tmp; |
| 845 | } | 878 | } |
| @@ -935,7 +968,7 @@ static inline int skb_headroom(const struct sk_buff *skb) | |||
| 935 | */ | 968 | */ |
| 936 | static inline int skb_tailroom(const struct sk_buff *skb) | 969 | static inline int skb_tailroom(const struct sk_buff *skb) |
| 937 | { | 970 | { |
| 938 | return skb_is_nonlinear(skb) ? 0 : skb->end - skb->tail; | 971 | return skb_is_nonlinear(skb) ? 0 : skb->end - skb_tail_pointer(skb); |
| 939 | } | 972 | } |
| 940 | 973 | ||
| 941 | /** | 974 | /** |
| @@ -1127,8 +1160,8 @@ static inline void __skb_trim(struct sk_buff *skb, unsigned int len) | |||
| 1127 | WARN_ON(1); | 1160 | WARN_ON(1); |
| 1128 | return; | 1161 | return; |
| 1129 | } | 1162 | } |
| 1130 | skb->len = len; | 1163 | skb->len = len; |
| 1131 | skb->tail = skb->data + len; | 1164 | skb_set_tail_pointer(skb, len); |
| 1132 | } | 1165 | } |
| 1133 | 1166 | ||
| 1134 | /** | 1167 | /** |
diff --git a/include/net/inet_ecn.h b/include/net/inet_ecn.h index 06a2c69a89e5..de8399a79774 100644 --- a/include/net/inet_ecn.h +++ b/include/net/inet_ecn.h | |||
| @@ -114,14 +114,12 @@ static inline int INET_ECN_set_ce(struct sk_buff *skb) | |||
| 114 | { | 114 | { |
| 115 | switch (skb->protocol) { | 115 | switch (skb->protocol) { |
| 116 | case __constant_htons(ETH_P_IP): | 116 | case __constant_htons(ETH_P_IP): |
| 117 | if (skb_network_header(skb) + sizeof(struct iphdr) <= | 117 | if (skb->network_header + sizeof(struct iphdr) <= skb->tail) |
| 118 | skb->tail) | ||
| 119 | return IP_ECN_set_ce(ip_hdr(skb)); | 118 | return IP_ECN_set_ce(ip_hdr(skb)); |
| 120 | break; | 119 | break; |
| 121 | 120 | ||
| 122 | case __constant_htons(ETH_P_IPV6): | 121 | case __constant_htons(ETH_P_IPV6): |
| 123 | if (skb_network_header(skb) + sizeof(struct ipv6hdr) <= | 122 | if (skb->network_header + sizeof(struct ipv6hdr) <= skb->tail) |
| 124 | skb->tail) | ||
| 125 | return IP6_ECN_set_ce(ipv6_hdr(skb)); | 123 | return IP6_ECN_set_ce(ipv6_hdr(skb)); |
| 126 | break; | 124 | break; |
| 127 | } | 125 | } |
diff --git a/include/net/netlink.h b/include/net/netlink.h index bcaf67b7a19d..2c7ab107f20d 100644 --- a/include/net/netlink.h +++ b/include/net/netlink.h | |||
| @@ -525,7 +525,7 @@ static inline struct sk_buff *nlmsg_new(size_t payload, gfp_t flags) | |||
| 525 | */ | 525 | */ |
| 526 | static inline int nlmsg_end(struct sk_buff *skb, struct nlmsghdr *nlh) | 526 | static inline int nlmsg_end(struct sk_buff *skb, struct nlmsghdr *nlh) |
| 527 | { | 527 | { |
| 528 | nlh->nlmsg_len = skb->tail - (unsigned char *) nlh; | 528 | nlh->nlmsg_len = skb_tail_pointer(skb) - (unsigned char *)nlh; |
| 529 | 529 | ||
| 530 | return skb->len; | 530 | return skb->len; |
| 531 | } | 531 | } |
| @@ -538,7 +538,7 @@ static inline int nlmsg_end(struct sk_buff *skb, struct nlmsghdr *nlh) | |||
| 538 | */ | 538 | */ |
| 539 | static inline void *nlmsg_get_pos(struct sk_buff *skb) | 539 | static inline void *nlmsg_get_pos(struct sk_buff *skb) |
| 540 | { | 540 | { |
| 541 | return skb->tail; | 541 | return skb_tail_pointer(skb); |
| 542 | } | 542 | } |
| 543 | 543 | ||
| 544 | /** | 544 | /** |
| @@ -940,7 +940,7 @@ static inline unsigned long nla_get_msecs(struct nlattr *nla) | |||
| 940 | */ | 940 | */ |
| 941 | static inline struct nlattr *nla_nest_start(struct sk_buff *skb, int attrtype) | 941 | static inline struct nlattr *nla_nest_start(struct sk_buff *skb, int attrtype) |
| 942 | { | 942 | { |
| 943 | struct nlattr *start = (struct nlattr *) skb->tail; | 943 | struct nlattr *start = (struct nlattr *)skb_tail_pointer(skb); |
| 944 | 944 | ||
| 945 | if (nla_put(skb, attrtype, 0, NULL) < 0) | 945 | if (nla_put(skb, attrtype, 0, NULL) < 0) |
| 946 | return NULL; | 946 | return NULL; |
| @@ -960,7 +960,7 @@ static inline struct nlattr *nla_nest_start(struct sk_buff *skb, int attrtype) | |||
| 960 | */ | 960 | */ |
| 961 | static inline int nla_nest_end(struct sk_buff *skb, struct nlattr *start) | 961 | static inline int nla_nest_end(struct sk_buff *skb, struct nlattr *start) |
| 962 | { | 962 | { |
| 963 | start->nla_len = skb->tail - (unsigned char *) start; | 963 | start->nla_len = skb_tail_pointer(skb) - (unsigned char *)start; |
| 964 | return skb->len; | 964 | return skb->len; |
| 965 | } | 965 | } |
| 966 | 966 | ||
diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index dcb3a91f1364..4129df708079 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h | |||
| @@ -337,7 +337,7 @@ static inline unsigned char * tcf_get_base_ptr(struct sk_buff *skb, int layer) | |||
| 337 | static inline int tcf_valid_offset(const struct sk_buff *skb, | 337 | static inline int tcf_valid_offset(const struct sk_buff *skb, |
| 338 | const unsigned char *ptr, const int len) | 338 | const unsigned char *ptr, const int len) |
| 339 | { | 339 | { |
| 340 | return unlikely((ptr + len) < skb->tail && ptr > skb->head); | 340 | return unlikely((ptr + len) < skb_tail_pointer(skb) && ptr > skb->head); |
| 341 | } | 341 | } |
| 342 | 342 | ||
| 343 | #ifdef CONFIG_NET_CLS_IND | 343 | #ifdef CONFIG_NET_CLS_IND |
