From: Martin KaFai Lau <martin.lau@linux.dev>
To: Kuniyuki Iwashima <kuniyu@google.com>,
Shakeel Butt <shakeel.butt@linux.dev>
Cc: Alexei Starovoitov <ast@kernel.org>,
Andrii Nakryiko <andrii@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Neal Cardwell <ncardwell@google.com>,
Willem de Bruijn <willemb@google.com>,
Mina Almasry <almasrymina@google.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>,
bpf@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH v4 bpf-next/net 4/5] net-memcg: Allow decoupling memcg from global protocol memory accounting.
Date: Tue, 2 Sep 2025 13:16:50 -0700 [thread overview]
Message-ID: <4334e29b-1cd0-48ba-9afa-54d01b1b7143@linux.dev> (raw)
In-Reply-To: <20250829010026.347440-5-kuniyu@google.com>
On 8/28/25 6:00 PM, Kuniyuki Iwashima wrote:
> +static inline bool sk_should_enter_memory_pressure(struct sock *sk)
> +{
> + return !mem_cgroup_sk_enabled(sk) || !mem_cgroup_sk_isolated(sk);
> +}
> +
> static inline long
> proto_memory_allocated(const struct proto *prot)
> {
> @@ -3154,8 +3158,11 @@ bool sk_page_frag_refill(struct sock *sk, struct page_frag *pfrag)
> if (likely(skb_page_frag_refill(32U, pfrag, sk->sk_allocation)))
> return true;
>
> - sk_enter_memory_pressure(sk);
> + if (sk_should_enter_memory_pressure(sk))
> + sk_enter_memory_pressure(sk);
> +
> sk_stream_moderate_sndbuf(sk);
> +
> return false;
> }
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 71a956fbfc55..dcbd49e2f8af 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -908,7 +908,8 @@ struct sk_buff *tcp_stream_alloc_skb(struct sock *sk, gfp_t gfp,
> }
> __kfree_skb(skb);
> } else {
> - sk->sk_prot->enter_memory_pressure(sk);
> + if (sk_should_enter_memory_pressure(sk))
> + tcp_enter_memory_pressure(sk);
This change from sk_prot->enter_memory_pressure to tcp_enter_memory_pressure
looks fine. A qq / nit, have you thought about checking
sk_should_enter_memory_pressure inside the tcp_enter_memory_pressure(sk) /
sk_enter_memory_pressure(sk) ?
Other changes of patch 4 lgtm.
Shakeel, you have ack-ed patch 1. Will you take a look at patch 3 and patch 4 also?
> sk_stream_moderate_sndbuf(sk);
> }
> @@ -1016,7 +1017,7 @@ static void mptcp_enter_memory_pressure(struct sock *sk)
> mptcp_for_each_subflow(msk, subflow) {
> struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
>
> - if (first)
> + if (first && sk_should_enter_memory_pressure(ssk))
> tcp_enter_memory_pressure(ssk);
> sk_stream_moderate_sndbuf(ssk);
>
> diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
> index f672a62a9a52..6696ef837116 100644
> --- a/net/tls/tls_device.c
> +++ b/net/tls/tls_device.c
> @@ -35,6 +35,7 @@
> #include <linux/netdevice.h>
> #include <net/dst.h>
> #include <net/inet_connection_sock.h>
> +#include <net/proto_memory.h>
> #include <net/tcp.h>
> #include <net/tls.h>
> #include <linux/skbuff_ref.h>
> @@ -371,7 +372,8 @@ static int tls_do_allocation(struct sock *sk,
> if (!offload_ctx->open_record) {
> if (unlikely(!skb_page_frag_refill(prepend_size, pfrag,
> sk->sk_allocation))) {
> - READ_ONCE(sk->sk_prot)->enter_memory_pressure(sk);
> + if (sk_should_enter_memory_pressure(sk))
> + READ_ONCE(sk->sk_prot)->enter_memory_pressure(sk);
> sk_stream_moderate_sndbuf(sk);
> return -ENOMEM;
> }
next prev parent reply other threads:[~2025-09-02 20:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 1:00 [PATCH v4 bpf-next/net 0/5] bpf: Allow decoupling memcg from sk->sk_prot->memory_allocated Kuniyuki Iwashima
2025-08-29 1:00 ` [PATCH v4 bpf-next/net 1/5] tcp: Save lock_sock() for memcg in inet_csk_accept() Kuniyuki Iwashima
2025-09-02 18:55 ` Martin KaFai Lau
2025-09-02 19:32 ` Kuniyuki Iwashima
2025-08-29 1:00 ` [PATCH v4 bpf-next/net 2/5] bpf: Support bpf_setsockopt() for BPF_CGROUP_INET_SOCK_CREATE Kuniyuki Iwashima
2025-09-02 19:10 ` Martin KaFai Lau
2025-09-02 19:33 ` Kuniyuki Iwashima
2025-08-29 1:00 ` [PATCH v4 bpf-next/net 3/5] bpf: Introduce SK_BPF_MEMCG_FLAGS and SK_BPF_MEMCG_SOCK_ISOLATED Kuniyuki Iwashima
2025-09-02 20:02 ` Martin KaFai Lau
2025-09-02 20:13 ` Kuniyuki Iwashima
2025-08-29 1:00 ` [PATCH v4 bpf-next/net 4/5] net-memcg: Allow decoupling memcg from global protocol memory accounting Kuniyuki Iwashima
2025-09-02 20:16 ` Martin KaFai Lau [this message]
2025-09-02 20:45 ` Kuniyuki Iwashima
2025-08-29 1:00 ` [PATCH v4 bpf-next/net 5/5] selftest: bpf: Add test for SK_BPF_MEMCG_SOCK_ISOLATED Kuniyuki Iwashima
2025-09-02 20:26 ` Martin KaFai Lau
2025-09-02 20:49 ` Kuniyuki Iwashima
2025-09-03 16:59 ` Kuniyuki Iwashima
2025-09-03 17:08 ` Kuniyuki Iwashima
2025-09-04 5:50 ` Martin KaFai Lau
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=4334e29b-1cd0-48ba-9afa-54d01b1b7143@linux.dev \
--to=martin.lau@linux.dev \
--cc=almasrymina@google.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hannes@cmpxchg.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=kuniyu@google.com \
--cc=mhocko@kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=roman.gushchin@linux.dev \
--cc=sdf@fomichev.me \
--cc=shakeel.butt@linux.dev \
--cc=willemb@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).