[PATCH 2.6] NETFILTER (5/x): use slab cache for ip_conntrack_expect
Harald Welte
laforge@netfilter.org
Sat, 24 Jul 2004 10:32:23 -0400
--QAdlk5ze2izLk3Ap
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hi Dave,
This patch adds a new slab cache (ip_conntrack_expect) for expectations.
Signed-off-by: Pablo Neira <pablo@eurodev.net>
Signed-off-by: Harald Welte <laforge@netfilter.org>
diff -u -r1.1.1.1 ip_conntrack_core.c
--- a/net/ipv4/netfilter/ip_conntrack_core.c 11 May 2004 13:07:08 -0000 1.1=
=2E1.1
+++ b/net/ipv4/netfilter/ip_conntrack_core.c 2 Jun 2004 11:06:44 -0000
@@ -67,6 +67,7 @@
static atomic_t ip_conntrack_count =3D ATOMIC_INIT(0);
struct list_head *ip_conntrack_hash;
static kmem_cache_t *ip_conntrack_cachep;
+static kmem_cache_t *ip_conntrack_expect_cachep;
struct ip_conntrack ip_conntrack_untracked;
=20
extern struct ip_conntrack_protocol ip_conntrack_generic_protocol;
@@ -176,7 +177,7 @@
IP_NF_ASSERT(atomic_read(&exp->use));
IP_NF_ASSERT(!timer_pending(&exp->timeout));
=20
- kfree(exp);
+ kmem_cache_free(ip_conntrack_expect_cachep, exp);
}
=20
=20
@@ -335,7 +336,7 @@
list_del(&ct->master->expected_list);
master =3D ct->master->expectant;
}
- kfree(ct->master);
+ kmem_cache_free(ip_conntrack_expect_cachep, ct->master);
}
WRITE_UNLOCK(&ip_conntrack_lock);
=20
@@ -923,9 +924,8 @@
ip_conntrack_expect_alloc()
{
struct ip_conntrack_expect *new;
-=09
- new =3D (struct ip_conntrack_expect *)
- kmalloc(sizeof(struct ip_conntrack_expect), GFP_ATOMIC);
+
+ new =3D kmem_cache_alloc(ip_conntrack_expect_cachep, GFP_ATOMIC);
if (!new) {
DEBUGP("expect_related: OOM allocating expect\n");
return NULL;
@@ -933,6 +933,7 @@
=20
/* tuple_cmp compares whole union, we have to initialized cleanly */
memset(new, 0, sizeof(struct ip_conntrack_expect));
+ atomic_set(&new->use, 1);
=20
return new;
}
@@ -944,7 +945,6 @@
DEBUGP("new expectation %p of conntrack %p\n", new, related_to);
new->expectant =3D related_to;
new->sibling =3D NULL;
- atomic_set(&new->use, 1);
=20
/* add to expected list for this connection */
list_add(&new->expected_list, &related_to->sibling_list);
@@ -998,7 +998,8 @@
}
=20
WRITE_UNLOCK(&ip_conntrack_lock);
- kfree(expect);
+ /* This expectation is not inserted so no need to lock */
+ kmem_cache_free(ip_conntrack_expect_cachep, expect);
return -EEXIST;
=20
} else if (related_to->helper->max_expected &&=20
@@ -1017,7 +1018,7 @@
related_to->helper->name,
NIPQUAD(related_to->tuplehash[IP_CT_DIR_ORIGINAL].t=
uple.src.ip),
NIPQUAD(related_to->tuplehash[IP_CT_DIR_ORIGINAL].t=
uple.dst.ip));
- kfree(expect);
+ kmem_cache_free(ip_conntrack_expect_cachep, expect);
return -EPERM;
}
DEBUGP("ip_conntrack: max number of expected "
@@ -1058,7 +1059,7 @@
WRITE_UNLOCK(&ip_conntrack_lock);
DEBUGP("expect_related: busy!\n");
=20
- kfree(expect);
+ kmem_cache_free(ip_conntrack_expect_cachep, expect);
return -EBUSY;
}
=20
@@ -1379,6 +1380,7 @@
}
=20
kmem_cache_destroy(ip_conntrack_cachep);
+ kmem_cache_destroy(ip_conntrack_expect_cachep);
vfree(ip_conntrack_hash);
nf_unregister_sockopt(&so_getorigdst);
}
@@ -1431,6 +1433,15 @@
printk(KERN_ERR "Unable to create ip_conntrack slab cache\n");
goto err_free_hash;
}
+
+ ip_conntrack_expect_cachep =3D kmem_cache_create("ip_conntrack_expect",
+ sizeof(struct ip_conntrack_expect),
+ 0, SLAB_HWCACHE_ALIGN, NULL, NULL);
+ if (!ip_conntrack_expect_cachep) {
+ printk(KERN_ERR "Unable to create ip_expect slab cache\n");
+ goto err_free_conntrack_slab;
+ }
+
/* Don't NEED lock here, but good form anyway. */
WRITE_LOCK(&ip_conntrack_lock);
/* Sew in builtin protocols. */
@@ -1458,6 +1469,8 @@
=20
return ret;
=20
+err_free_conntrack_slab:
+ kmem_cache_destroy(ip_conntrack_cachep);
err_free_hash:
vfree(ip_conntrack_hash);
err_unreg_sockopt:
--=20
- Harald Welte <laforge@netfilter.org> http://www.netfilter.org/
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D
"Fragmentation is like classful addressing -- an interesting early
architectural error that shows how much experimentation was going
on while IP was being designed." -- Paul Vixie
--QAdlk5ze2izLk3Ap
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFBAnL2XaXGVTD0i/8RAiuBAKCPCTDtH4Iyb3EhJONdMQHskgFrgwCfSeMJ
+jX6FD0O2L3aYaHsBgcVBTQ=
=pGJC
-----END PGP SIGNATURE-----
--QAdlk5ze2izLk3Ap--