From: Wei Wang <weiwan@google.com>
To: "David S . Miller" <davem@davemloft.net>,
netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Cc: Shakeel Butt <shakeelb@google.com>, Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next 2/3] tcp: adjust sndbuf according to sk_reserved_mem
Date: Mon, 27 Sep 2021 11:25:22 -0700 [thread overview]
Message-ID: <20210927182523.2704818-3-weiwan@google.com> (raw)
In-Reply-To: <20210927182523.2704818-1-weiwan@google.com>
If user sets SO_RESERVE_MEM socket option, in order to fully utilize the
reserved memory in memory pressure state on the tx path, we modify the
logic in sk_stream_moderate_sndbuf() to set sk_sndbuf according to
available reserved memory, instead of MIN_SOCK_SNDBUF, and adjust it
when new data is acked.
Signed-off-by: Wei Wang <weiwan@google.com>
Signed-off-by: Eric Dumazet <edumazet@google.com>
---
include/net/sock.h | 1 +
net/ipv4/tcp_input.c | 14 ++++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index b0df2d3843fd..e6ad628adcd2 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2388,6 +2388,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
return;
val = min(sk->sk_sndbuf, sk->sk_wmem_queued >> 1);
+ val = max_t(u32, val, sk_unused_reserved_mem(sk));
WRITE_ONCE(sk->sk_sndbuf, max_t(u32, val, SOCK_MIN_SNDBUF));
}
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 141e85e6422b..a7611256f235 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -5381,7 +5381,7 @@ static int tcp_prune_queue(struct sock *sk)
return -1;
}
-static bool tcp_should_expand_sndbuf(const struct sock *sk)
+static bool tcp_should_expand_sndbuf(struct sock *sk)
{
const struct tcp_sock *tp = tcp_sk(sk);
@@ -5392,8 +5392,18 @@ static bool tcp_should_expand_sndbuf(const struct sock *sk)
return false;
/* If we are under global TCP memory pressure, do not expand. */
- if (tcp_under_memory_pressure(sk))
+ if (tcp_under_memory_pressure(sk)) {
+ int unused_mem = sk_unused_reserved_mem(sk);
+
+ /* Adjust sndbuf according to reserved mem. But make sure
+ * it never goes below SOCK_MIN_SNDBUF.
+ * See sk_stream_moderate_sndbuf() for more details.
+ */
+ if (unused_mem > SOCK_MIN_SNDBUF)
+ WRITE_ONCE(sk->sk_sndbuf, unused_mem);
+
return false;
+ }
/* If we are under soft global TCP memory pressure, do not expand. */
if (sk_memory_allocated(sk) >= sk_prot_mem_limits(sk, 0))
--
2.33.0.685.g46640cef36-goog
next prev parent reply other threads:[~2021-09-27 18:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-27 18:25 [PATCH net-next 0/3] net: add new socket option SO_RESERVE_MEM Wei Wang
2021-09-27 18:25 ` [PATCH net-next 1/3] " Wei Wang
2021-09-27 18:25 ` Wei Wang [this message]
2021-09-27 18:25 ` [PATCH net-next 3/3] tcp: adjust rcv_ssthresh according to sk_reserved_mem Wei Wang
2021-09-28 0:50 ` [PATCH net-next 0/3] net: add new socket option SO_RESERVE_MEM Jakub Kicinski
2021-09-28 3:33 ` Wei Wang
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=20210927182523.2704818-3-weiwan@google.com \
--to=weiwan@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=shakeelb@google.com \
/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).