Messages in this thread | | | Date | Fri, 13 Oct 2023 01:09:21 +0000 | Subject | Re: [PATCH net-next 2/2] sock: Fix improper heuristic on raising memory | From | Shakeel Butt <> |
| |
On Tue, Oct 03, 2023 at 08:49:08PM +0800, Abel Wu wrote: [...] > > 1. minimum buffer size even under pressure. > > This is required by RFC 7323 (TCP Extensions for High Performance) to > make features like Window Scale option work as expected, and should be > succeeded under global pressure by tcp_{r,w}mem's definition. And IMHO > for same reason, it should also be succeeded under memcg pressure, or > else workloads might suffer performance drop due to bottleneck on > network. > > The allocation must not be succeeded either exceed global or memcg's > hard limit, or else a DoS attack can be taken place by spawning lots > of sockets that are under minimum buffer size. >
Sounds good.
> > > > 2. allow allocation for a socket whose usage is below average of the > > system. > > Since 'average' is within the scope of global accounting, this one > only makes sense under global memory pressure. Actually this exists > before cgroup was born, hence doesn't take memcg into consideration. > > While OTOH the intention of throttling under memcg pressure is to > relief the memcg from heavy reclaim pressure, this heuristic does no > help. And there also seems to be no reason to succeed the allocation > when global or memcg's hard limit is exceeded. >
Sounds good too.
> > > > 3. socket is over its sndbuf. > > TBH I don't get its point.. >
So, this corresponds to following code in __sk_mem_raise_allocated()
if (kind == SK_MEM_SEND && sk->sk_type == SOCK_STREAM) { sk_stream_moderate_sndbuf(sk);
/* Fail only if socket is _under_ its sndbuf. * In this case we cannot block, so that we have to fail. */ if (sk->sk_wmem_queued + size >= sk->sk_sndbuf) { /* Force charge with __GFP_NOFAIL */ if (memcg_charge && !charged) { mem_cgroup_charge_skmem(sk->sk_memcg, amt, gfp_memcg_charge() | __GFP_NOFAIL); } return 1; } }
Here we moderate the sk_sndbuf possibly half of sk_wmem_queued and thus we always succeed unless user has done SO_SNDBUF on the socket in which case it interacts with sk_stream_wait_memory() called in sendmsg.
I am not really able to make sense of the interaction between this code and sk_stream_wait_memory() and will punt to networking experts to shed some light.
Other than that I think we need to answer if we want to moderate the sndbuf on memcg charge failure.
> > > > Let's discuss which heuristic applies to which accounting infra and > > under which state (under pressure or over limit). > > I will follow your suggestion to post a patch to explicitly document > the behaviors once things are cleared. >
Let's just post the patch and see what other folks comment as well.
| |