Commit 9a05475c authored by Julian Anastasov's avatar Julian Anastasov Committed by Pablo Neira Ayuso

ipvs: avoid kmem_cache_zalloc in ip_vs_conn_new

We have many fields to set and few to reset,
use kmem_cache_alloc instead to save some cycles.
Signed-off-by: default avatarJulian Anastasov <ja@ssi.bg>
Signed-off by: Hans Schillstrom <hans@schillstrom.com>
Signed-off-by: default avatarSimon Horman <horms@verge.net.au>
parent 1845ed0b
...@@ -233,6 +233,21 @@ static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst, ...@@ -233,6 +233,21 @@ static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
dst->ip = src->ip; dst->ip = src->ip;
} }
static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst,
const union nf_inet_addr *src)
{
#ifdef CONFIG_IP_VS_IPV6
if (af == AF_INET6) {
dst->in6 = src->in6;
return;
}
#endif
dst->ip = src->ip;
dst->all[1] = 0;
dst->all[2] = 0;
dst->all[3] = 0;
}
static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a, static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
const union nf_inet_addr *b) const union nf_inet_addr *b)
{ {
......
...@@ -861,7 +861,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, ...@@ -861,7 +861,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
struct ip_vs_proto_data *pd = ip_vs_proto_data_get(p->net, struct ip_vs_proto_data *pd = ip_vs_proto_data_get(p->net,
p->protocol); p->protocol);
cp = kmem_cache_zalloc(ip_vs_conn_cachep, GFP_ATOMIC); cp = kmem_cache_alloc(ip_vs_conn_cachep, GFP_ATOMIC);
if (cp == NULL) { if (cp == NULL) {
IP_VS_ERR_RL("%s(): no memory\n", __func__); IP_VS_ERR_RL("%s(): no memory\n", __func__);
return NULL; return NULL;
...@@ -872,13 +872,13 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, ...@@ -872,13 +872,13 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
ip_vs_conn_net_set(cp, p->net); ip_vs_conn_net_set(cp, p->net);
cp->af = p->af; cp->af = p->af;
cp->protocol = p->protocol; cp->protocol = p->protocol;
ip_vs_addr_copy(p->af, &cp->caddr, p->caddr); ip_vs_addr_set(p->af, &cp->caddr, p->caddr);
cp->cport = p->cport; cp->cport = p->cport;
ip_vs_addr_copy(p->af, &cp->vaddr, p->vaddr); ip_vs_addr_set(p->af, &cp->vaddr, p->vaddr);
cp->vport = p->vport; cp->vport = p->vport;
/* proto should only be IPPROTO_IP if d_addr is a fwmark */ /* proto should only be IPPROTO_IP if d_addr is a fwmark */
ip_vs_addr_copy(p->protocol == IPPROTO_IP ? AF_UNSPEC : p->af, ip_vs_addr_set(p->protocol == IPPROTO_IP ? AF_UNSPEC : p->af,
&cp->daddr, daddr); &cp->daddr, daddr);
cp->dport = dport; cp->dport = dport;
cp->flags = flags; cp->flags = flags;
cp->fwmark = fwmark; cp->fwmark = fwmark;
...@@ -887,6 +887,10 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, ...@@ -887,6 +887,10 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
cp->pe = p->pe; cp->pe = p->pe;
cp->pe_data = p->pe_data; cp->pe_data = p->pe_data;
cp->pe_data_len = p->pe_data_len; cp->pe_data_len = p->pe_data_len;
} else {
cp->pe = NULL;
cp->pe_data = NULL;
cp->pe_data_len = 0;
} }
spin_lock_init(&cp->lock); spin_lock_init(&cp->lock);
...@@ -897,18 +901,28 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p, ...@@ -897,18 +901,28 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
*/ */
atomic_set(&cp->refcnt, 1); atomic_set(&cp->refcnt, 1);
cp->control = NULL;
atomic_set(&cp->n_control, 0); atomic_set(&cp->n_control, 0);
atomic_set(&cp->in_pkts, 0); atomic_set(&cp->in_pkts, 0);
cp->packet_xmit = NULL;
cp->app = NULL;
cp->app_data = NULL;
/* reset struct ip_vs_seq */
cp->in_seq.delta = 0;
cp->out_seq.delta = 0;
atomic_inc(&ipvs->conn_count); atomic_inc(&ipvs->conn_count);
if (flags & IP_VS_CONN_F_NO_CPORT) if (flags & IP_VS_CONN_F_NO_CPORT)
atomic_inc(&ip_vs_conn_no_cport_cnt); atomic_inc(&ip_vs_conn_no_cport_cnt);
/* Bind the connection with a destination server */ /* Bind the connection with a destination server */
cp->dest = NULL;
ip_vs_bind_dest(cp, dest); ip_vs_bind_dest(cp, dest);
/* Set its state and timeout */ /* Set its state and timeout */
cp->state = 0; cp->state = 0;
cp->old_state = 0;
cp->timeout = 3*HZ; cp->timeout = 3*HZ;
cp->sync_endtime = jiffies & ~3UL; cp->sync_endtime = jiffies & ~3UL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment