Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2639628rwo; Sun, 23 Jul 2023 21:12:00 -0700 (PDT) X-Google-Smtp-Source: APBJJlGTUkjw0eBe+3C92x8ZQVxSXhX5/xLGDmd7un7h9IbspieoekwQiJouCBOJCSvOYRR22quR X-Received: by 2002:a17:902:d2cd:b0:1b0:3ab6:5140 with SMTP id n13-20020a170902d2cd00b001b03ab65140mr12723627plc.4.1690171919780; Sun, 23 Jul 2023 21:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690171919; cv=none; d=google.com; s=arc-20160816; b=gO/vF5c1eq2nMb50eceS72mcEWno7/Dy6ArqsJyJBodaThZ23nwzUDW9jGLf1GmZgT Td+F+B+D0Jq/UOYsRy5fdCwo9jLXrP41CZbTFAAurzHOhVDG0elwn+yTFT14b3RQfO3f dGWPUp0miGGUW+5QK+8x00d/dsmvBjQPPm1sfCXeeHDUVblsVr54axKqvENAqKOzIfMB td4qLFxETB13Zo5hWQs82PyK5W0Dqcu6jIhRUzANEykbxZIuP2yOnRfVuy4E+Qv6etNp kWFi0mF6pS+jVp5zZgIaGt8j/0uSgH/JlgcMWIii67tKiGKly/5nQK1d4OdZ0rkDzzo5 f0gQ== 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=1NSxBI+jZ4lM78HRKxD8ibkmyQyG/FtRFP+HyoBnx5I=; fh=pXSObhosTNW0VUaTJQhPeyHITy/E/IB+LZxFAmd4cnQ=; b=Vc634zbIE0Ye0TiGlaE9x2EMKTduKypuuQCj5bc3p49iKuDDUvVKN54Ep/Y2/2Glur SHLQc8HqoALlCq+4RNzUuF2ritT63oQKxW3LVMuUQRjLTBgF1oSB7MCKe3nAiGtvCIKw AcJQv8iPZtLLjWsyDWvcdbAE6IEi0o0DJ2MPSbFUnpT2irM2rxf/1A8QpOwPZdkVcM4u ZevJOUdHvOQUD1f243UnZH+lNxVtD5SMYzALXSrWcsg5/k3UtElZIANwbrAtQHA3CoNw zxwv4pxIWbHQxQylazOv+TEh1BPaR8Br+ex77u48bCrmSe+mu22Bwgw8AfXzEPATvJMR SNBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=PgEeS0qO; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c2-20020a170902848200b001b886728cddsi7785126plo.416.2023.07.23.21.11.47; Sun, 23 Jul 2023 21:11:59 -0700 (PDT) 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=@bytedance.com header.s=google header.b=PgEeS0qO; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229883AbjGXDrj (ORCPT + 99 others); Sun, 23 Jul 2023 23:47:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229468AbjGXDri (ORCPT ); Sun, 23 Jul 2023 23:47:38 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B21FE1 for ; Sun, 23 Jul 2023 20:47:12 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-2681223aaacso377080a91.0 for ; Sun, 23 Jul 2023 20:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690170431; x=1690775231; 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=1NSxBI+jZ4lM78HRKxD8ibkmyQyG/FtRFP+HyoBnx5I=; b=PgEeS0qOI+pKcrpPsv7cx17Jlt7Uzht14nwBIdBKNMvY9lkPJv+0Kt98k1wsdnIzG9 iSOI7qakWbJdPnM6TsHMhEEbpc1/VybplhTM0PsZyroqv8Kmm0p+by7fpC7oedDAGnFJ eCmTNVgTyCAu5MVVme1Ez5G8PIxUSZqLfqn3iEHdI5GWl+HVWWK3XgVHPwP99qeED/Nr 54QvjkQaaJj8zr0ff8BGNk0KBQ5UUrnePYxFm4YzSF3r0O2Nq3CP3fITV8nYm1kwMXkc ro+uz9JlKWbIcp26gzgXJ+gw4DKpOys7OSBDl5v5JwqaBhyejNeuuwKnv1Em5AkWiAPb jwRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690170431; x=1690775231; 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=1NSxBI+jZ4lM78HRKxD8ibkmyQyG/FtRFP+HyoBnx5I=; b=gK2NTo3wFJs7Hb5ZO9koPTphhdFK7QDI073xCDss90woKf+pVjO6IIjSQPE0n47z61 +EPVIsAKaGxtgYpRF8NAPVFhcHfXbUNw9KIseqqNxwKEkIkRrL2jCSEwC2wYtdY2fE0l IwZOOx3KDGAs4FH39eA1cae57Bjfj3YV89a6e3qX6SJEGKRgXskZ03G8k2xi4jjDXJUs WX7AkjJ7d/gSYmOuEuA2w62JJeP0OEsbGXwONDFIp1TaVjUjBonUB5yWsiwkQCzAcMwG XuYWD84z+YoWi2BkibYhfJASEUt0+X+5fBmwZg1Fh832lqHOzQAAPk1UlCk6xDezoZB5 vMYA== X-Gm-Message-State: ABy/qLYcqog0tdtnsFCAefkwGLCEp/yKjSlQS7KBJ4ZObpQS3TNIoeUf Uvw/dicU45rH8VNG6ZkNTfMaeA== X-Received: by 2002:a17:90b:195:b0:268:f2e:b480 with SMTP id t21-20020a17090b019500b002680f2eb480mr3628698pjs.11.1690170431458; Sun, 23 Jul 2023 20:47:11 -0700 (PDT) Received: from ?IPV6:fdbd:ff1:ce00:11bb:1457:9302:1528:c8f4? ([240e:694:e21:b::2]) by smtp.gmail.com with ESMTPSA id om5-20020a17090b3a8500b002677739860fsm5583934pjb.34.2023.07.23.20.47.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 23 Jul 2023 20:47:10 -0700 (PDT) Message-ID: <58e75f44-16e3-a40a-4c8a-0f61bbf393f9@bytedance.com> Date: Mon, 24 Jul 2023 11:47:02 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: Re: [PATCH RESEND net-next 1/2] net-memcg: Scopify the indicators of sockmem pressure To: Roman Gushchin Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Johannes Weiner , Michal Hocko , Shakeel Butt , Muchun Song , Andrew Morton , David Ahern , Yosry Ahmed , "Matthew Wilcox (Oracle)" , Yu Zhao , Kefeng Wang , Yafang Shao , Kuniyuki Iwashima , Martin KaFai Lau , Alexander Mikhalitsyn , Breno Leitao , David Howells , Jason Xing , Xin Long , Michal Hocko , Alexei Starovoitov , open list , "open list:NETWORKING [GENERAL]" , "open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)" , "open list:CONTROL GROUP - MEMORY RESOURCE CONTROLLER (MEMCG)" References: <20230711124157.97169-1-wuyun.abel@bytedance.com> Content-Language: en-US From: Abel Wu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Hi Roman, thanks for taking time to have a look! On 7/22/23 8:20 AM, Roman Gushchin wrote: > On Tue, Jul 11, 2023 at 08:41:43PM +0800, Abel Wu wrote: >> Now there are two indicators of socket memory pressure sit inside >> struct mem_cgroup, socket_pressure and tcpmem_pressure. > > Hi Abel! > >> When in legacy mode aka. cgroupv1, the socket memory is charged >> into a separate counter memcg->tcpmem rather than ->memory, so >> the reclaim pressure of the memcg has nothing to do with socket's >> pressure at all. > > But we still might set memcg->socket_pressure and propagate the pressure, > right? Yes, but the pressure comes from memcg->socket_pressure does not mean pressure in socket memory in cgroupv1, which might lead to premature reclamation or throttling on socket memory allocation. As the following example shows: ->memory ->tcpmem limit 10G 10G usage 9G 4G pressure true false the memcg's memory limits are both set to 10G, and the ->memory part is suffering from reclaim pressure while ->tcpmem still has much room for use. I have no idea why should treat the ->tcpmem as under pressure in this scenario, am I missed something? > If you're changing this, you need to provide a bit more data on why it's > a good idea. I'm not saying the current status is perfect, but I think we need > a bit more justification for this change. > >> While for default mode, the ->tcpmem is simply >> not used. >> >> So {socket,tcpmem}_pressure are only used in default/legacy mode >> respectively. This patch fixes the pieces of code that make mixed >> use of both. >> >> Signed-off-by: Abel Wu >> --- >> include/linux/memcontrol.h | 4 ++-- >> mm/vmpressure.c | 8 ++++++++ >> 2 files changed, 10 insertions(+), 2 deletions(-) >> >> diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h >> index 5818af8eca5a..5860c7f316b9 100644 >> --- a/include/linux/memcontrol.h >> +++ b/include/linux/memcontrol.h >> @@ -1727,8 +1727,8 @@ void mem_cgroup_sk_alloc(struct sock *sk); >> void mem_cgroup_sk_free(struct sock *sk); >> static inline bool mem_cgroup_under_socket_pressure(struct mem_cgroup *memcg) >> { >> - if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && memcg->tcpmem_pressure) >> - return true; >> + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys)) >> + return !!memcg->tcpmem_pressure; > > So here you can have something like > if (cgroup_subsys_on_dfl(memory_cgrp_subsys)) { > do { > if (time_before(jiffies, READ_ONCE(memcg->socket_pressure))) > return true; > } while ((memcg = parent_mem_cgroup(memcg))); > } else { > return !!READ_ONCE(memcg->socket_pressure); > } Yes, this looks better. > > And, please, add a bold comment here or nearby the socket_pressure definition > that it has a different semantics in the legacy and default modes. Agreed. > > Overall I think it's a good idea to clean these things up and thank you > for working on this. But I wonder if we can make the next step and leave only > one mechanism for both cgroup v1 and v2 instead of having this weird setup > where memcg->socket_pressure is set differently from different paths on cgroup > v1 and v2. There is some difficulty in unifying the mechanism for both cgroup designs. Throttling socket memory allocation when memcg is under pressure only makes sense when socket memory and other usages are sharing the same limit, which is not true for cgroupv1. Thoughts? Thanks & Best, Abel