Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6679776rwb; Mon, 5 Dec 2022 16:20:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf47zBfKwMSHZr6CflUL4HnoIlzAXxNqT2JraJ36+zQu6w0yDDQ44Je/b8eksWHOOFSS1yv9 X-Received: by 2002:a17:907:f8d:b0:7c0:edc9:c89e with SMTP id kb13-20020a1709070f8d00b007c0edc9c89emr6545367ejc.494.1670286008271; Mon, 05 Dec 2022 16:20:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670286008; cv=none; d=google.com; s=arc-20160816; b=kZFVKPB/li9Y3kgd9OrgV3vw1kzOBOW9Q/P9LgI3p6mx5v4tlxHwPeLWXCmauAgk+g DUMleJbzErldqfahV0+mUwh9kofJ+6S8Kw3Wck1QGtz0Nk6UhZaP/LlEmOJ3bqdFex7Y 3xAeLziw57VNm9J/JxFr1rlRmsXRjkcp+hSYXeyezrd92WMrb65HkkcmwYYfzwPuMD67 6t8sXIUwnZlZbCdyRw5+VrSTeZNlJPNZgM3ms/oYTHQzU5nAeRaMcoho/yWb3PdtDeJz Ek3xJC544OL+tZ2MwwXVjv4pA3FY5cqyseLqpm4T9QqgTVY1zhSm6cEyBN+t/JJDkSi2 r0/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=GSIqPXduJlFanom97XBLoEuLvh8SiPtbTgxfQXMpbc0=; b=lhVO7dSknLjRHYhliztIWoKpYezQ7poivgJv/TkJHN4s6wRJrhGX0PpcosAcKLNmxL gyuD9YXeH0eokBC9APFguOy1lU0/U+aoOzQEuHbZzXPhTS9u4oyFVoECyYhUGBrhHcaK m/I9vsJshQXzm2zuYQFH16PdfywVQ+pmkBXORYfV9wJNzZYLX89D/hpBQDNSrsVAmE1l Dl4Em7FhyT+4o2MgpoBytHV5DqfEbztN2jSEbS2sXCHzETAWDmv7VYUxa0OiIYfaBTKn W8/5DxWyWntD7Qqw51+IU01f1GbjkxvBF51q8qZu5+5GJxx7ylsG9W0rPccp89ixpWm0 RjOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=kkNSWN2z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lg15-20020a170906f88f00b007a072b8240csi10562265ejb.927.2022.12.05.16.19.49; Mon, 05 Dec 2022 16:20:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=kkNSWN2z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232543AbiLEX5x (ORCPT + 80 others); Mon, 5 Dec 2022 18:57:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230151AbiLEX5v (ORCPT ); Mon, 5 Dec 2022 18:57:51 -0500 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0C1C6268 for ; Mon, 5 Dec 2022 15:57:50 -0800 (PST) Received: by mail-io1-xd30.google.com with SMTP id o189so3050579iof.0 for ; Mon, 05 Dec 2022 15:57:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=GSIqPXduJlFanom97XBLoEuLvh8SiPtbTgxfQXMpbc0=; b=kkNSWN2zeC0fdFsxdmzfipXeOEUbzILOt6EOpxumoJHrTAPZ0+VK8dI4YAfrt/x3Vj bD2vugxlIPivNs94+1JmU2kQhkNfkJelQhRN6Kh6mAUpm5HuNKWpp3/Am305Pvi03tkq 1UJ4F995pxzAwdmAF2yiwfmtZdXbllziUDo54= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=GSIqPXduJlFanom97XBLoEuLvh8SiPtbTgxfQXMpbc0=; b=fM2Z08oAIgKIKuPSYcUCdH//vrdGgt+/TppNy0uKFxSI4kf+BvutKevWEvovAuae+n fx8I2fP+kWvussOr1SpYOBixdNsXzwK304xX9RbufgAes4xHUfZ8IKA3Mqpwl5e2sSU2 Q5fJ3QicHBTjGFbz/jL0YLuePYpi3NRU0P2bG0RS5nCktUypV12Y2EmPRUrHNVh9n5d7 30xYM6AO5Gnb2wkLbpbjXn6dX6Kgs6xFNpSuPG3m/AcIKYbLupDUvUTuJvAGe1DB3r8B DbbFupHIgazc9jvp0Jel6s0XM/+bsA9+qX+53eSjLsqmApTHDgp4eWshO+bKyCV/Kn1k m6wQ== X-Gm-Message-State: ANoB5pnjHifMAe3v+X5xawIuYwtN90Us+GQ3d+d4vbPL13837enRKe0r 0+TuMnkZWEoCUziSi3z4k/kKCgj1BG2llhLXgHv3cQ== X-Received: by 2002:a02:ce9a:0:b0:389:e42b:89fb with SMTP id y26-20020a02ce9a000000b00389e42b89fbmr17113953jaq.281.1670284669913; Mon, 05 Dec 2022 15:57:49 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ivan Babrou Date: Mon, 5 Dec 2022 15:57:39 -0800 Message-ID: Subject: Re: Low TCP throughput due to vmpressure with swap enabled To: Johannes Weiner Cc: Linux MM , Linux Kernel Network Developers , linux-kernel , Michal Hocko , Roman Gushchin , Shakeel Butt , Muchun Song , Andrew Morton , Eric Dumazet , "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , Paolo Abeni , cgroups@vger.kernel.org, kernel-team Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 28, 2022 at 10:07 AM Johannes Weiner wrote: > > On Tue, Nov 22, 2022 at 05:28:24PM -0800, Ivan Babrou wrote: > > On Tue, Nov 22, 2022 at 2:11 PM Ivan Babrou wrote: > > > > > > On Tue, Nov 22, 2022 at 12:05 PM Johannes Weiner wrote: > > > > > > > > On Mon, Nov 21, 2022 at 04:53:43PM -0800, Ivan Babrou wrote: > > > > > Hello, > > > > > > > > > > We have observed a negative TCP throughput behavior from the following commit: > > > > > > > > > > * 8e8ae645249b mm: memcontrol: hook up vmpressure to socket pressure > > > > > > > > > > It landed back in 2016 in v4.5, so it's not exactly a new issue. > > > > > > > > > > The crux of the issue is that in some cases with swap present the > > > > > workload can be unfairly throttled in terms of TCP throughput. > > > > > > > > Thanks for the detailed analysis, Ivan. > > > > > > > > Originally, we pushed back on sockets only when regular page reclaim > > > > had completely failed and we were about to OOM. This patch was an > > > > attempt to be smarter about it and equalize pressure more smoothly > > > > between socket memory, file cache, anonymous pages. > > > > > > > > After a recent discussion with Shakeel, I'm no longer quite sure the > > > > kernel is the right place to attempt this sort of balancing. It kind > > > > of depends on the workload which type of memory is more imporant. And > > > > your report shows that vmpressure is a flawed mechanism to implement > > > > this, anyway. > > > > > > > > So I'm thinking we should delete the vmpressure thing, and go back to > > > > socket throttling only if an OOM is imminent. This is in line with > > > > what we do at the system level: sockets get throttled only after > > > > reclaim fails and we hit hard limits. It's then up to the users and > > > > sysadmin to allocate a reasonable amount of buffers given the overall > > > > memory budget. > > > > > > > > Cgroup accounting, limiting and OOM enforcement is still there for the > > > > socket buffers, so misbehaving groups will be contained either way. > > > > > > > > What do you think? Something like the below patch? > > > > > > The idea sounds very reasonable to me. I can't really speak for the > > > patch contents with any sort of authority, but it looks ok to my > > > non-expert eyes. > > > > > > There were some conflicts when cherry-picking this into v5.15. I think > > > the only real one was for the "!sc->proactive" condition not being > > > present there. For the rest I just accepted the incoming change. > > > > > > I'm going to be away from my work computer until December 5th, but > > > I'll try to expedite my backported patch to a production machine today > > > to confirm that it makes the difference. If I can get some approvals > > > on my internal PRs, I should be able to provide the results by EOD > > > tomorrow. > > > > I tried the patch and something isn't right here. > > Thanks for giving it a sping. > > > With the patch applied I'm capped at ~120MB/s, which is a symptom of a > > clamped window. > > > > I can't find any sockets with memcg->socket_pressure = 1, but at the > > same time I only see the following rcv_ssthresh assigned to sockets: > > Hm, I don't see how socket accounting would alter the network behavior > other than through socket_pressure=1. > > How do you look for that flag? If you haven't yet done something > comparable, can you try with tracing to rule out sampling errors? Apologies for a delayed reply, I took a week off away from computers. I looked with bpftrace (from my bash_history): $ sudo bpftrace -e 'kprobe:tcp_try_rmem_schedule { @sk[cpu] = arg0; } kretprobe:tcp_try_rmem_schedule { $arg = @sk[cpu]; if ($arg) { $sk = (struct sock *) $arg; $id = $sk->sk_memcg->css.cgroup->kn->id; $socket_pressure = $sk->sk_memcg->socket_pressure; if ($id == 21379) { printf("id = %d, socket_pressure = %d\n", $id, $socket_pressure); } } }' I tried your patch on top of v6.1-rc8 (where it produced no conflicts) in my vm and it still gave me low numbers and nothing in /sys/kernel/debug/tracing/trace. To be extra sure, I changed it from trace_printk to just printk and it still didn't show up in dmesg, even with constant low throughput: ivan@vm:~$ curl -o /dev/null https://sim.cfperf.net/cached-assets/zero-5g.bin % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 14 4768M 14 685M 0 0 12.9M 0 0:06:08 0:00:52 0:05:16 13.0M I still saw clamped rcv_ssthresh: $ sudo ss -tinm dport 443 State Recv-Q Send-Q Local Address:Port Peer Address:Port Process ESTAB 0 0 10.2.0.15:35800 162.159.136.82:443 skmem:(r0,rb2577228,t0,tb46080,f0,w0,o0,bl0,d0) cubic rto:201 rtt:0.42/0.09 ato:40 mss:1460 pmtu:1500 rcvmss:1440 advmss:1460 cwnd:10 bytes_sent:12948 bytes_acked:12949 bytes_received:2915062731 segs_out:506592 segs_in:2025111 data_segs_out:351 data_segs_in:2024911 send 278095238bps lastsnd:824 lastrcv:154 lastack:154 pacing_rate 556190472bps delivery_rate 47868848bps delivered:352 app_limited busy:147ms rcv_rtt:0.011 rcv_space:82199 rcv_ssthresh:5840 minrtt:0.059 snd_wnd:65535 tcp-ulp-tls rxconf: none txconf: none I also tried with my detection program for ebpf_exporter (fexit based version): * https://github.com/cloudflare/ebpf_exporter/pull/172/files Which also showed signs of a clamped window: # HELP ebpf_exporter_tcp_window_clamps_total Number of times that TCP window was clamped to a low value # TYPE ebpf_exporter_tcp_window_clamps_total counter ebpf_exporter_tcp_window_clamps_total 53887 In fact, I can replicate this with just curl to a public URL and fio running, > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index 066166aebbef..134b623bee6a 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -7211,6 +7211,7 @@ bool mem_cgroup_charge_skmem(struct mem_cgroup *memcg, unsigned int nr_pages, > goto success; > } > memcg->socket_pressure = 1; > + trace_printk("skmem charge failed nr_pages=%u gfp=%pGg\n", nr_pages, &gfp_mask); > if (gfp_mask & __GFP_NOFAIL) { > try_charge(memcg, gfp_mask, nr_pages); > goto success;