Skip to content

Commit c60c34a

Browse files
committed
Merge branch 'net-better-packing-of-global-vars'
Eric Dumazet says: ==================== net: better packing of global vars First two patches avoid holes in data section, and last patch makes sure some siphash keys are contained in a single cache line. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 62803fe + 49ecc2e commit c60c34a

File tree

13 files changed

+16
-14
lines changed

13 files changed

+16
-14
lines changed

include/linux/netdevice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4942,7 +4942,7 @@ void netdev_info(const struct net_device *dev, const char *format, ...);
49424942

49434943
#define netdev_level_once(level, dev, fmt, ...) \
49444944
do { \
4945-
static bool __print_once __read_mostly; \
4945+
static bool __section(".data.once") __print_once; \
49464946
\
49474947
if (!__print_once) { \
49484948
__print_once = true; \

include/linux/once.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void __do_once_done(bool *done, struct static_key_true *once_key,
3838
#define DO_ONCE(func, ...) \
3939
({ \
4040
bool ___ret = false; \
41-
static bool ___done = false; \
41+
static bool __section(".data.once") ___done = false; \
4242
static DEFINE_STATIC_KEY_TRUE(___once_key); \
4343
if (static_branch_unlikely(&___once_key)) { \
4444
unsigned long ___flags; \

include/linux/siphash.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ typedef struct {
2121
u64 key[2];
2222
} siphash_key_t;
2323

24+
#define siphash_aligned_key_t siphash_key_t __aligned(16)
25+
2426
static inline bool siphash_key_is_zero(const siphash_key_t *key)
2527
{
2628
return !(key->key[0] | key->key[1]);

net/core/flow_dissector.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ bool __skb_flow_dissect(const struct net *net,
14601460
}
14611461
EXPORT_SYMBOL(__skb_flow_dissect);
14621462

1463-
static siphash_key_t hashrnd __read_mostly;
1463+
static siphash_aligned_key_t hashrnd;
14641464
static __always_inline void __flow_hash_secret_init(void)
14651465
{
14661466
net_get_random_once(&hashrnd, sizeof(hashrnd));

net/core/secure_seq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include <linux/in6.h>
2020
#include <net/tcp.h>
2121

22-
static siphash_key_t net_secret __read_mostly;
23-
static siphash_key_t ts_secret __read_mostly;
22+
static siphash_aligned_key_t net_secret;
23+
static siphash_aligned_key_t ts_secret;
2424

2525
static __always_inline void net_secret_init(void)
2626
{

net/ipv4/route.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ static void fnhe_remove_oldest(struct fnhe_hash_bucket *hash)
602602

603603
static u32 fnhe_hashfun(__be32 daddr)
604604
{
605-
static siphash_key_t fnhe_hash_key __read_mostly;
605+
static siphash_aligned_key_t fnhe_hash_key;
606606
u64 hval;
607607

608608
net_get_random_once(&fnhe_hash_key, sizeof(fnhe_hash_key));

net/ipv4/syncookies.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <net/tcp.h>
1515
#include <net/route.h>
1616

17-
static siphash_key_t syncookie_secret[2] __read_mostly;
17+
static siphash_aligned_key_t syncookie_secret[2];
1818

1919
#define COOKIEBITS 24 /* Upper bits store count */
2020
#define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1)

net/ipv6/route.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ static void rt6_exception_remove_oldest(struct rt6_exception_bucket *bucket)
14851485
static u32 rt6_exception_hash(const struct in6_addr *dst,
14861486
const struct in6_addr *src)
14871487
{
1488-
static siphash_key_t rt6_exception_key __read_mostly;
1488+
static siphash_aligned_key_t rt6_exception_key;
14891489
struct {
14901490
struct in6_addr dst;
14911491
struct in6_addr src;

net/ipv6/syncookies.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define COOKIEBITS 24 /* Upper bits store count */
2121
#define COOKIEMASK (((__u32)1 << COOKIEBITS) - 1)
2222

23-
static siphash_key_t syncookie6_secret[2] __read_mostly;
23+
static siphash_aligned_key_t syncookie6_secret[2];
2424

2525
/* RFC 2460, Section 8.3:
2626
* [ipv6 tcp] MSS must be computed as the maximum packet size minus 60 [..]

net/netfilter/nf_conntrack_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ EXPORT_SYMBOL_GPL(nf_conntrack_htable_size);
189189
unsigned int nf_conntrack_max __read_mostly;
190190
EXPORT_SYMBOL_GPL(nf_conntrack_max);
191191
seqcount_spinlock_t nf_conntrack_generation __read_mostly;
192-
static siphash_key_t nf_conntrack_hash_rnd __read_mostly;
192+
static siphash_aligned_key_t nf_conntrack_hash_rnd;
193193

194194
static u32 hash_conntrack_raw(const struct nf_conntrack_tuple *tuple,
195195
unsigned int zoneid,
@@ -482,7 +482,7 @@ EXPORT_SYMBOL_GPL(nf_ct_invert_tuple);
482482
*/
483483
u32 nf_ct_get_id(const struct nf_conn *ct)
484484
{
485-
static __read_mostly siphash_key_t ct_id_seed;
485+
static siphash_aligned_key_t ct_id_seed;
486486
unsigned long a, b, c, d;
487487

488488
net_get_random_once(&ct_id_seed, sizeof(ct_id_seed));

0 commit comments

Comments
 (0)