Commit 1845ed0bb29fa7864781021e0c8d06af318f358a
Committed by
Pablo Neira Ayuso
1 parent
088339a57d
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
ipvs: reorder keys in connection structure
__ip_vs_conn_in_get and ip_vs_conn_out_get are hot places. Optimize them, so that ports are matched first. By moving net and fwmark below, on 32-bit arch we can fit caddr in 32-byte cache line and all addresses in 64-byte cache line. Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off by: Hans Schillstrom <hans@schillstrom.com> Signed-off-by: Simon Horman <horms@verge.net.au>
Showing 2 changed files with 16 additions and 15 deletions Side-by-side Diff
include/net/ip_vs.h
... | ... | @@ -566,20 +566,19 @@ |
566 | 566 | */ |
567 | 567 | struct ip_vs_conn { |
568 | 568 | struct hlist_node c_list; /* hashed list heads */ |
569 | -#ifdef CONFIG_NET_NS | |
570 | - struct net *net; /* Name space */ | |
571 | -#endif | |
572 | 569 | /* Protocol, addresses and port numbers */ |
573 | - u16 af; /* address family */ | |
574 | 570 | __be16 cport; |
575 | - __be16 vport; | |
576 | 571 | __be16 dport; |
577 | - __u32 fwmark; /* Fire wall mark from skb */ | |
572 | + __be16 vport; | |
573 | + u16 af; /* address family */ | |
578 | 574 | union nf_inet_addr caddr; /* client address */ |
579 | 575 | union nf_inet_addr vaddr; /* virtual address */ |
580 | 576 | union nf_inet_addr daddr; /* destination address */ |
581 | 577 | volatile __u32 flags; /* status flags */ |
582 | 578 | __u16 protocol; /* Which protocol (TCP/UDP) */ |
579 | +#ifdef CONFIG_NET_NS | |
580 | + struct net *net; /* Name space */ | |
581 | +#endif | |
583 | 582 | |
584 | 583 | /* counter and timer */ |
585 | 584 | atomic_t refcnt; /* reference count */ |
... | ... | @@ -593,6 +592,7 @@ |
593 | 592 | * state transition triggerd |
594 | 593 | * synchronization |
595 | 594 | */ |
595 | + __u32 fwmark; /* Fire wall mark from skb */ | |
596 | 596 | unsigned long sync_endtime; /* jiffies + sent_retries */ |
597 | 597 | |
598 | 598 | /* Control members */ |
net/netfilter/ipvs/ip_vs_conn.c
... | ... | @@ -265,8 +265,8 @@ |
265 | 265 | rcu_read_lock(); |
266 | 266 | |
267 | 267 | hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) { |
268 | - if (cp->af == p->af && | |
269 | - p->cport == cp->cport && p->vport == cp->vport && | |
268 | + if (p->cport == cp->cport && p->vport == cp->vport && | |
269 | + cp->af == p->af && | |
270 | 270 | ip_vs_addr_equal(p->af, p->caddr, &cp->caddr) && |
271 | 271 | ip_vs_addr_equal(p->af, p->vaddr, &cp->vaddr) && |
272 | 272 | ((!p->cport) ^ (!(cp->flags & IP_VS_CONN_F_NO_CPORT))) && |
... | ... | @@ -350,9 +350,9 @@ |
350 | 350 | rcu_read_lock(); |
351 | 351 | |
352 | 352 | hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) { |
353 | - if (!ip_vs_conn_net_eq(cp, p->net)) | |
354 | - continue; | |
355 | - if (p->pe_data && p->pe->ct_match) { | |
353 | + if (unlikely(p->pe_data && p->pe->ct_match)) { | |
354 | + if (!ip_vs_conn_net_eq(cp, p->net)) | |
355 | + continue; | |
356 | 356 | if (p->pe == cp->pe && p->pe->ct_match(p, cp)) { |
357 | 357 | if (__ip_vs_conn_get(cp)) |
358 | 358 | goto out; |
359 | 359 | |
... | ... | @@ -366,9 +366,10 @@ |
366 | 366 | * p->vaddr is a fwmark */ |
367 | 367 | ip_vs_addr_equal(p->protocol == IPPROTO_IP ? AF_UNSPEC : |
368 | 368 | p->af, p->vaddr, &cp->vaddr) && |
369 | - p->cport == cp->cport && p->vport == cp->vport && | |
369 | + p->vport == cp->vport && p->cport == cp->cport && | |
370 | 370 | cp->flags & IP_VS_CONN_F_TEMPLATE && |
371 | - p->protocol == cp->protocol) { | |
371 | + p->protocol == cp->protocol && | |
372 | + ip_vs_conn_net_eq(cp, p->net)) { | |
372 | 373 | if (__ip_vs_conn_get(cp)) |
373 | 374 | goto out; |
374 | 375 | } |
... | ... | @@ -404,8 +405,8 @@ |
404 | 405 | rcu_read_lock(); |
405 | 406 | |
406 | 407 | hlist_for_each_entry_rcu(cp, &ip_vs_conn_tab[hash], c_list) { |
407 | - if (cp->af == p->af && | |
408 | - p->vport == cp->cport && p->cport == cp->dport && | |
408 | + if (p->vport == cp->cport && p->cport == cp->dport && | |
409 | + cp->af == p->af && | |
409 | 410 | ip_vs_addr_equal(p->af, p->vaddr, &cp->caddr) && |
410 | 411 | ip_vs_addr_equal(p->af, p->caddr, &cp->daddr) && |
411 | 412 | p->protocol == cp->protocol && |