Skip to content

Commit 7fba530

Browse files
arjunroykuba-moo
authored andcommitted
net-zerocopy: Refactor skb frag fast-forward op.
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>
1 parent 2cd8116 commit 7fba530

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
@@ -1758,6 +1758,28 @@ int tcp_mmap(struct file *file, struct socket *sock,
17581758
}
17591759
EXPORT_SYMBOL(tcp_mmap);
17601760

1761+
static skb_frag_t *skb_advance_to_frag(struct sk_buff *skb, u32 offset_skb,
1762+
u32 *offset_frag)
1763+
{
1764+
skb_frag_t *frag;
1765+
1766+
offset_skb -= skb_headlen(skb);
1767+
if ((int)offset_skb < 0 || skb_has_frag_list(skb))
1768+
return NULL;
1769+
1770+
frag = skb_shinfo(skb)->frags;
1771+
while (offset_skb) {
1772+
if (skb_frag_size(frag) > offset_skb) {
1773+
*offset_frag = offset_skb;
1774+
return frag;
1775+
}
1776+
offset_skb -= skb_frag_size(frag);
1777+
++frag;
1778+
}
1779+
*offset_frag = 0;
1780+
return frag;
1781+
}
1782+
17611783
static int tcp_copy_straggler_data(struct tcp_zerocopy_receive *zc,
17621784
struct sk_buff *skb, u32 copylen,
17631785
u32 *offset, u32 *seq)
@@ -1884,6 +1906,8 @@ static int tcp_zerocopy_receive(struct sock *sk,
18841906
curr_addr = address;
18851907
while (length + PAGE_SIZE <= zc->length) {
18861908
if (zc->recv_skip_hint < PAGE_SIZE) {
1909+
u32 offset_frag;
1910+
18871911
/* If we're here, finish the current batch. */
18881912
if (pg_idx) {
18891913
ret = tcp_zerocopy_vm_insert_batch(vma, pages,
@@ -1904,16 +1928,9 @@ static int tcp_zerocopy_receive(struct sock *sk,
19041928
skb = tcp_recv_skb(sk, seq, &offset);
19051929
}
19061930
zc->recv_skip_hint = skb->len - offset;
1907-
offset -= skb_headlen(skb);
1908-
if ((int)offset < 0 || skb_has_frag_list(skb))
1931+
frags = skb_advance_to_frag(skb, offset, &offset_frag);
1932+
if (!frags || offset_frag)
19091933
break;
1910-
frags = skb_shinfo(skb)->frags;
1911-
while (offset) {
1912-
if (skb_frag_size(frags) > offset)
1913-
goto out;
1914-
offset -= skb_frag_size(frags);
1915-
frags++;
1916-
}
19171934
}
19181935
if (skb_frag_size(frags) != PAGE_SIZE || skb_frag_off(frags)) {
19191936
int remaining = zc->recv_skip_hint;

0 commit comments

Comments
 (0)