From: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.2 3/9] ms/net: factor-out _sk_charge() helper
Date: Thu, 19 Nov 2026 06:35:28 +0200 [thread overview]
Message-ID: <20261119044702.1218722-4-eva.kurchatova@virtuozzo.com> (raw)
In-Reply-To: <20261119044702.1218722-1-eva.kurchatova@virtuozzo.com>
From: Paolo Abeni <pabeni@redhat.com>
Move out of __inet_accept() the code dealing charging newly
accepted socket to memcg. MPTCP will soon use it to on a per
subflow basis, in different contexts.
No functional changes intended.
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Acked-by: Geliang Tang <geliang@kernel.org>
Acked-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://patch.msgid.link/20251121-net-next-mptcp-memcg-backlog-imp-v1-1-1f34b6c1e0b1@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
(cherry picked from commit 075b19c211dfeea5f27075293ddf8795b78c9bd9)
Rebase note: __sk_charge() uses sk->sk_memcg and
mem_cgroup_charge_skmem(), as this tree has neither mem_cgroup_from_sk()
nor mem_cgroup_sk_charge(), and __inet_accept() keeps SCTP out as in
the previous patch.
https://virtuozzo.atlassian.net/browse/VSTOR-155321
Feature: fix ms/net
Signed-off-by: Eva Kurchatova <eva.kurchatova@virtuozzo.com>
---
include/net/sock.h | 2 ++
net/core/sock.c | 18 ++++++++++++++++++
net/ipv4/af_inet.c | 18 +-----------------
3 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 17c965061c30..bfd578ffe66c 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1585,6 +1585,8 @@ static inline void sk_mem_uncharge(struct sock *sk, int size)
sk_mem_reclaim(sk);
}
+void __sk_charge(struct sock *sk, gfp_t gfp);
+
#if IS_ENABLED(CONFIG_PROVE_LOCKING) && IS_ENABLED(CONFIG_MODULES)
static inline void sk_owner_set(struct sock *sk, struct module *owner)
{
diff --git a/net/core/sock.c b/net/core/sock.c
index 46e20b96214c..f43ce9cd1847 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -3375,6 +3375,24 @@ void __sk_mem_reclaim(struct sock *sk, int amount)
}
EXPORT_SYMBOL(__sk_mem_reclaim);
+void __sk_charge(struct sock *sk, gfp_t gfp)
+{
+ int amt;
+
+ gfp |= __GFP_NOFAIL;
+ if (sk->sk_memcg) {
+ /* The socket has not been accepted yet, no need
+ * to look at newsk->sk_wmem_queued.
+ */
+ amt = sk_mem_pages(sk->sk_forward_alloc +
+ atomic_read(&sk->sk_rmem_alloc));
+ if (amt)
+ mem_cgroup_charge_skmem(sk->sk_memcg, amt, gfp);
+ }
+
+ kmem_cache_charge(sk, gfp);
+}
+
int sk_set_peek_off(struct sock *sk, int val)
{
WRITE_ONCE(sk->sk_peek_off, val);
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 5c2097f96c8f..f02efe8201dd 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -762,24 +762,8 @@ void __inet_accept(struct socket *sock, struct socket *newsock, struct sock *new
{
/* SCTP sets the memcg of its accepted sockets in sk_alloc() */
if (mem_cgroup_sockets_enabled && newsk->sk_protocol != IPPROTO_SCTP) {
- gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
-
mem_cgroup_sk_alloc(newsk);
-
- if (newsk->sk_memcg) {
- int amt;
-
- /* The socket has not been accepted yet, no need
- * to look at newsk->sk_wmem_queued.
- */
- amt = sk_mem_pages(newsk->sk_forward_alloc +
- atomic_read(&newsk->sk_rmem_alloc));
- if (amt)
- mem_cgroup_charge_skmem(newsk->sk_memcg, amt,
- gfp);
- }
-
- kmem_cache_charge(newsk, gfp);
+ __sk_charge(newsk, GFP_KERNEL);
}
sock_rps_record_flow(newsk);
--
2.56.1
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-11-19 4:49 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 4:35 [Devel] [PATCH hci-8.2 0/9] ms/mptcp: backport fixes for dropped stream segments Eva Kurchatova
2026-11-19 4:35 ` [Devel] [PATCH hci-8.2 1/9] ms/tcp: Save lock_sock() for memcg in inet_csk_accept() Eva Kurchatova
2026-11-19 4:53 ` no-reply
2026-11-19 17:08 ` Konstantin Khorenko
2026-11-19 4:35 ` [Devel] [PATCH hci-8.2 2/9] ms/mptcp: Fix up subflow's memcg when CONFIG_SOCK_CGROUP_DATA=n Eva Kurchatova
2026-11-19 4:52 ` no-reply
2026-11-19 17:08 ` Konstantin Khorenko
2026-11-19 4:35 ` Eva Kurchatova [this message]
2026-11-19 4:53 ` [Devel] [PATCH hci-8.2 3/9] ms/net: factor-out _sk_charge() helper no-reply
2026-11-19 17:08 ` Konstantin Khorenko
2026-11-19 4:35 ` [Devel] [PATCH hci-8.2 4/9] ms/mptcp: factor-out cgroup data inherit helper Eva Kurchatova
2026-11-19 4:54 ` no-reply
2026-11-19 17:08 ` Konstantin Khorenko
2026-11-19 4:35 ` [Devel] [PATCH hci-8.2 5/9] ms/mptcp: grafting MPJ subflow earlier Eva Kurchatova
2026-11-19 4:59 ` no-reply
2026-11-19 17:08 ` Konstantin Khorenko
2026-11-19 4:35 ` [Devel] [PATCH hci-8.2 6/9] ms/mptcp: fix memcg accounting for passive sockets Eva Kurchatova
2026-11-19 4:58 ` no-reply
2026-11-19 17:08 ` Konstantin Khorenko
2026-11-19 4:35 ` [Devel] [PATCH hci-8.2 7/9] ms/mptcp: handle first subflow closing consistently Eva Kurchatova
2026-11-19 4:59 ` no-reply
2026-11-19 17:08 ` Konstantin Khorenko
2026-11-19 4:35 ` [Devel] [PATCH hci-8.2 8/9] ms/mptcp: borrow forward memory from subflow Eva Kurchatova
2026-11-19 5:03 ` no-reply
2026-11-19 17:08 ` Konstantin Khorenko
2026-11-19 4:35 ` [Devel] [PATCH hci-8.2 9/9] ms/mptcp: reclaim forward-allocated memory on RX path errors Eva Kurchatova
2026-11-19 5:01 ` no-reply
2026-11-19 17:08 ` Konstantin Khorenko
2026-11-19 17:08 ` [Devel] [PATCH hci-8.2 0/9] ms/mptcp: backport fixes for dropped stream segments Konstantin Khorenko
2026-11-19 17:08 ` Konstantin Khorenko
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=20261119044702.1218722-4-eva.kurchatova@virtuozzo.com \
--to=eva.kurchatova@virtuozzo.com \
--cc=devel@openvz.org \
--cc=khorenko@virtuozzo.com \
--cc=vladimir.riabchun@virtuozzo.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.