Skip to content

Commit 1a37e41

Browse files
hormsdavem330
authored andcommitted
net: Use 16bits for *_headers fields of struct skbuff
In order to mitigate ongoing incresase in the size of struct skbuff use 16 bit integer offsets rather than pointers for inner_*_headers. This appears to reduce the size of struct skbuff from 0xd0 to 0xc0 bytes on x86_64 with the following all unset. CONFIG_XFRM CONFIG_NF_CONNTRACK CONFIG_NF_CONNTRACK_MODULE NET_SKBUFF_NF_DEFRAG_NEEDED CONFIG_BRIDGE_NETFILTER CONFIG_NET_SCHED CONFIG_IPV6_NDISC_NODETYPE CONFIG_NET_DMA CONFIG_NETWORK_SECMARK Signed-off-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 50ab731 commit 1a37e41

File tree

1 file changed

+6
-113
lines changed

1 file changed

+6
-113
lines changed

include/linux/skbuff.h

Lines changed: 6 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -509,12 +509,12 @@ struct sk_buff {
509509
__u32 reserved_tailroom;
510510
};
511511

512-
sk_buff_data_t inner_transport_header;
513-
sk_buff_data_t inner_network_header;
514-
sk_buff_data_t inner_mac_header;
515-
sk_buff_data_t transport_header;
516-
sk_buff_data_t network_header;
517-
sk_buff_data_t mac_header;
512+
__u16 inner_transport_header;
513+
__u16 inner_network_header;
514+
__u16 inner_mac_header;
515+
__u16 transport_header;
516+
__u16 network_header;
517+
__u16 mac_header;
518518
/* These elements must be at the end, see alloc_skb() for details. */
519519
sk_buff_data_t tail;
520520
sk_buff_data_t end;
@@ -1527,7 +1527,6 @@ static inline void skb_reset_mac_len(struct sk_buff *skb)
15271527
skb->mac_len = skb->network_header - skb->mac_header;
15281528
}
15291529

1530-
#ifdef NET_SKBUFF_DATA_USES_OFFSET
15311530
static inline unsigned char *skb_inner_transport_header(const struct sk_buff
15321531
*skb)
15331532
{
@@ -1638,112 +1637,6 @@ static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
16381637
skb->mac_header += offset;
16391638
}
16401639

1641-
#else /* NET_SKBUFF_DATA_USES_OFFSET */
1642-
static inline unsigned char *skb_inner_transport_header(const struct sk_buff
1643-
*skb)
1644-
{
1645-
return skb->inner_transport_header;
1646-
}
1647-
1648-
static inline void skb_reset_inner_transport_header(struct sk_buff *skb)
1649-
{
1650-
skb->inner_transport_header = skb->data;
1651-
}
1652-
1653-
static inline void skb_set_inner_transport_header(struct sk_buff *skb,
1654-
const int offset)
1655-
{
1656-
skb->inner_transport_header = skb->data + offset;
1657-
}
1658-
1659-
static inline unsigned char *skb_inner_network_header(const struct sk_buff *skb)
1660-
{
1661-
return skb->inner_network_header;
1662-
}
1663-
1664-
static inline void skb_reset_inner_network_header(struct sk_buff *skb)
1665-
{
1666-
skb->inner_network_header = skb->data;
1667-
}
1668-
1669-
static inline void skb_set_inner_network_header(struct sk_buff *skb,
1670-
const int offset)
1671-
{
1672-
skb->inner_network_header = skb->data + offset;
1673-
}
1674-
1675-
static inline unsigned char *skb_inner_mac_header(const struct sk_buff *skb)
1676-
{
1677-
return skb->inner_mac_header;
1678-
}
1679-
1680-
static inline void skb_reset_inner_mac_header(struct sk_buff *skb)
1681-
{
1682-
skb->inner_mac_header = skb->data;
1683-
}
1684-
1685-
static inline void skb_set_inner_mac_header(struct sk_buff *skb,
1686-
const int offset)
1687-
{
1688-
skb->inner_mac_header = skb->data + offset;
1689-
}
1690-
static inline bool skb_transport_header_was_set(const struct sk_buff *skb)
1691-
{
1692-
return skb->transport_header != NULL;
1693-
}
1694-
1695-
static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
1696-
{
1697-
return skb->transport_header;
1698-
}
1699-
1700-
static inline void skb_reset_transport_header(struct sk_buff *skb)
1701-
{
1702-
skb->transport_header = skb->data;
1703-
}
1704-
1705-
static inline void skb_set_transport_header(struct sk_buff *skb,
1706-
const int offset)
1707-
{
1708-
skb->transport_header = skb->data + offset;
1709-
}
1710-
1711-
static inline unsigned char *skb_network_header(const struct sk_buff *skb)
1712-
{
1713-
return skb->network_header;
1714-
}
1715-
1716-
static inline void skb_reset_network_header(struct sk_buff *skb)
1717-
{
1718-
skb->network_header = skb->data;
1719-
}
1720-
1721-
static inline void skb_set_network_header(struct sk_buff *skb, const int offset)
1722-
{
1723-
skb->network_header = skb->data + offset;
1724-
}
1725-
1726-
static inline unsigned char *skb_mac_header(const struct sk_buff *skb)
1727-
{
1728-
return skb->mac_header;
1729-
}
1730-
1731-
static inline int skb_mac_header_was_set(const struct sk_buff *skb)
1732-
{
1733-
return skb->mac_header != NULL;
1734-
}
1735-
1736-
static inline void skb_reset_mac_header(struct sk_buff *skb)
1737-
{
1738-
skb->mac_header = skb->data;
1739-
}
1740-
1741-
static inline void skb_set_mac_header(struct sk_buff *skb, const int offset)
1742-
{
1743-
skb->mac_header = skb->data + offset;
1744-
}
1745-
#endif /* NET_SKBUFF_DATA_USES_OFFSET */
1746-
17471640
static inline void skb_probe_transport_header(struct sk_buff *skb,
17481641
const int offset_hint)
17491642
{

0 commit comments

Comments
 (0)