Skip to contentSkip to conversation

Netfilter: Don't cachline align slab allocs

PATCH Applied Rusty Russell 3 participants 4 messages Jan 17, 2005 – Feb 2, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Netfilter: Don't cachline align slab allocs

Name: Don't cachline align slab allocs
Status: Trivial

Anton points out that cacheline aligning conntrack entries is a wank. He's right: there's lots of them, and they're currently ~200 bytes. Same with the cargo-cult programming in ipt_hashlimit.

net/ipv4/netfilter/ipt_hashlimit.c +1 -3
Index: linux-2.6.11-rc1-bk4-Netfilter/net/ipv4/netfilter/ipt_hashlimit.c
===================================================================
@@ -668,11 +668,9 @@
 		goto cleanup_nothing;
 	}
 
-	/* FIXME: do we really want HWCACHE_ALIGN since our objects are
-	 * quite small ? */
 	hashlimit_cachep = kmem_cache_create("ipt_hashlimit",
 					    sizeof(struct dsthash_ent), 0,
-					    SLAB_HWCACHE_ALIGN, NULL, NULL);
+					    0, NULL, NULL);
 	if (!hashlimit_cachep) {
 		printk(KERN_ERR "Unable to create ipt_hashlimit slab cache\n");
 		ret = -ENOMEM;
net/ipv4/netfilter/ip_conntrack_core.c +2 -2
Index: linux-2.6.11-rc1-bk4-Netfilter/net/ipv4/netfilter/ip_conntrack_core.c
===================================================================
@@ -1205,7 +1205,7 @@
 
 	ip_conntrack_cachep = kmem_cache_create("ip_conntrack",
 	                                        sizeof(struct ip_conntrack), 0,
-	                                        SLAB_HWCACHE_ALIGN, NULL,NULL);
+	                                        0, NULL, NULL);
 	if (!ip_conntrack_cachep) {
 		printk(KERN_ERR "Unable to create ip_conntrack slab cache\n");
 		goto err_free_hash;
@@ -1213,7 +1213,7 @@
 
 	ip_conntrack_expect_cachep = kmem_cache_create("ip_conntrack_expect",
 					sizeof(struct ip_conntrack_expect),
-					0, SLAB_HWCACHE_ALIGN, NULL, NULL);
+					0, 0, NULL, NULL);
 	if (!ip_conntrack_expect_cachep) {
 		printk(KERN_ERR "Unable to create ip_expect slab cache\n");
 		goto err_free_conntrack_slab;
Signature · 1 line
A bad analogy is like a leaky screwdriver -- Richard Braakman
maintainer Applied
#1 lore raw
Quoted 7 lines · On Mon, 17 Jan 2005 18:40:49 +1100 Rusty Russell <[email protected]> wrote:

Name: Don't cachline align slab allocs
Status: Trivial

Anton points out that cacheline aligning conntrack entries is a wank. He's right: there's lots of them, and they're currently ~200 bytes. Same with the cargo-cult programming in ipt_hashlimit.

Applied, thanks.

#2 lore raw
In reply to Rusty Russell
Quoted 2 lines · Rusty Russell

Anton points out that cacheline aligning conntrack entries is a wank. He's right: there's lots of them, and they're currently ~200 bytes.

I'm totally fine believing both of you... but ... So why is/was it a bad idea?

Quoted 1 line

Same with the cargo-cult programming in ipt_hashlimit.

Mh, please elaborate about that 'cargo-cult programming' phrase - seems to be an expression I'm not familiar with, as non-native english speaker.

Thanks!

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "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
#3 lore raw
Quoted 6 lines · Harald Welte
Quoted 2 lines · Rusty Russell

Anton points out that cacheline aligning conntrack entries is a wank. He's right: there's lots of them, and they're currently ~200 bytes.

I'm totally fine believing both of you... but ... So why is/was it a bad idea?

It has the effect of enlarging the structure to a cacheline boundary, hence reducing density and worsening cache behaviour (as well as wasting memory). The only gain would be if there were a significant probability of "false sharing" where two connection tracking entries accessed by different CPUs were in the same cacheline. This is unlikely because of the number of conntrack entries, and the fact that they are bigger than a cacheline already (ie. at worst, only two could share a cacheline, and then not completely).

In general, cacheline aligned is hard to justify for any slab allocation for performance reasons, as slab indicates that many are being allocated.

Quoted 5 lines
Quoted 1 line

Same with the cargo-cult programming in ipt_hashlimit.

Mh, please elaborate about that 'cargo-cult programming' phrase - seems to be an expression I'm not familiar with, as non-native english speaker.

That's disingenuous: don't blame your language skills for my lack of clarity. From the jargon file:

http://www.catb.org/~esr/jargon/html/C/cargo-cult-programming.html

cargo cult programming: n.

A style of (incompetent) programming dominated by ritual inclusion of code or program structures that serve no real purpose. A cargo cult programmer will usually explain the extra code as a way of working around some bug encountered in the past, but usually neither the bug nor the reason the code apparently avoided the bug was ever fully understood (compare shotgun debugging, voodoo programming).

The term ‘cargo cult’ is a reference to aboriginal religions that grew up in the South Pacific after World War II. The practices of these cults center on building elaborate mockups of airplanes and military style landing strips in the hope of bringing the return of the god-like airplanes that brought such marvelous cargo during the war. Hackish usage probably derives from Richard Feynman's characterization of certain practices as “cargo cult science” in his book Surely You're Joking, Mr. Feynman! (W. W. Norton & Co, New York 1985, ISBN 0-393-01921-7).

My only difference here is that I place 50% of the blame on the interface, not the poor programmer who copied the code.

Rusty.

Signature · 1 line
A bad analogy is like a leaky screwdriver -- Richard Braakman