Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tls: rx: periodically flush socket backlog

We continuously hold the socket lock during large reads and writes.
This may inflate RTT and negatively impact TCP performance.
Flush the backlog periodically. I tried to pick a flush period (128kB)
which gives significant benefit but the max Bps rate is not yet visibly
impacted.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jakub Kicinski and committed by
David S. Miller
c46b0183 f36068a2

+24
+1
net/core/sock.c
··· 2870 2870 __release_sock(sk); 2871 2871 spin_unlock_bh(&sk->sk_lock.slock); 2872 2872 } 2873 + EXPORT_SYMBOL_GPL(__sk_flush_backlog); 2873 2874 2874 2875 /** 2875 2876 * sk_wait_data - wait for data to arrive at sk_receive_queue
+23
net/tls/tls_sw.c
··· 1738 1738 return copied ? : err; 1739 1739 } 1740 1740 1741 + static void 1742 + tls_read_flush_backlog(struct sock *sk, struct tls_prot_info *prot, 1743 + size_t len_left, size_t decrypted, ssize_t done, 1744 + size_t *flushed_at) 1745 + { 1746 + size_t max_rec; 1747 + 1748 + if (len_left <= decrypted) 1749 + return; 1750 + 1751 + max_rec = prot->overhead_size - prot->tail_size + TLS_MAX_PAYLOAD_SIZE; 1752 + if (done - *flushed_at < SZ_128K && tcp_inq(sk) > max_rec) 1753 + return; 1754 + 1755 + *flushed_at = done; 1756 + sk_flush_backlog(sk); 1757 + } 1758 + 1741 1759 int tls_sw_recvmsg(struct sock *sk, 1742 1760 struct msghdr *msg, 1743 1761 size_t len, ··· 1768 1750 struct sk_psock *psock; 1769 1751 unsigned char control = 0; 1770 1752 ssize_t decrypted = 0; 1753 + size_t flushed_at = 0; 1771 1754 struct strp_msg *rxm; 1772 1755 struct tls_msg *tlm; 1773 1756 struct sk_buff *skb; ··· 1857 1838 err = tls_record_content_type(msg, tlm, &control); 1858 1839 if (err <= 0) 1859 1840 goto recv_end; 1841 + 1842 + /* periodically flush backlog, and feed strparser */ 1843 + tls_read_flush_backlog(sk, prot, len, to_decrypt, 1844 + decrypted + copied, &flushed_at); 1860 1845 1861 1846 ctx->recv_pkt = NULL; 1862 1847 __strp_unpause(&ctx->strp);