Re: (RFC): SKB Initialization

Mala Anand (manand@us.ibm.com)
Wed, 21 Aug 2002 11:59:44 -0500


Here is a 2.5.25 patch that improves the skb header initialization
on SMP systems [for netperf]. The patch removes the constructor
for the skbuff_head_cache and moves the initialization of the skb
header from __free_skb to alloc_skb.

Since skbs freed on one CPU may end up being allocated on another cpu,
and often are, the initialization on the free side may not be the
right choice for SMP particularily if the free slab is then allocated
on another CPU.

I measured the cycles spent in initializing skb in the stock kernel
versus with the patch. I collected the cycles at the end of running
tcp_stream netperf test using 4KB message size, 64KB socket buffer
size, 2 adapter test on a 2-way system.

Two 996MHz Pentium III systems with 2 gigabit ethernet cards in each
one of them are used. The cycles are collected at the server
end.

The patch reduces the numer of cylces by 25%

Baseline on Linux 2.5.25 kernel:
-------------------------------

CPU 0 CPU 1
------ ------
Avg cycles in alloc_skb: 64.05 203.39
Avg cycles in __kfree_skb: 127.54 228.95
------ -------
Total Avg Cycles 191.59 432.34
------ -------

# of times alloc_skb called: 235,478 2,060,422
# of times __kfree_skb called: 2,063,276 232,359

Linux 2.5.25+Skbinit Patch:
--------------------------
CPU 0 CPU 1
----- -----
Avg cycles in alloc skb: 237.21 230.91

# of times alloc_skb called: 1,226,594 1,213,327

I also will collect the cycles of this init code in Specweb99 workload
and will post it later.

diff -Naur linux2.5.25/net/core/skbuff.c linux-525skb/net/core/skbuff.c
--- linux2.5.25/net/core/skbuff.c Tue Aug 20 08:50:58 2002
+++ linux-525skb/net/core/skbuff.c Wed Aug 21 08:51:52 2002
@@ -195,18 +195,37 @@
goto nodata;

/* XXX: does not include slab overhead */
+ skb->next = skb->prev = NULL;
+ skb->list = NULL;
+ skb->sk = NULL;
+ skb->stamp.tv_sec = 0; /* No idea about time */
+ skb->dev = NULL;
+ skb->dst = NULL;
+ memset(skb->cb, 0, sizeof(skb->cb));
+ skb->len = 0;
+ skb->data_len = 0;
+ skb->csum = 0;
+ skb->cloned = 0;
+ skb->pkt_type = PACKET_HOST; /* Default type */
+ skb->ip_summed = 0;
+ skb->priority = 0;
+ skb->security = 0; /* By default packets are insecure */
skb->truesize = size + sizeof(struct sk_buff);
-
/* Load the data pointers. */
skb->head = skb->data = skb->tail = data;
skb->end = data + size;
-
- /* Set up other state */
- skb->len = 0;
- skb->cloned = 0;
- skb->data_len = 0;
-
atomic_set(&skb->users, 1);
+ skb->destructor = NULL;
+#ifdef CONFIG_NETFILTER
+ skb->nfmark = skb->nfcache = 0;
+ skb->nfct = NULL;
+#ifdef CONFIG_NETFILTER_DEBUG
+ skb->nf_debug = 0;
+#endif
+#endif
+#ifdef CONFIG_NET_SCHED
+ skb->tc_index = 0;
+#endif
atomic_set(&(skb_shinfo(skb)->dataref), 1);
skb_shinfo(skb)->nr_frags = 0;
skb_shinfo(skb)->frag_list = NULL;
@@ -326,7 +345,7 @@
#ifdef CONFIG_NETFILTER
nf_conntrack_put(skb->nfct);
#endif
- skb_headerinit(skb, NULL, 0); /* clean state */
+ /* skb_headerinit(skb, NULL, 0); clean state */
kfree_skbmem(skb);
}

@@ -1191,7 +1210,7 @@
sizeof(struct sk_buff),
0,
SLAB_HWCACHE_ALIGN,
- skb_headerinit, NULL);
+ NULL, NULL);
if (!skbuff_head_cache)
panic("cannot create skbuff cache");

Regards,
Mala

Mala Anand
IBM Linux Technology Center - Kernel Performance
E-mail:manand@us.ibm.com
http://www-124.ibm.comdeveloperworks/opensource/linuxperf
http://www-124.ibm.com/developerworks/projects/linuxperf
Phone:838-8088; Tie-line:678-8088

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/