Commit def87cf4 authored by Krishna Kumar's avatar Krishna Kumar Committed by David S. Miller

tcp: Slightly optimize tcp_sendmsg

Slightly optimize tcp_sendmsg since NETIF_F_SG is used many
times iteratively in the loop. The only other modification is
to change:
			} else if (i == MAX_SKB_FRAGS ||
				   (!i &&
				   !(sk->sk_route_caps & NETIF_F_SG))) {
	to:
			} else if (i == MAX_SKB_FRAGS || !sg) {

The reason why this change is correct: this code (other than
the MAX_SKB_FRAGS case) executes only due to the else part
of: "if (skb_tailroom(skb) > 0) {" - i.e. there was no space
in the skb to put the data inline. Hence SG is false is a
sufficient condition, and there is no way a fragment can be
added to the skb.

Changelog:
	- Added the above explanation for the change
Signed-off-by: default avatarKrishna Kumar <krkumar2@in.ibm.com>
Acked-by: default avatarIlpo Järvinen <ilpo.jarvinen@helsinki.fi>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent afeca340
...@@ -876,12 +876,12 @@ ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset, ...@@ -876,12 +876,12 @@ ssize_t tcp_sendpage(struct socket *sock, struct page *page, int offset,
#define TCP_PAGE(sk) (sk->sk_sndmsg_page) #define TCP_PAGE(sk) (sk->sk_sndmsg_page)
#define TCP_OFF(sk) (sk->sk_sndmsg_off) #define TCP_OFF(sk) (sk->sk_sndmsg_off)
static inline int select_size(struct sock *sk) static inline int select_size(struct sock *sk, int sg)
{ {
struct tcp_sock *tp = tcp_sk(sk); struct tcp_sock *tp = tcp_sk(sk);
int tmp = tp->mss_cache; int tmp = tp->mss_cache;
if (sk->sk_route_caps & NETIF_F_SG) { if (sg) {
if (sk_can_gso(sk)) if (sk_can_gso(sk))
tmp = 0; tmp = 0;
else { else {
...@@ -905,7 +905,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, ...@@ -905,7 +905,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
struct sk_buff *skb; struct sk_buff *skb;
int iovlen, flags; int iovlen, flags;
int mss_now, size_goal; int mss_now, size_goal;
int err, copied; int sg, err, copied;
long timeo; long timeo;
lock_sock(sk); lock_sock(sk);
...@@ -933,6 +933,8 @@ int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, ...@@ -933,6 +933,8 @@ int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN))
goto out_err; goto out_err;
sg = sk->sk_route_caps & NETIF_F_SG;
while (--iovlen >= 0) { while (--iovlen >= 0) {
int seglen = iov->iov_len; int seglen = iov->iov_len;
unsigned char __user *from = iov->iov_base; unsigned char __user *from = iov->iov_base;
...@@ -958,8 +960,9 @@ int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, ...@@ -958,8 +960,9 @@ int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
if (!sk_stream_memory_free(sk)) if (!sk_stream_memory_free(sk))
goto wait_for_sndbuf; goto wait_for_sndbuf;
skb = sk_stream_alloc_skb(sk, select_size(sk), skb = sk_stream_alloc_skb(sk,
sk->sk_allocation); select_size(sk, sg),
sk->sk_allocation);
if (!skb) if (!skb)
goto wait_for_memory; goto wait_for_memory;
...@@ -996,9 +999,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, ...@@ -996,9 +999,7 @@ int tcp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
/* We can extend the last page /* We can extend the last page
* fragment. */ * fragment. */
merge = 1; merge = 1;
} else if (i == MAX_SKB_FRAGS || } else if (i == MAX_SKB_FRAGS || !sg) {
(!i &&
!(sk->sk_route_caps & NETIF_F_SG))) {
/* Need to add new fragment and cannot /* Need to add new fragment and cannot
* do this because interface is non-SG, * do this because interface is non-SG,
* or because all the page slots are * or because all the page slots are
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment