mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 10:01:39 -05:00
net: factor-out _sk_charge() helper
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>
This commit is contained in:
committed by
Jakub Kicinski
parent
f296b73d17
commit
075b19c211
@@ -1631,6 +1631,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)
|
||||
{
|
||||
|
||||
@@ -3448,6 +3448,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 (mem_cgroup_from_sk(sk)) {
|
||||
/* 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_sk_charge(sk, amt, gfp);
|
||||
}
|
||||
|
||||
kmem_cache_charge(sk, gfp);
|
||||
}
|
||||
|
||||
int sk_set_peek_off(struct sock *sk, int val)
|
||||
{
|
||||
WRITE_ONCE(sk->sk_peek_off, val);
|
||||
|
||||
@@ -756,23 +756,8 @@ EXPORT_SYMBOL(inet_stream_connect);
|
||||
void __inet_accept(struct socket *sock, struct socket *newsock, struct sock *newsk)
|
||||
{
|
||||
if (mem_cgroup_sockets_enabled) {
|
||||
gfp_t gfp = GFP_KERNEL | __GFP_NOFAIL;
|
||||
|
||||
mem_cgroup_sk_alloc(newsk);
|
||||
|
||||
if (mem_cgroup_from_sk(newsk)) {
|
||||
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_sk_charge(newsk, amt, gfp);
|
||||
}
|
||||
|
||||
kmem_cache_charge(newsk, gfp);
|
||||
__sk_charge(newsk, GFP_KERNEL);
|
||||
}
|
||||
|
||||
sock_rps_record_flow(newsk);
|
||||
|
||||
Reference in New Issue
Block a user