net: better packing of global vars
Subsystems (6)
cover net: better packing of global vars
From: Eric Dumazet <[email protected]>
First two patches avoid holes in data section, and last patch makes sure some siphash keys are contained in a single cache line.
Eric Dumazet (3):
once: use __section(".data.once")
net: use .data.once section in netdev_level_once()
net: align static siphash keys
include/linux/netdevice.h | 2 +- include/linux/once.h | 2 +- include/linux/siphash.h | 2 ++ net/core/flow_dissector.c | 2 +- net/core/secure_seq.c | 4 ++-- net/ipv4/route.c | 2 +- net/ipv4/syncookies.c | 2 +- net/ipv6/route.c | 2 +- net/ipv6/syncookies.c | 2 +- net/netfilter/nf_conntrack_core.c | 4 ++-- net/netfilter/nf_conntrack_expect.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 2 +- net/netfilter/nf_nat_core.c | 2 +- 13 files changed, 16 insertions(+), 14 deletions(-)
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
PATCH 1/3 once: use __section(".data.once")
From: Eric Dumazet <[email protected]>
.data.once contains nicely packed bool variables.
It is used already by DO_ONCE_LITE().
Using it also in DO_ONCE() removes holes in .data section.
--- include/linux/once.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/once.h +1 -1
@@ -38,7 +38,7 @@ void __do_once_done(bool *done, struct static_key_true *once_key,#define DO_ONCE (func, ...) \ ({ \ bool ___ret = false; \ - static bool ___done = false; \ + static bool __section(".data.once") ___done = false; \ static DEFINE_STATIC_KEY_TRUE(___once_key); \ if (static_branch_unlikely(&___once_key)) { \ unsigned long ___flags; \
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
PATCH 2/3 net: use .data.once section in netdev_level_once()
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
Same rationale than prior patch : using the dedicated section avoid holes and pack all these bool values.
--- include/linux/netdevice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/netdevice.h +1 -1
@@ -5291,7 +5291,7 @@ void netdev_info(const struct net_device *dev, const char *format, ...);#define netdev_level_once (level, dev, fmt, ...) \ do { \ - static bool __print_once __read_mostly; \ + static bool __section(".data.once") __print_once; \ \ if (!__print_once) { \ __print_once = true; \
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
PATCH 3/3 net: align static siphash keys
In reply to Eric DumazetFrom: Eric Dumazet <[email protected]>
siphash keys use 16 bytes.
Define siphash_aligned_key_t macro so that we can make sure they are not crossing a cache line boundary.
--- include/linux/siphash.h | 2 ++ net/core/flow_dissector.c | 2 +- net/core/secure_seq.c | 4 ++-- net/ipv4/route.c | 2 +- net/ipv4/syncookies.c | 2 +- net/ipv6/route.c | 2 +- net/ipv6/syncookies.c | 2 +- net/netfilter/nf_conntrack_core.c | 4 ++-- net/netfilter/nf_conntrack_expect.c | 2 +- net/netfilter/nf_conntrack_netlink.c | 2 +- net/netfilter/nf_nat_core.c | 2 +- 11 files changed, 14 insertions(+), 12 deletions(-)
include/linux/siphash.h +2 -0
@@ -21,6 +21,8 @@ typedef struct {u64 key[2 ]; } siphash_key_t; +#define siphash_aligned_key_t siphash_key_t __aligned(16) +static inline bool siphash_key_is_zero (const siphash_key_t *key) {return !(key->key[0 ] | key->key[1 ]);
net/core/flow_dissector.c +1 -1
@@ -1460,7 +1460,7 @@ bool __skb_flow_dissect(const struct net *net, }EXPORT_SYMBOL (__skb_flow_dissect); -static siphash_key_t hashrnd__read_mostly ; +static siphash_aligned_key_t hashrnd; static __always_inline void __flow_hash_secret_init(void) {net_get_random_once (&hashrnd,sizeof (hashrnd));
net/core/secure_seq.c +2 -2
@@ -19,8 +19,8 @@#include <linux/in6.h> #include <net/tcp.h> -static siphash_key_t net_secret__read_mostly ; -static siphash_key_t ts_secret__read_mostly ; +static siphash_aligned_key_t net_secret; +static siphash_aligned_key_t ts_secret; static __always_inline void net_secret_init(void) {
net/ipv4/route.c +1 -1
@@ -602,7 +602,7 @@ static void fnhe_remove_oldest(struct fnhe_hash_bucket *hash)static u32 fnhe_hashfun (__be32 daddr) { -static siphash_key_t fnhe_hash_key__read_mostly ; +static siphash_aligned_key_t fnhe_hash_key;u64 hval;net_get_random_once (&fnhe_hash_key,sizeof (fnhe_hash_key));
net/ipv4/syncookies.c +1 -1
@@ -14,7 +14,7 @@#include <net/tcp.h> #include <net/route.h> -static siphash_key_t syncookie_secret[2 ]__read_mostly ; +static siphash_aligned_key_t syncookie_secret[2 ];#define COOKIEBITS 24/* Upper bits store count */ #define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1)
net/ipv6/route.c +1 -1
@@ -1485,7 +1485,7 @@ static void rt6_exception_remove_oldest(struct rt6_exception_bucket *bucket)static u32 rt6_exception_hash (const struct in6_addr *dst,const struct in6_addr *src) { -static siphash_key_t rt6_exception_key__read_mostly ; +static siphash_aligned_key_t rt6_exception_key;struct {struct in6_addr dst;struct in6_addr src;
net/ipv6/syncookies.c +1 -1
@@ -20,7 +20,7 @@#define COOKIEBITS 24/* Upper bits store count */ #define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1) -static siphash_key_t syncookie6_secret[2 ]__read_mostly ; +static siphash_aligned_key_t syncookie6_secret[2 ];/* RFC 2460, Section 8.3: * [ipv6 tcp] MSS must be computed as the maximum packet size minus 60 [..]
net/netfilter/nf_conntrack_core.c +2 -2
@@ -189,7 +189,7 @@ EXPORT_SYMBOL_GPL(nf_conntrack_htable_size);unsigned int nf_conntrack_max__read_mostly ;EXPORT_SYMBOL_GPL (nf_conntrack_max);seqcount_spinlock_t nf_conntrack_generation__read_mostly ; -static siphash_key_t nf_conntrack_hash_rnd__read_mostly ; +static siphash_aligned_key_t nf_conntrack_hash_rnd; static u32 hash_conntrack_raw(const struct nf_conntrack_tuple *tuple, unsigned int zoneid,
@@ -482,7 +482,7 @@ EXPORT_SYMBOL_GPL(nf_ct_invert_tuple);*/ u32 nf_ct_get_id (const struct nf_conn *ct) { -static __read_mostly siphash_key_t ct_id_seed; +static siphash_aligned_key_t ct_id_seed;unsigned long a, b, c, d;net_get_random_once (&ct_id_seed,sizeof (ct_id_seed));
net/netfilter/nf_conntrack_expect.c +1 -1
@@ -41,7 +41,7 @@ EXPORT_SYMBOL_GPL(nf_ct_expect_hash);unsigned int nf_ct_expect_max__read_mostly ;static struct kmem_cache *nf_ct_expect_cachep__read_mostly ; -static siphash_key_t nf_ct_expect_hashrnd__read_mostly ; +static siphash_aligned_key_t nf_ct_expect_hashrnd;/* nf_conntrack_expect helper functions */ void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -2997,7 +2997,7 @@ static const union nf_inet_addr any_addr;static __be32 nf_expect_get_id (const struct nf_conntrack_expect *exp) { -static __read_mostly siphash_key_t exp_id_seed; +static siphash_aligned_key_t exp_id_seed;unsigned long a, b, c, d;net_get_random_once (&exp_id_seed,sizeof (exp_id_seed));
net/netfilter/nf_nat_core.c +1 -1
@@ -34,7 +34,7 @@ static unsigned int nat_net_id __read_mostly;static struct hlist_head *nf_nat_bysource__read_mostly ;static unsigned int nf_nat_htable_size__read_mostly ; -static siphash_key_t nf_nat_hash_rnd__read_mostly ; +static siphash_aligned_key_t nf_nat_hash_rnd;struct nf_nat_lookup_hook_priv {struct nf_hook_entries __rcu *entries;
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:
Quoted 6 lines · On Mon, 15 Nov 2021 09:23:00 -0800 you wrote:
From: Eric Dumazet <[email protected]>
First two patches avoid holes in data section, and last patch makes sure some siphash keys are contained in a single cache line.
Quoted 6 lines
Eric Dumazet (3):
once: use__section(".data.once")
net: use .data.once section innetdev_level_once()
net: align static siphash keys[...]
Here is the summary with links:
- [net-next,1/3] once: use __section(".data.once")
https://git.kernel.org/netdev/net-next/c/c2c60ea37e5b - [net-next,2/3] net: use .data.once section in netdev_level_once() https://git.kernel.org/netdev/net-next/c/7071732c26fe - [net-next,3/3] net: align static siphash keys https://git.kernel.org/netdev/net-next/c/49ecc2e9c3ab
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html