From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, willemb@google.com,
eric.dumazet@gmail.com, dsahern@gmail.com,
yoshfuji@linux-ipv6.org, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next v2 1/2] net: ip: refactor SG checks
Date: Tue, 22 Jun 2021 15:50:56 -0700 [thread overview]
Message-ID: <20210622225057.2108592-1-kuba@kernel.org> (raw)
There is a number of rt->dst.dev->features & NETIF_F_SG checks
scattered throughout the code. Shorten the lines by caching
the result of this check.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
net/ipv4/ip_output.c | 13 ++++++-------
net/ipv6/ip6_output.c | 13 ++++++-------
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index c3efc7d658f6..90031f5446bd 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -981,12 +981,14 @@ static int __ip_append_data(struct sock *sk,
unsigned int maxfraglen, fragheaderlen, maxnonfragsize;
int csummode = CHECKSUM_NONE;
struct rtable *rt = (struct rtable *)cork->dst;
+ bool has_sg, paged, extra_uref = false;
unsigned int wmem_alloc_delta = 0;
- bool paged, extra_uref = false;
u32 tskey = 0;
skb = skb_peek_tail(queue);
+ has_sg = rt->dst.dev->features & NETIF_F_SG;
+
exthdrlen = !skb ? rt->dst.header_len : 0;
mtu = cork->gso_size ? IP_MAX_MTU : cork->fragsize;
paged = !!cork->gso_size;
@@ -1023,8 +1025,7 @@ static int __ip_append_data(struct sock *sk,
if (!uarg)
return -ENOBUFS;
extra_uref = !skb_zcopy(skb); /* only ref on new uarg */
- if (rt->dst.dev->features & NETIF_F_SG &&
- csummode == CHECKSUM_PARTIAL) {
+ if (has_sg && csummode == CHECKSUM_PARTIAL) {
paged = true;
} else {
uarg->zerocopy = 0;
@@ -1074,8 +1075,7 @@ static int __ip_append_data(struct sock *sk,
fraglen = datalen + fragheaderlen;
pagedlen = 0;
- if ((flags & MSG_MORE) &&
- !(rt->dst.dev->features&NETIF_F_SG))
+ if ((flags & MSG_MORE) && !has_sg)
alloclen = mtu;
else if (!paged)
alloclen = fraglen;
@@ -1174,8 +1174,7 @@ static int __ip_append_data(struct sock *sk,
if (copy > length)
copy = length;
- if (!(rt->dst.dev->features&NETIF_F_SG) &&
- skb_tailroom(skb) >= copy) {
+ if (!has_sg && skb_tailroom(skb) >= copy) {
unsigned int off;
off = skb->len;
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index ff4f9ebcf7f6..c667b7e2856f 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1444,8 +1444,8 @@ static int __ip6_append_data(struct sock *sk,
struct ipv6_txoptions *opt = v6_cork->opt;
int csummode = CHECKSUM_NONE;
unsigned int maxnonfragsize, headersize;
+ bool has_sg, paged, extra_uref = false;
unsigned int wmem_alloc_delta = 0;
- bool paged, extra_uref = false;
skb = skb_peek_tail(queue);
if (!skb) {
@@ -1453,6 +1453,8 @@ static int __ip6_append_data(struct sock *sk,
dst_exthdrlen = rt->dst.header_len - rt->rt6i_nfheader_len;
}
+ has_sg = rt->dst.dev->features & NETIF_F_SG;
+
paged = !!cork->gso_size;
mtu = cork->gso_size ? IP6_MAX_MTU : cork->fragsize;
orig_mtu = mtu;
@@ -1515,8 +1517,7 @@ static int __ip6_append_data(struct sock *sk,
if (!uarg)
return -ENOBUFS;
extra_uref = !skb_zcopy(skb); /* only ref on new uarg */
- if (rt->dst.dev->features & NETIF_F_SG &&
- csummode == CHECKSUM_PARTIAL) {
+ if (has_sg && csummode == CHECKSUM_PARTIAL) {
paged = true;
} else {
uarg->zerocopy = 0;
@@ -1582,8 +1583,7 @@ static int __ip6_append_data(struct sock *sk,
fraglen = datalen + fragheaderlen;
pagedlen = 0;
- if ((flags & MSG_MORE) &&
- !(rt->dst.dev->features&NETIF_F_SG))
+ if ((flags & MSG_MORE) && !has_sg)
alloclen = mtu;
else if (!paged)
alloclen = fraglen;
@@ -1698,8 +1698,7 @@ static int __ip6_append_data(struct sock *sk,
if (copy > length)
copy = length;
- if (!(rt->dst.dev->features&NETIF_F_SG) &&
- skb_tailroom(skb) >= copy) {
+ if (!has_sg && skb_tailroom(skb) >= copy) {
unsigned int off;
off = skb->len;
--
2.31.1
next reply other threads:[~2021-06-22 22:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-22 22:50 Jakub Kicinski [this message]
2021-06-22 22:50 ` [PATCH net-next v2 2/2] net: ip: avoid OOM kills with large UDP sends over loopback Jakub Kicinski
2021-06-23 14:25 ` Eric Dumazet
2021-06-23 15:58 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210622225057.2108592-1-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=eric.dumazet@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=willemb@google.com \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).