Skip to content

Commit d1a6150

Browse files
arjunroygregkh
authored andcommitted
net-zerocopy: Refactor skb frag fast-forward op.
[ Upstream commit 7fba530 ] Refactor skb frag fast-forwarding for tcp receive zerocopy. This is part of a patch set that introduces short-circuited hybrid copies for small receive operations, which results in roughly 33% fewer syscalls for small RPC scenarios. skb_advance_to_frag(), given a skb and an offset into the skb, iterates from the first frag for the skb until we're at the frag specified by the offset. Assuming the offset provided refers to how many bytes in the skb are already read, the returned frag points to the next frag we may read from, while offset_frag is set to the number of bytes from this frag that we have already read. If frag is not null and offset_frag is equal to 0, then we may be able to map this frag's page into the process address space with vm_insert_page(). However, if offset_frag is not equal to 0, then we cannot do so. Signed-off-by: Arjun Roy <arjunroy@google.com> Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Soheil Hassas Yeganeh <soheil@google.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5f7aadf commit d1a6150

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

‎net/ipv4/tcp.c‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,6 +1746,28 @@ int tcp_mmap(struct file *file, struct socket *sock,
17461746
}
17471747
EXPORT_SYMBOL(tcp_mmap);
17481748

1749+
static skb_frag_t *skb_advance_to_frag(struct sk_buff *skb, u32 offset_skb,
1750+
u32 *offset_frag)
1751+
{
1752+
skb_frag_t *frag;
1753+
1754+
offset_skb -= skb_headlen(skb);
1755+
if ((int)offset_skb < 0 || skb_has_frag_list(skb))
1756+
return NULL;
1757+
1758+
frag = skb_shinfo(skb)->frags;
1759+
while (offset_skb) {
1760+
if (skb_frag_size(frag) > offset_skb) {
1761+
*offset_frag = offset_skb;
1762+
return frag;
1763+
}
1764+
offset_skb -= skb_frag_size(frag);
1765+
++frag;
1766+
}
1767+
*offset_frag = 0;
1768+
return frag;
1769+
}
1770+
17491771
static int tcp_copy_straggler_data(struct tcp_zerocopy_receive *zc,
17501772
struct sk_buff *skb, u32 copylen,
17511773
u32 *offset, u32 *seq)
@@ -1872,6 +1894,8 @@ static int tcp_zerocopy_receive(struct sock *sk,
18721894
curr_addr = address;
18731895
while (length + PAGE_SIZE <= zc->length) {
18741896
if (zc->recv_skip_hint < PAGE_SIZE) {
1897+
u32 offset_frag;
1898+
18751899
/* If we're here, finish the current batch. */
18761900
if (pg_idx) {
18771901
ret = tcp_zerocopy_vm_insert_batch(vma, pages,
@@ -1892,16 +1916,9 @@ static int tcp_zerocopy_receive(struct sock *sk,
18921916
skb = tcp_recv_skb(sk, seq, &offset);
18931917
}
18941918
zc->recv_skip_hint = skb->len - offset;
1895-
offset -= skb_headlen(skb);
1896-
if ((int)offset < 0 || skb_has_frag_list(skb))
1919+
frags = skb_advance_to_frag(skb, offset, &offset_frag);
1920+
if (!frags || offset_frag)
18971921
break;
1898-
frags = skb_shinfo(skb)->frags;
1899-
while (offset) {
1900-
if (skb_frag_size(frags) > offset)
1901-
goto out;
1902-
offset -= skb_frag_size(frags);
1903-
frags++;
1904-
}
19051922
}
19061923
if (skb_frag_size(frags) != PAGE_SIZE || skb_frag_off(frags)) {
19071924
int remaining = zc->recv_skip_hint;

0 commit comments

Comments
 (0)