From c10621e6fa8de50619d7dd28546dd3288f053ab8 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Wed, 26 Mar 2014 16:28:47 +0100 Subject: [PATCH] trafgen: keep a small initial ring buffer size to reduce cache-misses Heavily reduce the initial ring buffer size for trafgen to just 196KiB, so that we can heavily reduce the number of cache-misses related to cache references. People can still overwrite this setting later on via command line option for their specific architecture if they wish. Perhaps the RX_RING should be checked as well in netsniff-ng though the use case there is slightly different. Before: Performance counter stats for 'trafgen -i blub -o dummy0 -n100000000': 137,765,493,346 instructions:k # 0.82 insns per cycle 167,438,826,578 cycles:k # 0.000 GHz 59,508,315 branch-misses:k 361 context-switches:k 6 cpu-migrations:k 134,751,541 cache-misses:k # 85.019 % of all cache refs 158,495,358 cache-references:k 755 kmem:kmem_cache_alloc 15.139458202 seconds time elapsed After: Performance counter stats for 'trafgen -i blub -o dummy0 -n100000000': 137,889,782,650 instructions:k # 0.92 insns per cycle 150,239,185,971 cycles:k # 0.000 GHz 71,583,573 branch-misses:k 423 context-switches:k 7 cpu-migrations:k 60,239 cache-misses:k # 0.073 % of all cache refs 82,502,468 cache-references:k 740 kmem:kmem_cache_alloc 12.028787964 seconds time elapsed Signed-off-by: Daniel Borkmann --- trafgen.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/trafgen.c b/trafgen.c index f50ac220..af15ef28 100644 --- a/trafgen.c +++ b/trafgen.c @@ -874,6 +874,9 @@ int main(int argc, char **argv) ctx.gid = getgid(); ctx.qdisc_path = false; + /* Keep an initial small default size to reduce cache-misses. */ + ctx.reserve_size = 196 * (1 << 10); + while ((c = getopt_long(argc, argv, short_options, long_options, &opt_index)) != EOF) { switch (c) { -- 2.11.4.GIT