Skip to content

Commit 7ccf765

Browse files
committed
tcp: sk_forced_mem_schedule() optimization
jira LE-1907 Rebuild_History Non-Buildable kernel-5.14.0-427.28.1.el9_4 commit-author Eric Dumazet <edumazet@google.com> commit 219160b sk_memory_allocated_add() has three callers, and returns to them @memory_allocated. sk_forced_mem_schedule() is one of them, and ignores the returned value. Change sk_memory_allocated_add() to return void. Change sock_reserve_memory() and __sk_mem_raise_allocated() to call sk_memory_allocated(). This removes one cache line miss [1] for RPC workloads, as first skbs in TCP write queue and receive queue go through sk_forced_mem_schedule(). [1] Cache line holding tcp_memory_allocated. Signed-off-by: Eric Dumazet <edumazet@google.com> Acked-by: Soheil Hassas Yeganeh <soheil@google.com> Reviewed-by: Shakeel Butt <shakeelb@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 219160b) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 87107d1 commit 7ccf765

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

include/net/sock.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,7 @@ sk_memory_allocated(const struct sock *sk)
14861486
/* 1 MB per cpu, in page units */
14871487
#define SK_MEMORY_PCPU_RESERVE (1 << (20 - PAGE_SHIFT))
14881488

1489-
static inline long
1489+
static inline void
14901490
sk_memory_allocated_add(struct sock *sk, int amt)
14911491
{
14921492
int local_reserve;
@@ -1498,7 +1498,6 @@ sk_memory_allocated_add(struct sock *sk, int amt)
14981498
atomic_long_add(local_reserve, sk->sk_prot->memory_allocated);
14991499
}
15001500
preempt_enable();
1501-
return sk_memory_allocated(sk);
15021501
}
15031502

15041503
static inline void

net/core/sock.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,8 @@ static int sock_reserve_memory(struct sock *sk, int bytes)
10181018
return -ENOMEM;
10191019

10201020
/* pre-charge to forward_alloc */
1021-
allocated = sk_memory_allocated_add(sk, pages);
1021+
sk_memory_allocated_add(sk, pages);
1022+
allocated = sk_memory_allocated(sk);
10221023
/* If the system goes into memory pressure with this
10231024
* precharge, give up and return error.
10241025
*/
@@ -2926,11 +2927,13 @@ EXPORT_SYMBOL(sk_wait_data);
29262927
*/
29272928
int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
29282929
{
2929-
struct proto *prot = sk->sk_prot;
2930-
long allocated = sk_memory_allocated_add(sk, amt);
29312930
bool memcg_charge = mem_cgroup_sockets_enabled && sk->sk_memcg;
2931+
struct proto *prot = sk->sk_prot;
29322932
bool charged = true;
2933+
long allocated;
29332934

2935+
sk_memory_allocated_add(sk, amt);
2936+
allocated = sk_memory_allocated(sk);
29342937
if (memcg_charge &&
29352938
!(charged = mem_cgroup_charge_skmem(sk->sk_memcg, amt,
29362939
gfp_memcg_charge())))

0 commit comments

Comments
 (0)