Skip to content

Commit

Permalink
sock: Ignore memcg pressure heuristics when raising allocated
Browse files Browse the repository at this point in the history
Before sockets became aware of net-memcg's memory pressure since
commit e1aab16 ("socket: initial cgroup code."), the memory
usage would be granted to raise if below average even when under
protocol's pressure. This provides fairness among the sockets of
same protocol.

That commit changes this because the heuristic will also be
effective when only memcg is under pressure which makes no sense.
So revert that behavior.

After reverting, __sk_mem_raise_allocated() no longer considers
memcg's pressure. As memcgs are isolated from each other w.r.t.
memory accounting, consuming one's budget won't affect others.
So except the places where buffer sizes are needed to be tuned,
allow workloads to use the memory they are provisioned.

Signed-off-by: Abel Wu <wuyun.abel@bytedance.com>
Acked-by: Shakeel Butt <shakeelb@google.com>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20231019120026.42215-3-wuyun.abel@bytedance.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Abel Wu authored and Paolo Abeni committed Oct 24, 2023
1 parent 2e12072 commit 66e6369
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,13 @@ EXPORT_SYMBOL(sk_wait_data);
* @amt: pages to allocate
* @kind: allocation type
*
* Similar to __sk_mem_schedule(), but does not update sk_forward_alloc
* Similar to __sk_mem_schedule(), but does not update sk_forward_alloc.
*
* Unlike the globally shared limits among the sockets under same protocol,
* consuming the budget of a memcg won't have direct effect on other ones.
* So be optimistic about memcg's tolerance, and leave the callers to decide
* whether or not to raise allocated through sk_under_memory_pressure() or
* its variants.
*/
int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
{
Expand Down Expand Up @@ -3093,7 +3099,11 @@ int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind)
if (sk_has_memory_pressure(sk)) {
u64 alloc;

if (!sk_under_memory_pressure(sk))
/* The following 'average' heuristic is within the
* scope of global accounting, so it only makes
* sense for global memory pressure.
*/
if (!sk_under_global_memory_pressure(sk))
return 1;

/* Try to be fair among all the sockets under global
Expand Down

0 comments on commit 66e6369

Please sign in to comment.