Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sock: Ignore memcg pressure heuristics when raising allocated

Before sockets became aware of net-memcg's memory pressure since
commit e1aab161e013 ("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>

authored by

Abel Wu and committed by
Paolo Abeni
66e6369e 2e12072c

+12 -2
+12 -2
net/core/sock.c
··· 3035 3035 * @amt: pages to allocate 3036 3036 * @kind: allocation type 3037 3037 * 3038 - * Similar to __sk_mem_schedule(), but does not update sk_forward_alloc 3038 + * Similar to __sk_mem_schedule(), but does not update sk_forward_alloc. 3039 + * 3040 + * Unlike the globally shared limits among the sockets under same protocol, 3041 + * consuming the budget of a memcg won't have direct effect on other ones. 3042 + * So be optimistic about memcg's tolerance, and leave the callers to decide 3043 + * whether or not to raise allocated through sk_under_memory_pressure() or 3044 + * its variants. 3039 3045 */ 3040 3046 int __sk_mem_raise_allocated(struct sock *sk, int size, int amt, int kind) 3041 3047 { ··· 3099 3093 if (sk_has_memory_pressure(sk)) { 3100 3094 u64 alloc; 3101 3095 3102 - if (!sk_under_memory_pressure(sk)) 3096 + /* The following 'average' heuristic is within the 3097 + * scope of global accounting, so it only makes 3098 + * sense for global memory pressure. 3099 + */ 3100 + if (!sk_under_global_memory_pressure(sk)) 3103 3101 return 1; 3104 3102 3105 3103 /* Try to be fair among all the sockets under global