net-zerocopy: Reduce compound page head access
Subsystems (3)
PATCH 1/2 net-zerocopy: Reduce compound page head access
From: Xiaoyan Li <[email protected]>
When compound pages are enabled, although the mm layer still returns an array of page pointers, a subset (or all) of them may have the same page head since a max 180kb skb can span 2 hugepages if it is on the boundary, be a mix of pages and 1 hugepage, or fit completely in a hugepage. Instead of referencing page head on all page pointers, use page length arithmetic to only call page head when referencing a known different page head to avoid touching a cold cacheline.
Tested:
See next patch with changes to tcp_mmap
Correntess:
On a pair of separate hosts as send with MSG_ZEROCOPY will force a copy on tx if using loopback alone, check that the SHA on the message sent is equivalent to checksum on the message received, since the current program already checks for the length.
echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages ./tcp_mmap -s -z
./tcp_mmap -H $DADDR -z
SHA256 is correct
received 2 MB (100 % mmap'ed) in 0.005914 s, 2.83686 Gbit
cpu usage user:0.001984 sys:0.000963, 1473.5 usec per MB, 10 c-switches
Performance:
Run neper between adjacent hosts with the same configtcp_stream -Z --skip-rx-copy -6 -T 20 -F 1000 --stime-use-proc --test-length=30
Before patch: stime_end=37.670000
After patch: stime_end=30.310000
--- net/core/datagram.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
net/core/datagram.c +11 -3
@@ -622,12 +622,12 @@ int __zerocopy_sg_from_iter(struct msghdr *msg, struct sock *sk, frag =skb_shinfo (skb)->nr_frags;while (length &&iov_iter_count (from)) { +struct page *head, *last_head =NULL ;struct page *pages[MAX_SKB_FRAGS ]; -struct page *last_head =NULL ; +int refs, order, n =0 ;size_t start;ssize_t copied;unsigned long truesize; -int refs, n =0 ;if (frag ==MAX_SKB_FRAGS )return -EMSGSIZE ;
@@ -650,9 +650,17 @@ int __zerocopy_sg_from_iter(struct msghdr *msg, struct sock *sk, }else {refcount_add (truesize, &skb->sk->sk_wmem_alloc); } + + head =compound_head (pages[n]); + order =compound_order (head); +for (refs =0 ; copied !=0 ; start =0 ) {int size =min_t (int, copied,PAGE_SIZE - start); -struct page *head =compound_head (pages[n]); + +if (pages[n] - head > (1UL << order) -1 ) { + head =compound_head (pages[n]); + order =compound_order (head); + } start += (pages[n] - head) <<PAGE_SHIFT ; copied -= size;
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
PATCH 2/2 selftests/net: Add SHA256 computation over data sent in tcp_mmap
From: Xiaoyan Li <[email protected]>
Add option to compute and send SHA256 over data sent (-i).
This is to ensure the correctness of data received. Data is randomly populated from /dev/urandom.
Tested:
./tcp_mmap -s -z -i
./tcp_mmap -z -H $ADDR -i
SHA256 is correct
./tcp_mmap -s -i
./tcp_mmap -H $ADDR -i
SHA256 is correct
--- tools/testing/selftests/net/Makefile | 2 +- tools/testing/selftests/net/tcp_mmap.c | 102 ++++++++++++++++++++++--- 2 files changed, 92 insertions(+), 12 deletions(-)
tools/testing/selftests/net/Makefile +1 -1
@@ -89,7 +89,7 @@ TEST_FILES := settings include ../lib.mk $(OUTPUT)/reuseport_bpf_numa: LDLIBS += -lnuma -$(OUTPUT)/tcp_mmap: LDLIBS += -lpthread +$(OUTPUT)/tcp_mmap: LDLIBS += -lpthread -lcrypto $(OUTPUT)/tcp_inq: LDLIBS += -lpthread $(OUTPUT)/bind_bhash: LDLIBS += -lpthread
tools/testing/selftests/net/tcp_mmap.c +91 -11
222 lines not on this page · raw message
Signature · 1 line
2.40.0.rc1.284.g88254d51c5-goog
Re: [PATCH net-next 2/2] selftests/net: Add SHA256 computation over data sent in tcp_mmap
Quoted 13 lines · Coco Li
From: Xiaoyan Li <[email protected]>
Add option to compute and send SHA256 over data sent (-i).
This is to ensure the correctness of data received. Data is randomly populated from
/dev/urandom.Tested:
./tcp_mmap -s -z -i
./tcp_mmap -z -H $ADDR -i
SHA256 is correct
Quoted 6 lines
./tcp_mmap -s -i
./tcp_mmap -H $ADDR -i
SHA256 is correctSigned-off-by Coco Li <[email protected]>
Quoted 11 lines · Coco Li
From: Xiaoyan Li <[email protected]>
When compound pages are enabled, although the mm layer still returns an array of page pointers, a subset (or all) of them may have the same page head since a max 180kb skb can span 2 hugepages if it is on the boundary, be a mix of pages and 1 hugepage, or fit completely in a hugepage. Instead of referencing page head on all page pointers, use page length arithmetic to only call page head when referencing a known different page head to avoid touching a cold cacheline.
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 11 lines · On Tue, 21 Mar 2023 16:12:01 +0800 you wrote:
From: Xiaoyan Li <[email protected]>
When compound pages are enabled, although the mm layer still returns an array of page pointers, a subset (or all) of them may have the same page head since a max 180kb skb can span 2 hugepages if it is on the boundary, be a mix of pages and 1 hugepage, or fit completely in a hugepage. Instead of referencing page head on all page pointers, use page length arithmetic to only call page head when referencing a known different page head to avoid touching a cold cacheline.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,1/2] net-zerocopy: Reduce compound page head access
https://git.kernel.org/netdev/net-next/c/593ef60c7445 - [net-next,2/2] selftests/net: Add SHA256 computation over data sent in tcp_mmap https://git.kernel.org/netdev/net-next/c/5c5945dc695c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html