Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp523164rwb; Tue, 25 Jul 2023 20:59:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlG7dQNNU4zSnR3Ssq6BHBs9GfSr5sywqiXoI7kdp6CbozSRVHnpmY0DcuKBCQr2SfIES3QK X-Received: by 2002:a05:6402:1154:b0:51e:c61:1cd6 with SMTP id g20-20020a056402115400b0051e0c611cd6mr467776edw.35.1690343948536; Tue, 25 Jul 2023 20:59:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690343948; cv=none; d=google.com; s=arc-20160816; b=bPhJ1GR+7Upy3wWVcIBTJRxJD3MO1/cKVWCNX+VI9o+bNuuk+KAajMfQB6l0afqAyL L5qk3RZRQsUsjcOfeFob+L2raZZBNhBFQ3NKLzVb1FqPkQrqMTqOywAoKnJ8r+q77Esv TK3cMSEHK3ibf+hkOyD1Mz1y/U2ffzXLtSOx93jbI1IwNDUs5dtJU0+KBfXgbS+3ixgm f/xJmD+I/j6RNPBglreG+O9dCkV+bEGKWl0J405zz7hEEvK3ajAw6DVpMZpVk9j1Kj7x wAyvRB2FT2QQwRB5Lx8EAMqRoResZ/ylxbA1BgoY8QKM+2YlDb3Zcgxwa0FGPAam+dfi 3aTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=M8HcyBJhNbmAFYQ4vhr/4v6PwhJI/M2KUGD3rBet++I=; fh=4iXgJX52FQtMjCk2TzFrTBu6n0T5NOoWQ289GEZF05U=; b=x43cKtv0byRTvUvFWuFnUWadm7Dfz7PvCdiwoYVPKN9/B7HKmS8OFF+j+BeIAj75Tc +5C+KRlcQkphiJHJHoxcElf9mJjsOEsuwuasiE0GLoxAhkAPJpbOQrssVAdjWo7T8VXP PZAgbjeqSlrJPjwcx36eYM/ITWfiMqvuVN6wxt7TUqF01prbvtyRyWzm9iYRiUMkYaBq kVBm/CXEIhDWZ8t9Q42IuYGMG52ItaiCzQqJg+xwR4Qc1OmHPPfzbidGiALHc2fYe1S0 Wkjw/GKzdRbmqXPggwFT5lwSLI0g7CmGWYLLy5h5gDKpDcRy2x/0Y61ETcUUomXu6I+K 2CEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=CWY0VoBd; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bo13-20020a0564020b2d00b0052228fad0f4si4633019edb.24.2023.07.25.20.58.44; Tue, 25 Jul 2023 20:59:08 -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=@linux.dev header.s=key1 header.b=CWY0VoBd; 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=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230307AbjGZC40 (ORCPT + 99 others); Tue, 25 Jul 2023 22:56:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjGZC4Z (ORCPT ); Tue, 25 Jul 2023 22:56:25 -0400 Received: from out-61.mta1.migadu.com (out-61.mta1.migadu.com [95.215.58.61]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8018E64 for ; Tue, 25 Jul 2023 19:56:23 -0700 (PDT) Date: Tue, 25 Jul 2023 19:56:13 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1690340181; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=M8HcyBJhNbmAFYQ4vhr/4v6PwhJI/M2KUGD3rBet++I=; b=CWY0VoBdxv90fE2Kx4slvk7SKhNU64RiS4zo/67lqAHvkomMISjpuadrAKmiZtx3178RPo yfNQlTWX6efUd8GwjE2kygFoh9/mTxSUiV5Wph+uzlk+0wfwPoF0KJq+FVvK2fSuFHgH1v ppQqROFo3fA+qYCo3RRaBLzBqJjPyxU= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Roman Gushchin To: Abel Wu 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)" Subject: Re: Re: [PATCH RESEND net-next 1/2] net-memcg: Scopify the indicators of sockmem pressure Message-ID: References: <20230711124157.97169-1-wuyun.abel@bytedance.com> <58e75f44-16e3-a40a-4c8a-0f61bbf393f9@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <58e75f44-16e3-a40a-4c8a-0f61bbf393f9@bytedance.com> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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, Jul 24, 2023 at 11:47:02AM +0800, Abel Wu wrote: > 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 Yes, now it makes sense to me. Thank you for the explanation. Then I'd organize the patchset in the following way: 1) cgroup v1-only fix to not throttle tcpmem based on the vmpressure 2) a formal code refactoring > > 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? I see... Generally speaking cgroup v1 is considered frozen, so we can leave it as it is, except when it creates an unnecessary complexity in the code. I'm curious, was your work driven by some real-world problem or a desire to clean up the code? Both are valid reasons of course. Thanks!