From: Eric Dumazet <eduma...@google.com>

struct inet_timewait_death_row uses two cache lines, because we want
tw_count to use a full cache line to avoid false sharing.

Rework its definition and placement in netns_ipv4 so that:

1) We add 60 bytes of padding after tw_count to avoid
  false sharing, knowing that tcp_death_row will
  have ____cacheline_aligned_in_smp attribute.

2) We do not risk padding before tcp_death_row, because
  we move it at the beginning of netns_ipv4, even if new
 fields are added later.

3) We do not waste 48 bytes of padding after it.

Note that I have not changed dccp.

pahole result for struct netns_ipv4 before/after the patch :

/* size: 832, cachelines: 13, members: 139 */
/* sum members: 721, holes: 12, sum holes: 95 */
/* padding: 16 */
/* paddings: 2, sum paddings: 55 */

->

/* size: 768, cachelines: 12, members: 139 */
/* sum members: 673, holes: 11, sum holes: 39 */
/* padding: 56 */
/* paddings: 2, sum paddings: 7 */
/* forced alignments: 1 */

Signed-off-by: Eric Dumazet <eduma...@google.com>
---
 include/net/netns/ipv4.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
index 
9c8dd424d79b1d1100b6cbaa64d9fda9352a0b3a..1085ed4e0788d7cd432dfc7e5604ef3cd66dc337
 100644
--- a/include/net/netns/ipv4.h
+++ b/include/net/netns/ipv4.h
@@ -32,14 +32,18 @@ struct inet_hashinfo;
 
 struct inet_timewait_death_row {
        atomic_t                tw_count;
+       char                    tw_pad[L1_CACHE_BYTES - sizeof(atomic_t)];
 
-       struct inet_hashinfo    *hashinfo ____cacheline_aligned_in_smp;
+       struct inet_hashinfo    *hashinfo;
        int                     sysctl_max_tw_buckets;
 };
 
 struct tcp_fastopen_context;
 
 struct netns_ipv4 {
+       /* Please keep tcp_death_row at first field in netns_ipv4 */
+       struct inet_timewait_death_row tcp_death_row 
____cacheline_aligned_in_smp;
+
 #ifdef CONFIG_SYSCTL
        struct ctl_table_header *forw_hdr;
        struct ctl_table_header *frags_hdr;
@@ -175,7 +179,6 @@ struct netns_ipv4 {
        int sysctl_tcp_comp_sack_nr;
        unsigned long sysctl_tcp_comp_sack_delay_ns;
        unsigned long sysctl_tcp_comp_sack_slack_ns;
-       struct inet_timewait_death_row tcp_death_row;
        int sysctl_max_syn_backlog;
        int sysctl_tcp_fastopen;
        const struct tcp_congestion_ops __rcu  *tcp_congestion_control;
-- 
2.31.0.291.g576ba9dcdaf-goog

Reply via email to