I have a try on zero_copy of kernel 4.14, follow is the details about zero_copy in kernel 4.14.
[1] (https://netdevconf.org/2.1/papers/netdev.pdf)
And I test it in squid which is a cache proxy.My code is a little diffrent with above. I use epoll to handle zerocopy and copy disk file to send to the client. When the socket is writable, I use function as follow
send(fd, buf, sz, MSG_ZEROCOPY); //sz=16KB, 32KB
Also I handle EPOLLERR as follow to free the buf allocated.
recvmsg(fd, &msg, MSG_ERRQUEUE)
But I found that the fd is often waked up with EPOLLERR, SO I call recvmsg after every send calls or else the cpu runs very high. Then I use curl to make requests to the squid proxy which has caches for the request.
foreach -c 400 -w 4 'curl -o /dev/null -s -w "%{time_connect} %{time_total} %{speed_download}\n" http://160MB.html -x 192.168.1.20:3128 -H "Pragma: "'
But the result shows that non_zero_copy code is more quickly. And the cpu hot functions distributes as follow:
non_zero_copy: %Cpu1 : 21.9 us, 77.1 sy, 0.0 ni, 0.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.3 st
32.52% [kernel] [k] copy_user_enhanced_fast_string
8.73% libc-2.17.so [.] __memcpy_ssse3_back
6.36% [kernel] [k] iowrite16
3.97% [kernel] [k] do_syscall_64
3.60% [kernel] [k] _raw_spin_unlock_irqrestore
3.25% libc-2.17.so [.] __memset_sse2
2.74% [kernel] [k] find_get_entry
2.03% libpthread-2.17.so [.] pthread_cond_wait@@GLIBC_2.3.2
1.66% [kernel] [k] tcp_sendmsg_locked
1.44% [kernel] [k] generic_file_read_iter
0.84% [kernel] [k] finish_task_switch
0.80% libc-2.17.so [.] epoll_ctl
0.78% [kernel] [k] __fget
0.78% [kernel] [k] get_page_from_freelist
0.77% [kernel] [k] sock_poll
0.71% [kernel] [k] skb_release_data
0.69% libpthread-2.17.so [.] __pthread_disable_asynccancel
0.64% [kernel] [k] sys_epoll_ctl
0.62% [kernel] [k] __audit_syscall_exit
zero_copy: %Cpu1 : 35.8 us, 63.9 sy, 0.0 ni, 0.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
9.41% [kernel] [k] do_syscall_64
8.57% [kernel] [k] copy_user_enhanced_fast_string
7.79% [kernel] [k] _raw_spin_unlock_irqrestore
7.55% libc-2.17.so [.] 0x00000000000f7d13
6.70% [kernel] [k] ep_send_events_proc
5.11% [vdso] [.] __vdso_gettimeofday
4.73% libc-2.17.so [.] __memset_sse2
4.16% [kernel] [k] pvclock_clocksource_read
3.66% libc-2.17.so [.] __memcpy_ssse3_back
2.02% [kernel] [k] tcp_poll
1.95% [kernel] [k] iowrite16
1.93% squid [.] comm_select
1.73% [kernel] [k] find_get_entry
1.57% [kernel] [k] sock_poll
1.54% [kernel] [k] __fget
1.53% [kernel] [k] select_estimate_accuracy
1.41% squid [.] getCurrentTime
0.86% [kernel] [k] ktime_get_ts64
0.84% [kernel] [k] ep_poll
0.83% [kernel] [k] ep_scan_ready_list.isra.13
0.81% libpthread-2.17.so [.] pthread_cond_wait@@GLIBC_2.3.2
0.73% [kernel] [k] fput
0.71% [kernel] [k] __audit_syscall_entry
0.71% [kernel] [k] __audit_syscall_exit
0.70% [kernel] [k] mutex_lock
0.66% [kernel] [k] _raw_spin_lock_irqsave
0.59% libc-2.17.so [.] __libc_disable_asynccancel
0.57% squid [.] statHistCount
Does anyone have the same test with me? And why my test is not same with the result of the article in pdf above.