Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2844544rdb; Fri, 22 Sep 2023 09:48:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHHkMg1SKj/81DxjXiLph+ZxFqYnmZ9S/M/SnM9XRZ/C4shquggzWQCswZsM1uAWHNBlNd8 X-Received: by 2002:a05:6808:10e:b0:3ae:aa6:dc0c with SMTP id b14-20020a056808010e00b003ae0aa6dc0cmr176801oie.9.1695401304292; Fri, 22 Sep 2023 09:48:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695401304; cv=none; d=google.com; s=arc-20160816; b=pCG75tSoYwk7SC02Kr+a4kS5xAvPj4UaDAr/m29yHfHPgUUz8VpfGyXzvQWpdBvuJh 2SXQWKeZBmomRLUfvQH4L0kzZarxxDsrKUszu+NJMt32koBiIabqz1KvMpAPLNXiHi/Z WGsfc4F4FNK62nljOl67pD3u9mVrLPr2tA5T8B4AVXlh/zLgbOyoSAeb/GvzRxfS0iaW OVFOGWh39N4fKn1D45XluxzI9ngt+xorGTDRn4LSGnGgcDE2rykgxneNQA4Wk0Mgn/RA +hA8jxoxEirfKrpdbOsPnL1E14i65rVov/U1C0qgKfCdMLigyVw/4MfgOQkzlwe7a5QE m6NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=RICN8tort+CWLhQVSIa56+kaySuy9xkNGnfuP8kUQqc=; fh=0m3gyEBZvNqjuZ7kEuCvDqCtgOlUwTGeYotZuvYvXjE=; b=oIlzkSXK+42MJtdYkeUkmsuVY0PFZwl7686/TrSOI0qI1dXl/KTkmpt2sbciE6e2D1 1eNfJ1ntvMn2WJxOywcfymqqSrf0tgw7t4XYEfcIFk+/oQnqJ4aJDGv8jDX+S3mGiGr5 eWm/CYqB6d/fMZV/3nAptu26QWfXDpz9+cxItsIjUTCEnFTQeaqspRQW+2vIai5K8dzE ScAPG2WPLQgZ03bhgQe75YYpWhugpMvJhLvEf3xJ9KqcTLidPgHQh0uSD0djggIF8kI2 jXCSUaBnEgE6XyRbU2GmI8gZNzgVV55jTumR80VwDeo8uJXlRtuw4bFnuafUKbotG0sr rmiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ai9yrCLf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id j191-20020a6380c8000000b00578e153c979si4053781pgd.740.2023.09.22.09.48.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 09:48:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ai9yrCLf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 53CFB808EF77; Fri, 22 Sep 2023 01:36:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232609AbjIVIgp (ORCPT + 99 others); Fri, 22 Sep 2023 04:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjIVIgn (ORCPT ); Fri, 22 Sep 2023 04:36:43 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1BB899 for ; Fri, 22 Sep 2023 01:36:15 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6910ea9cca1so1491252b3a.1 for ; Fri, 22 Sep 2023 01:36:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1695371775; x=1695976575; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=RICN8tort+CWLhQVSIa56+kaySuy9xkNGnfuP8kUQqc=; b=ai9yrCLfMgYecX1TwSjw1MSxfZ+DTTw9hIpklIUEzd9HwAEZwDRRhdonxBnuj9mCSf 6yYHNUFLOOmvwL2gtoRTzlRQyAFkdEw7Qs//kym4jZC+oNCt4GqF9SZD+weCsbpay59I JNUnWpn72CeAZksLhCaRHiroAJi2Ej2HcGBY7zT/uE+ewxi2aPvbO4OXwXR7BA/ngyF4 EbyJwZhsP3SZo16GTeCWYLfFivM9snZ1654VapK7vL95EXIJNWnA5bpL91XcG+z5hAPN K/ZGfp2YKsDcza//zlI0yKhvR039lVl7eZwGyEtKRDG3ESKIY5W22Io/t5ijpXqOtIFv GaTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695371775; x=1695976575; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RICN8tort+CWLhQVSIa56+kaySuy9xkNGnfuP8kUQqc=; b=XUV3bKy4+t3qgCF/WJMjecFu1MVug0lXp9TAPNxJLYMMMiZQp62CBU/MOhpV3Hetpx zxm20MORPx3/BBace//Wf26Q3xPiSR5ihfbJixBrFvSvwel9HOW1B0O6ufMY8bQ13u1g 3IpTzd7lR3bSaIZ4dVmH/7JosSzgjbJYVJTIfTs7sFRMbbXcXquIaMmpjfVEuTx1GACX oDpCqglLHRyT/EV4Wf3tt0YRJNDq2UB7r39nW0A1xMipbgPwQvpPT9rY1uF1/VdQZseM Hgl0CC8/MrvVeRKiJ/xTKb62MGAKGO1IcR7zJkCl6lzClxSbmsaz6AKmUYURafYS//Op fEiQ== X-Gm-Message-State: AOJu0YziQlOEnGzfITLH5Iquz3bhpCVBIMMrLF2vNNqZg4iAq4aTZaZm Nxn1VIe3jgB07DCQQ0BBNZGICs5/qVDZHvO9sqU= X-Received: by 2002:a05:6a20:9187:b0:15a:2d98:bc81 with SMTP id v7-20020a056a20918700b0015a2d98bc81mr8767748pzd.53.1695371775244; Fri, 22 Sep 2023 01:36:15 -0700 (PDT) Received: from [10.254.1.169] ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id z1-20020a170902708100b001bb0eebd90asm2860013plk.245.2023.09.22.01.36.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 22 Sep 2023 01:36:14 -0700 (PDT) Message-ID: <82c0a442-c7d7-d0f1-54de-7a5e7e6a31d5@bytedance.com> Date: Fri, 22 Sep 2023 16:36:04 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: Re: [PATCH net-next 2/2] sock: Fix improper heuristic on raising memory To: Shakeel Butt Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima , Breno Leitao , Alexander Mikhalitsyn , David Howells , Jason Xing , Xin Long , KAMEZAWA Hiroyuki , "open list:NETWORKING [GENERAL]" , open list References: <20230920132545.56834-1-wuyun.abel@bytedance.com> <20230920132545.56834-2-wuyun.abel@bytedance.com> <20230921190156.s4oygohw4hud42tx@google.com> Content-Language: en-US From: Abel Wu In-Reply-To: <20230921190156.s4oygohw4hud42tx@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Fri, 22 Sep 2023 01:36:47 -0700 (PDT) On 9/22/23 3:01 AM, Shakeel Butt wrote: > On Wed, Sep 20, 2023 at 09:25:41PM +0800, Abel Wu wrote: >> 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. >> Fix this by skipping this heuristic when under memcg pressure. >> >> Fixes: e1aab161e013 ("socket: initial cgroup code.") >> Signed-off-by: Abel Wu >> --- >> net/core/sock.c | 10 +++++++++- >> 1 file changed, 9 insertions(+), 1 deletion(-) >> >> diff --git a/net/core/sock.c b/net/core/sock.c >> index 379eb8b65562..ef5cf6250f17 100644 >> --- a/net/core/sock.c >> +++ b/net/core/sock.c >> @@ -3093,8 +3093,16 @@ 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)) >> + if (memcg && mem_cgroup_under_socket_pressure(memcg)) >> + goto suppress_allocation; >> + >> + if (!sk_under_global_memory_pressure(sk)) >> return 1; > > I am onboard with replacing sk_under_memory_pressure() with > sk_under_global_memory_pressure(). However suppressing on memcg pressure > is a behavior change from status quo and need more thought and testing. > > I think there are three options for this hunk: > > 1. proposed patch > 2. Consider memcg pressure only for !in_softirq(). > 3. Don't consider memcg pressure at all. > > All three options are behavior change from the status quo but with > different risk levels. (1) may reintroduce the regression fixed by > 720ca52bcef22 ("net-memcg: avoid stalls when under memory pressure"). Just for the record, it is same for the current upstream implementation if the socket reaches average usage. Taking option 2 will fix this too. > (2) is more inlined with 720ca52bcef22. (3) has the risk to making memcg > limits ineffective. > > IMHO we should go with (2) as there is already a precedence in > 720ca52bcef22. Yes, I agree. Actually applying option(2) would make this patch quite similar to the previous version[a], except the below part: /* Under limit. */ if (allocated <= sk_prot_mem_limits(sk, 0)) { sk_leave_memory_pressure(sk); - return 1; + if (!under_memcg_pressure) + return 1; } My original thought is to inherit the behavior of tcpmem pressure. There are also 3 levels of memcg pressure named low/medium/critical, but considering that the 'low' level is too much conservative for socket allocation, I made the following match: PROTOCOL MEMCG ACTION ----------------------------------------------------- low