Skip to content

Commit fbb192a

Browse files
committed
Merge branch 'skbuff-bitfields'
Jakub Kicinski says: ==================== net: skbuff: hide some bitfield members There is a number of protocol or subsystem specific fields in struct sk_buff which are only accessed by one subsystem. We can wrap them in ifdefs with minimal code impact. This gives us a better chance to save a 2B and a 4B holes resulting with the following savings (assuming a lucky kernel config): - /* size: 232, cachelines: 4, members: 28 */ - /* sum members: 227, holes: 1, sum holes: 4 */ - /* sum bitfield members: 8 bits (1 bytes) */ + /* size: 224, cachelines: 4, members: 28 */ /* forced alignments: 2 */ - /* last cacheline: 40 bytes */ + /* last cacheline: 32 bytes */ I think that the changes shouldn't be too controversial. The only one I'm not 100% sure of is the SCTP one, 12 extra LoC for one bit.. But it did fit squarely in the "this bit has only one user" category. ==================== Signed-off-by: David S. Miller <davem@davemloft.net> Acked-by: Simon Horman <horms@kernel.org>
2 parents 4edd97f + 48d80c3 commit fbb192a

6 files changed

Lines changed: 41 additions & 9 deletions

File tree

include/linux/skbuff.h

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ struct sk_buff {
934934
/* public: */
935935
__u8 pkt_type:3; /* see PKT_TYPE_MAX */
936936
__u8 ignore_df:1;
937-
__u8 nf_trace:1;
937+
__u8 dst_pending_confirm:1;
938938
__u8 ip_summed:2;
939939
__u8 ooo_okay:1;
940940

@@ -949,12 +949,14 @@ struct sk_buff {
949949
__u8 remcsum_offload:1;
950950
__u8 csum_complete_sw:1;
951951
__u8 csum_level:2;
952-
__u8 dst_pending_confirm:1;
952+
__u8 inner_protocol_type:1;
953953

954954
__u8 l4_hash:1;
955955
__u8 sw_hash:1;
956+
#ifdef CONFIG_WIRELESS
956957
__u8 wifi_acked_valid:1;
957958
__u8 wifi_acked:1;
959+
#endif
958960
__u8 no_fcs:1;
959961
/* Indicates the inner headers are valid in the skbuff. */
960962
__u8 encapsulation:1;
@@ -964,8 +966,12 @@ struct sk_buff {
964966
__u8 ndisc_nodetype:2;
965967
#endif
966968

969+
#if IS_ENABLED(CONFIG_IP_VS)
967970
__u8 ipvs_property:1;
968-
__u8 inner_protocol_type:1;
971+
#endif
972+
#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE) || IS_ENABLED(CONFIG_NF_TABLES)
973+
__u8 nf_trace:1;
974+
#endif
969975
#ifdef CONFIG_NET_SWITCHDEV
970976
__u8 offload_fwd_mark:1;
971977
__u8 offload_l3_fwd_mark:1;
@@ -981,12 +987,16 @@ struct sk_buff {
981987
__u8 decrypted:1;
982988
#endif
983989
__u8 slow_gro:1;
990+
#if IS_ENABLED(CONFIG_IP_SCTP)
984991
__u8 csum_not_inet:1;
992+
#endif
985993

986994
#ifdef CONFIG_NET_SCHED
987995
__u16 tc_index; /* traffic control index */
988996
#endif
989997

998+
u16 alloc_cpu;
999+
9901000
union {
9911001
__wsum csum;
9921002
struct {
@@ -1010,7 +1020,6 @@ struct sk_buff {
10101020
unsigned int sender_cpu;
10111021
};
10121022
#endif
1013-
u16 alloc_cpu;
10141023
#ifdef CONFIG_NETWORK_SECMARK
10151024
__u32 secmark;
10161025
#endif
@@ -1187,6 +1196,15 @@ static inline unsigned int skb_napi_id(const struct sk_buff *skb)
11871196
#endif
11881197
}
11891198

1199+
static inline bool skb_wifi_acked_valid(const struct sk_buff *skb)
1200+
{
1201+
#ifdef CONFIG_WIRELESS
1202+
return skb->wifi_acked_valid;
1203+
#else
1204+
return 0;
1205+
#endif
1206+
}
1207+
11901208
/**
11911209
* skb_unref - decrement the skb's reference count
11921210
* @skb: buffer
@@ -5049,7 +5067,19 @@ static inline void skb_reset_redirect(struct sk_buff *skb)
50495067

50505068
static inline bool skb_csum_is_sctp(struct sk_buff *skb)
50515069
{
5070+
#if IS_ENABLED(CONFIG_IP_SCTP)
50525071
return skb->csum_not_inet;
5072+
#else
5073+
return 0;
5074+
#endif
5075+
}
5076+
5077+
static inline void skb_reset_csum_not_inet(struct sk_buff *skb)
5078+
{
5079+
skb->ip_summed = CHECKSUM_NONE;
5080+
#if IS_ENABLED(CONFIG_IP_SCTP)
5081+
skb->csum_not_inet = 0;
5082+
#endif
50535083
}
50545084

50555085
static inline void skb_set_kcov_handle(struct sk_buff *skb,

include/net/sock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,7 +2697,7 @@ sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
26972697
else
26982698
sock_write_timestamp(sk, kt);
26992699

2700-
if (sock_flag(sk, SOCK_WIFI_STATUS) && skb->wifi_acked_valid)
2700+
if (sock_flag(sk, SOCK_WIFI_STATUS) && skb_wifi_acked_valid(skb))
27012701
__sock_recv_wifi_status(msg, sk, skb);
27022702
}
27032703

net/core/dev.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,8 +3315,7 @@ int skb_crc32c_csum_help(struct sk_buff *skb)
33153315
skb->len - start, ~(__u32)0,
33163316
crc32c_csum_stub));
33173317
*(__le32 *)(skb->data + offset) = crc32c_csum;
3318-
skb->ip_summed = CHECKSUM_NONE;
3319-
skb->csum_not_inet = 0;
3318+
skb_reset_csum_not_inet(skb);
33203319
out:
33213320
return ret;
33223321
}

net/core/skbuff.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5189,6 +5189,7 @@ void skb_tstamp_tx(struct sk_buff *orig_skb,
51895189
}
51905190
EXPORT_SYMBOL_GPL(skb_tstamp_tx);
51915191

5192+
#ifdef CONFIG_WIRELESS
51925193
void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
51935194
{
51945195
struct sock *sk = skb->sk;
@@ -5214,6 +5215,7 @@ void skb_complete_wifi_ack(struct sk_buff *skb, bool acked)
52145215
kfree_skb(skb);
52155216
}
52165217
EXPORT_SYMBOL_GPL(skb_complete_wifi_ack);
5218+
#endif /* CONFIG_WIRELESS */
52175219

52185220
/**
52195221
* skb_partial_csum_set - set up and verify partial csum values for packet

net/sched/act_csum.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ static int tcf_csum_sctp(struct sk_buff *skb, unsigned int ihl,
376376

377377
sctph->checksum = sctp_compute_cksum(skb,
378378
skb_network_offset(skb) + ihl);
379-
skb->ip_summed = CHECKSUM_NONE;
380-
skb->csum_not_inet = 0;
379+
skb_reset_csum_not_inet(skb);
381380

382381
return 1;
383382
}

net/socket.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
957957
}
958958
EXPORT_SYMBOL_GPL(__sock_recv_timestamp);
959959

960+
#ifdef CONFIG_WIRELESS
960961
void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk,
961962
struct sk_buff *skb)
962963
{
@@ -972,6 +973,7 @@ void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk,
972973
put_cmsg(msg, SOL_SOCKET, SCM_WIFI_STATUS, sizeof(ack), &ack);
973974
}
974975
EXPORT_SYMBOL_GPL(__sock_recv_wifi_status);
976+
#endif
975977

976978
static inline void sock_recv_drops(struct msghdr *msg, struct sock *sk,
977979
struct sk_buff *skb)

0 commit comments

Comments
 (0)