Splice network receive support
Subsystems (5)
cover Splice network receive support
Hi,
This series of patches applies on top of the splice series just posted. It implements basic network receive support, ie splicing from a socket to a pipe.
There seems to be a skhead_buff_cache leak somewhere that I need to track down, otherwise it works fine for me.
Signature · 1 line
Jens Axboe
PATCH 1/3 splice: don't assume regular pages in splice_to_pipe()
Allow caller to pass in a release function, there might be other resources that need releasing as well. Needed for network receive.
Signed-off-by Jens Axboe <[email protected]>
--- fs/splice.c | 9 ++++++++- include/linux/splice.h | 1 + 2 files changed, 9 insertions(+), 1 deletions(-)
fs/splice.c +8 -1
@@ -247,11 +247,16 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe, }while (page_nr < spd->nr_pages) -page_cache_release (spd->pages[page_nr++]); + spd->spd_release (spd, page_nr++);return ret; } +static void spd_release_page (struct splice_pipe_desc *spd,unsigned int i) +{ +page_cache_release (spd->pages[i]); +} + static int __generic_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe, size_t len,
@@ -270,6 +275,7 @@ __generic_file_splice_read(struct file *in, loff_t *ppos, .partial = partial, .flags = flags, .ops = &page_cache_pipe_buf_ops, + .spd_release = spd_release_page, }; index = *ppos >>PAGE_CACHE_SHIFT ;
@@ -1442,6 +1448,7 @@ static long vmsplice_to_pipe(struct file *file, const struct iovec __user *iov, .partial = partial, .flags = flags, .ops = &user_page_pipe_buf_ops, + .spd_release = spd_release_page, }; pipe =pipe_info (file->f_path.dentry->d_inode);
include/linux/splice.h +1 -0
@@ -53,6 +53,7 @@ struct splice_pipe_desc {int nr_pages;/* number of pages in map */ unsigned int flags;/* splice flags */ const struct pipe_buf_operations *ops;/* ops associated with output pipe */ +void (*spd_release)(struct splice_pipe_desc *,unsigned int ); }; typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *,
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 2/3 tcp_read_sock: alloc recv_actor() return return negative error value
In reply to Jens AxboeSigned-off-by Jens Axboe <[email protected]>
--- net/ipv4/tcp.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
net/ipv4/tcp.c +6 -2
@@ -1064,7 +1064,11 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,break ; } used =recv_actor (desc, skb, offset, len); -if (used <= len) { +if (used <0 ) { +if (!copied) + copied = used; +break ; + }else if (used <= len) { seq += used; copied += used; offset += used;
@@ -1086,7 +1090,7 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,tcp_rcv_space_adjust (sk);/* Clean up data we have read: This will do ACK frames. */ -if (copied) +if (copied >0 )tcp_cleanup_rbuf (sk, copied);return copied; }
Signature · 1 line
1.5.2.1.174.gcd03
PATCH 3/3 TCP splice receive support
In reply to Jens AxboeSupport for network splice receive.
Signed-off-by Jens Axboe <[email protected]>
--- include/linux/net.h | 3 + include/linux/skbuff.h | 5 + include/net/tcp.h | 3 + net/core/skbuff.c | 231 ++++++++++++++++++++++++++++++++++++++++++++++++ net/ipv4/af_inet.c | 1 + net/ipv4/tcp.c | 129 +++++++++++++++++++++++++++ net/socket.c | 13 +++ 7 files changed, 385 insertions(+), 0 deletions(-)
include/linux/net.h +3 -0
@@ -19,6 +19,7 @@#define _LINUX_NET_H#include <linux/wait.h> +#include <linux/splice.h> #include <asm/socket.h> struct poll_table_struct ;
@@ -165,6 +166,8 @@ struct proto_ops { struct vm_area_struct * vma);ssize_t (*sendpage) (struct socket *sock,struct page *page,int offset,size_t size,int flags); +ssize_t (*splice_read)(struct socket *sock,loff_t *ppos, +struct pipe_inode_info *pipe,size_t len,unsigned int flags); };struct net_proto_family {
include/linux/skbuff.h +5 -0
@@ -1504,6 +1504,11 @@ extern int skb_store_bits(struct sk_buff *skb, int offset,extern __wsum skb_copy_and_csum_bits (const struct sk_buff *skb,int offset,u8 *to,int len,__wsum csum); +extern int skb_splice_bits (struct sk_buff *skb, +unsigned int offset, +struct pipe_inode_info *pipe, +unsigned int len, +unsigned int flags);extern void skb_copy_and_csum_dev (const struct sk_buff *skb,u8 *to);extern void skb_split (struct sk_buff *skb,struct sk_buff *skb1,const u32 len);
include/net/tcp.h +3 -0
@@ -308,6 +308,9 @@ extern int tcp_twsk_unique(struct sock *sk,extern void tcp_twsk_destructor (struct sock *sk); +extern ssize_t tcp_splice_read (struct socket *sk,loff_t *ppos, +struct pipe_inode_info *pipe,size_t len,unsigned int flags); +static inline void tcp_dec_quickack_mode (struct sock *sk,const unsigned int pkts) {
net/core/skbuff.c +231 -0
249 lines not on this page · raw message
net/ipv4/af_inet.c +1 -0
@@ -835,6 +835,7 @@ const struct proto_ops inet_stream_ops = { .recvmsg = sock_common_recvmsg, .mmap = sock_no_mmap, .sendpage = tcp_sendpage, + .splice_read = tcp_splice_read, #ifdef CONFIG_COMPAT .compat_setsockopt = compat_sock_common_setsockopt, .compat_getsockopt = compat_sock_common_getsockopt,
net/ipv4/tcp.c +129 -0
159 lines not on this page · raw message
net/socket.c +13 -0
@@ -111,6 +111,9 @@ static long compat_sock_ioctl(struct file *file,static int sock_fasync (int fd,struct file *filp,int on);static ssize_t sock_sendpage (struct file *file,struct page *page,int offset,size_t size,loff_t *ppos,int more); +static ssize_t sock_splice_read (struct file *file,loff_t *ppos, +struct pipe_inode_info *pipe,size_t len, +unsigned int flags);/* * Socket files have a set of 'special' operations as well as the generic file ones. These don't appear
@@ -133,6 +136,7 @@ static const struct file_operations socket_file_ops = { .fasync = sock_fasync, .sendpage = sock_sendpage, .splice_write = generic_splice_sendpage, + .splice_read = sock_splice_read, };/*
@@ -691,6 +695,15 @@ static ssize_t sock_sendpage(struct file *file, struct page *page,return sock->ops->sendpage (sock, page, offset, size, flags); } +static ssize_t sock_splice_read (struct file *file,loff_t *ppos, +struct pipe_inode_info *pipe,size_t len, +unsigned int flags) +{ +struct socket *sock = file->private_data; + +return sock->ops->splice_read (sock, ppos, pipe, len, flags); +} +static struct sock_iocb *alloc_sock_iocb (struct kiocb *iocb,struct sock_iocb *siocb) {
Signature · 1 line
1.5.2.1.174.gcd03