From owner-freebsd-net@freebsd.org Fri Aug 26 15:17:32 2016 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D1063B707A0 for ; Fri, 26 Aug 2016 15:17:32 +0000 (UTC) (envelope-from slw@zxy.spb.ru) Received: from zxy.spb.ru (zxy.spb.ru [195.70.199.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 89081A6C for ; Fri, 26 Aug 2016 15:17:32 +0000 (UTC) (envelope-from slw@zxy.spb.ru) Received: from slw by zxy.spb.ru with local (Exim 4.86 (FreeBSD)) (envelope-from ) id 1bdIsr-0007U8-HV for freebsd-net@freebsd.org; Fri, 26 Aug 2016 18:17:29 +0300 Date: Fri, 26 Aug 2016 18:17:29 +0300 From: Slawa Olhovchenkov To: freebsd-net@freebsd.org Subject: Network stack profiling/optimisation Message-ID: <20160826151729.GG88122@zxy.spb.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: slw@zxy.spb.ru X-SA-Exim-Scanned: No (on zxy.spb.ru); SAEximRunCond expanded to false X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 26 Aug 2016 15:17:32 -0000 I am collect some data releted to network stack performance under heavy load. This is data collected on dual E5-2620, under 20Gbit load. At time peak network traffic (more then 25K connections, about 20Gbit total traffic) half of cores fully utilised by network stack. This is flamegraph from one core: http://zxy.spb.ru/cpu10.svg This is same, but stack cut of at ixgbe_rxeof for more unified tcp/ip stack view http://zxy.spb.ru/cpu10u.svg Top 3 used lines is: 7036 0xffffffff804bf02d atomic_cmpset_long /usr/obj/usr/src/sys/VSTREAM/./machine/atomic.h:163 static __inline int atomic_cmpset_long(volatile u_long *dst, u_long expect, u_long src) { u_char res; __asm __volatile( " " MPLOCKED " " > " cmpxchgq %3,%1 ; " " sete %0 ; " "# atomic_cmpset_long" : "=q" (res), /* 0 */ "+m" (*dst), /* 1 */ "+a" (expect) /* 2 */ : "r" (src) /* 3 */ : "memory", "cc"); return (res); } 6099 0xffffffff81171963 ?? ??:0 0xffffffff81171940 : mov 0x10(%r15),%rax 0xffffffff81171944 : add $0x8,%rax 0xffffffff81171948 : mov -0x4c(%rbp),%ecx 0xffffffff8117194b : test %cx,%cx 0xffffffff8117194e : mov %rax,0x10(%r15) 0xffffffff81171952 : je 0xffffffff8117198d 0xffffffff81171954 : mov 0x10(%rdi),%rcx 0xffffffff81171958 : mov -0x4c(%rbp),%edx 0xffffffff8117195b : nopl 0x0(%rax,%rax,1) 0xffffffff81171960 : mov (%rcx),%rsi 0xffffffff81171963 : mov %rsi,(%rax) 0xffffffff81171966 : mov 0x8(%rcx),%rsi 0xffffffff8117196a : mov %rsi,0x8(%rax) 0xffffffff8117196e : mov 0x10(%rcx),%rsi 0xffffffff81171972 : mov %rsi,0x10(%rax) 0xffffffff81171976 : mov 0x18(%rcx),%rsi 0xffffffff8117197a : mov %rsi,0x18(%rax) 0xffffffff8117197e : add $0xffffffffffffffe0,%edx 0xffffffff81171981 : add $0x20,%rcx 0xffffffff81171985 : add $0x20,%rax 0xffffffff81171989 : test %edx,%edx 5594 0xffffffff8053395a mb_free_ext /usr/src/sys/kern/uipc_mbuf.c:301 if (*(m->m_ext.ref_cnt) == 1 || I am able collect and process more measure for help to improve FreeBSD network stack. Have someone any idea about this? I am don't see evident and simple points of optimisation :(