Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6718727rwb; Tue, 22 Nov 2022 18:13:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf5KoO0ANfgNvZi8y20AcC3c9oSd+ZTOo2IT7An/e/wwyZRzNRrirrEtSHtcbS+PhepeXhkE X-Received: by 2002:a17:906:c303:b0:7ad:95d2:9df2 with SMTP id s3-20020a170906c30300b007ad95d29df2mr21496187ejz.607.1669169623734; Tue, 22 Nov 2022 18:13:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669169623; cv=none; d=google.com; s=arc-20160816; b=XeEUsdYZsj5YzSbZwZtrKT4duRRswpvu1PERxzzT91J89rF0fuLIGPyFDx+M4qpyD9 UIcqwDOh1SCcoQH4tBTZHFzG04lIZnwoRDR12kuXa0PahEDSkEaqRi/C2PzVtJ9uJs3K C1kfaZpHDSNGjX3yHkGzzPnW+uK0qRWPRTKQpywXqY2dS9+0I33Jy6ctaP0m42ehgh3J gpeXFnu6izNbMQLb1wLiVJgct8rZOyUfpNd8j7lGPhdL5/gJalwVyXQrn2IalN1lslqr PY5GAbHyMybJ7LMHJwhK9ak1S1zSy4V+Orq6RSGrJrNpnt9giSBmTP5dTmLuATL0J0lu GTOQ== 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=M42sWyNVtSXf63+/nFxRglHm/7sJT4os0b4YITaV5ns=; b=CgWyqj1+rauK0Z0TQurtEP8jHZXx1aLOGbI2dqDUML4x5n6LjMgobaY91GZw47jugo IoxeJ9C7peJYvuOB7xdPdp48PfpbfCKeVhjAFo6Q4wbUEQ32nyv3HPzzvRFnu3KZhPVl 52bdYigCrh7yE4cYrLfVxBaL5T+TIPZtj4wIklXm/MZxma94E9tWwuyhAThu9oCvKLYk vSQRHbZD6P46YAfLWsZsObEGKEhRtj2/YXF+HRw6PHXZ2ufnU9/oQ/Zc1HyBezaeyzd1 U//zF6uXxKM0yP1SM9gIUtgNeJkCYjTPH2PNfnpWSDvCYh+kp1PPSP2TisO5RPqCHJX3 HoYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=EEDxxsC8; 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 dr9-20020a170907720900b0078d4cf8de04si14072293ejc.380.2022.11.22.18.13.22; Tue, 22 Nov 2022 18:13:43 -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=EEDxxsC8; 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 S235178AbiKWB2j (ORCPT + 90 others); Tue, 22 Nov 2022 20:28:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233984AbiKWB2g (ORCPT ); Tue, 22 Nov 2022 20:28:36 -0500 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BF3387550 for ; Tue, 22 Nov 2022 17:28:36 -0800 (PST) Received: by mail-yb1-xb34.google.com with SMTP id k84so19340603ybk.3 for ; Tue, 22 Nov 2022 17:28:36 -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=M42sWyNVtSXf63+/nFxRglHm/7sJT4os0b4YITaV5ns=; b=EEDxxsC8axWN6EfK6HuKM4nKLyz6jyKaF6MQb03199u9fI9ncH2Pzi0Pkz2Rmfaln3 0LcVHqzeUlYiBsH/6c+Cd8NT5OeaxAlFYOn2KKOOs0oao+6e3/WwTuRD4LxatCOIGywm VjfLjjAHKCoOCfpD6aq+RuMP4XmMlWcW/Y98o= 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=M42sWyNVtSXf63+/nFxRglHm/7sJT4os0b4YITaV5ns=; b=QQh0Lwh267TcXHjndTW+fFU0fJvOOVEm3IZqNZChl8rM4t7xaW7S82j29vCtgMD0Eu mtcmIkjsh02IhjXd6hVZySYMx16fiKtslPRjol1gClgCBu2NClJLv+w+FKEoy2gKghe9 IjUbkXtZ8GcOTKsJ8B8R5/unVBfmEJSFDwR4bcp/dw4qKLyZwZxknLDV+4qhyUalYOOx /PgE9t0mjHbWO2dJ/EaF6aiHgtN5+oImbi+ulJCLoIXj8OtWrmO5mhQQoZYkU33Ka4ep nZT3Qqto6wvwKeCBchSU7G3qrw7pXCuqIESi4ge95SQJkNUsr3GqI/rItVJW//rAb0fp OyAw== X-Gm-Message-State: ANoB5plEN5tjFyi+WjjbYKLg3ifo4jK5HuvsDrl6HO6peIISi9BRlg5D SmeHx8hlxQxisOSp+8SaG02fO+qUwvK0yF9gIclcow== X-Received: by 2002:a25:a0d4:0:b0:6ea:3fec:4adb with SMTP id i20-20020a25a0d4000000b006ea3fec4adbmr15397598ybm.305.1669166915244; Tue, 22 Nov 2022 17:28:35 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ivan Babrou Date: Tue, 22 Nov 2022 17:28:24 -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 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. 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: $ sudo ss -tim dport 6443 | fgrep rcv_ssthresh | sed 's/.*rcv_ssthresh://' | awk '{ print $1 }' | sort -n | uniq -c | sort -n | tail 1 64076 181 65495 1456 5792 16531 64088 * 64088 is the default value * 5792 is 4 * advmss (clamped) Compare this to a machine without the patch but with cgroup.memory=nosocket in cmdline: $ sudo ss -tim dport 6443 | fgrep rcv_ssthresh | sed 's/.*rcv_ssthresh://' | awk '{ print $1 }' | sort -n | uniq -c | sort -n | tail 8 2806862 8 3777338 8 72776 8 86068 10 2024018 12 3777354 23 91172 29 66984 101 65495 5439 64088 There aren't any clamped sockets here and there are many different rcv_ssthresh values.