Skip to content

Commit 35f9c09

Browse files
Eric Dumazetdavem330
authored andcommitted
tcp: tcp_sendpages() should call tcp_push() once
commit 2f53384 (tcp: allow splice() to build full TSO packets) added a regression for splice() calls using SPLICE_F_MORE. We need to call tcp_flush() at the end of the last page processed in tcp_sendpages(), or else transmits can be deferred and future sends stall. Add a new internal flag, MSG_SENDPAGE_NOTLAST, acting like MSG_MORE, but with different semantic. For all sendpage() providers, its a transparent change. Only sock_sendpage() and tcp_sendpages() can differentiate the two different flags provided by pipe_to_sendpage() Reported-by: Tom Herbert <[email protected]> Cc: Nandita Dukkipati <[email protected]> Cc: Neal Cardwell <[email protected]> Cc: Tom Herbert <[email protected]> Cc: Yuchung Cheng <[email protected]> Cc: H.K. Jerry Chu <[email protected]> Cc: Maciej Żenczykowski <[email protected]> Cc: Mahesh Bandewar <[email protected]> Cc: Ilpo Järvinen <[email protected]> Signed-off-by: Eric Dumazet <eric.dumazet@gmail>com> Signed-off-by: David S. Miller <[email protected]>
1 parent 78d5021 commit 35f9c09

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

fs/splice.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/uio.h>
3131
#include <linux/security.h>
3232
#include <linux/gfp.h>
33+
#include <linux/socket.h>
3334

3435
/*
3536
* Attempt to steal a page from a pipe buffer. This should perhaps go into
@@ -690,7 +691,9 @@ static int pipe_to_sendpage(struct pipe_inode_info *pipe,
690691
if (!likely(file->f_op && file->f_op->sendpage))
691692
return -EINVAL;
692693

693-
more = (sd->flags & SPLICE_F_MORE) || sd->len < sd->total_len;
694+
more = (sd->flags & SPLICE_F_MORE) ? MSG_MORE : 0;
695+
if (sd->len < sd->total_len)
696+
more |= MSG_SENDPAGE_NOTLAST;
694697
return file->f_op->sendpage(file, buf->page, buf->offset,
695698
sd->len, &pos, more);
696699
}

include/linux/socket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ struct ucred {
265265
#define MSG_NOSIGNAL 0x4000 /* Do not generate SIGPIPE */
266266
#define MSG_MORE 0x8000 /* Sender will send more */
267267
#define MSG_WAITFORONE 0x10000 /* recvmmsg(): block until 1+ packets avail */
268-
268+
#define MSG_SENDPAGE_NOTLAST 0x20000 /* sendpage() internal : not the last page */
269269
#define MSG_EOF MSG_FIN
270270

271271
#define MSG_CMSG_CLOEXEC 0x40000000 /* Set close_on_exit for file

net/ipv4/tcp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page **pages, int poffse
860860
}
861861

862862
out:
863-
if (copied && !(flags & MSG_MORE))
863+
if (copied && !(flags & MSG_SENDPAGE_NOTLAST))
864864
tcp_push(sk, flags, mss_now, tp->nonagle);
865865
return copied;
866866

net/socket.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,9 @@ static ssize_t sock_sendpage(struct file *file, struct page *page,
811811

812812
sock = file->private_data;
813813

814-
flags = !(file->f_flags & O_NONBLOCK) ? 0 : MSG_DONTWAIT;
815-
if (more)
816-
flags |= MSG_MORE;
814+
flags = (file->f_flags & O_NONBLOCK) ? MSG_DONTWAIT : 0;
815+
/* more is a combination of MSG_MORE and MSG_SENDPAGE_NOTLAST */
816+
flags |= more;
817817

818818
return kernel_sendpage(sock, page, offset, size, flags);
819819
}

0 commit comments

Comments
 (0)