Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3452714pxb; Mon, 4 Apr 2022 17:26:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAMEd9JbpwdFtj3a/Qgi9/qJAWnlv4xoVmVOJ6u0HQtSbKKXj4kpHz3lo+uOWW2proBPCm X-Received: by 2002:a17:90a:7841:b0:1c7:e8ad:ea25 with SMTP id y1-20020a17090a784100b001c7e8adea25mr1004497pjl.25.1649118415914; Mon, 04 Apr 2022 17:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649118415; cv=none; d=google.com; s=arc-20160816; b=NrGvLYP94y/+JkugGCFC8+THXNta/tQ+08O4K1O95ZZKnGngOuFoMGcldZ6uzmE2b7 MwRM5wEfko8hUPPsWvk7e9wGZbpgJmE3JE7gvUBcxs9iUMWvblgqC2Qkxv/JS44G08KY RO5LHIm3tXETrQPzF73f4LruZkjaSBfw3fwEFocUP8JjfaRCDY2xgUEVYKNZMsKEmP2d QXiIZN0IvPjBfw+Pi1heEtTkW6zp0cgnA6iiwhjBXI4h2j/hXMnS0yGpY4n3VSr+SfcH GgBzhgCT2b2bqIC8KZbFCgJh2SHw4zV5bZWmtDcJm86cCPlDs2LgXL8GrZEeToTWs06p /CmA== 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:date:dkim-signature; bh=5dxs/pcLdXVxeVJIQ9J2D1RRV7VKB03Pri2wjxQxkWM=; b=1JGxmSmbMcnP5Mx1MNfEFLtIrCpTOfAFX34zQ/VaJgOKSfoL44Y/x2rUd6l3GnaPXJ EQFW4cfeC6YyBTsGAPxqG5Bi1W4tR876bGf7M+cS6Aq/T3sbCMwZed8zJl2CVCRYnsuS aABRTYYq4WsiYSdM9NK0a4CmDpGpi9/JbYKhKAFlB1q0IlhERpacLyW5QFY1Bn6lALNl ayL17sx+xi9NZT9EjBpFUW6cmB1Ca7OR7w2x3j2EJGbIk2vS6RQ+nJuUaxETAjiYcldx 7MOVCVoq0oJ2z5C5ZLklykv8YuwEkjLkT3tf8TPynpIq4IXV/DcVDu6+Guj/r6ddBLvV 03Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=lqtei1y5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id f19-20020a63f113000000b003994c5a1dc1si1858613pgi.508.2022.04.04.17.26.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Apr 2022 17:26:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=lqtei1y5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D1628119D; Mon, 4 Apr 2022 16:49:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345283AbiDDMcD (ORCPT + 99 others); Mon, 4 Apr 2022 08:32:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345159AbiDDMcA (ORCPT ); Mon, 4 Apr 2022 08:32:00 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4320725285; Mon, 4 Apr 2022 05:30:02 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 5CEDE210FD; Mon, 4 Apr 2022 12:30:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1649075400; h=from:from:reply-to: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=5dxs/pcLdXVxeVJIQ9J2D1RRV7VKB03Pri2wjxQxkWM=; b=lqtei1y56bozHx6RUQbYqp2K2A7ftAXKmlCZ9e+v0g0SgL9cP7EAMhkpt1OmwdUQ8K/FcZ 2yxYu6iHiH4hQ9VxGX3qGwd7+U7i0ZMZ7FrqBYl8ksOdylX32wqqr5hlPsTJKJVytO8PFT K1Ms4xnqI4b/aexn+8LnahmkZZRbyEY= Received: from suse.cz (unknown [10.100.201.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 7DFA0A3B87; Mon, 4 Apr 2022 12:29:59 +0000 (UTC) Date: Mon, 4 Apr 2022 14:29:59 +0200 From: Michal Hocko To: Zhaoyang Huang Cc: Suren Baghdasaryan , "zhaoyang.huang" , Andrew Morton , Johannes Weiner , Vladimir Davydov , "open list:MEMORY MANAGEMENT" , LKML , cgroups mailinglist , Ke Wang Subject: Re: [RFC PATCH] cgroup: introduce dynamic protection for memcg Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 04-04-22 19:23:03, Zhaoyang Huang wrote: > On Mon, Apr 4, 2022 at 5:32 PM Michal Hocko wrote: > > > > On Mon 04-04-22 17:23:43, Zhaoyang Huang wrote: > > > On Mon, Apr 4, 2022 at 5:07 PM Zhaoyang Huang wrote: > > > > > > > > On Mon, Apr 4, 2022 at 4:51 PM Michal Hocko wrote: > > > > > > > > > > On Mon 04-04-22 10:33:58, Zhaoyang Huang wrote: > > > > > [...] > > > > > > > One thing that I don't understand in this approach is: why memory.low > > > > > > > should depend on the system's memory pressure. It seems you want to > > > > > > > allow a process to allocate more when memory pressure is high. That is > > > > > > > very counter-intuitive to me. Could you please explain the underlying > > > > > > > logic of why this is the right thing to do, without going into > > > > > > > technical details? > > > > > > What I want to achieve is make memory.low be positive correlation with > > > > > > timing and negative to memory pressure, which means the protected > > > > > > memcg should lower its protection(via lower memcg.low) for helping > > > > > > system's memory pressure when it's high. > > > > > > > > > > I have to say this is still very confusing to me. The low limit is a > > > > > protection against external (e.g. global) memory pressure. Decreasing > > > > > the protection based on the external pressure sounds like it goes right > > > > > against the purpose of the knob. I can see reasons to update protection > > > > > based on refaults or other metrics from the userspace but I still do not > > > > > see how this is a good auto-magic tuning done by the kernel. > > > > > > > > > > > The concept behind is memcg's > > > > > > fault back of dropped memory is less important than system's latency > > > > > > on high memory pressure. > > > > > > > > > > Can you give some specific examples? > > > > For both of the above two comments, please refer to the latest test > > > > result in Patchv2 I have sent. I prefer to name my change as focus > > > > transfer under pressure as protected memcg is the focus when system's > > > > memory pressure is low which will reclaim from root, this is not > > > > against current design. However, when global memory pressure is high, > > > > then the focus has to be changed to the whole system, because it > > > > doesn't make sense to let the protected memcg out of everybody, it > > > > can't > > > > do anything when the system is trapped in the kernel with reclaiming work. > > > Does it make more sense if I describe the change as memcg will be > > > protect long as system pressure is under the threshold(partially > > > coherent with current design) and will sacrifice the memcg if pressure > > > is over the threshold(added change) > > > > No, not really. For one it is still really unclear why there should be any > > difference in the semantic between global and external memory pressure > > in general. The low limit is always a protection from the external > > pressure. And what should be the actual threshold? Amount of the reclaim > > performed, effectivness of the reclaim or what? > Please find bellowing for the test result, which shows current design > has more effective protection when system memory pressure is high. It > could be argued that the protected memcg lost the protection as its > usage dropped too much. Yes, this is exactly how I do see it. The memory low/min is a clear decision of the administrator to protect the memory consumption of the said memcg (or hierarchy) from external memory pressure. > I would like to say that this is just the goal > of the change. Is it reasonable to let the whole system be trapped in > memory pressure while the memcg holds the memory? I would argue that this is expected and reasonable indeed. You cannot provide a protection withtout pushing the pressure to others. The memory is a finite resource. > With regard to > threshold, it is a dynamic decayed watermark value which represents > the historic(watermark) and present(update to new usage if it expands > again) usage. Actually, I have update the code by adding opt-in code > which means this is a opt type of the memcg. This patch is coherent to > the original design if user want to set the fixed value by default and > also provide a new way of dynamic protected memcg without external > monitor and interactivation. The more I read here to more I am convinced that hooking into low/min limits is simply wrong. If you want to achieve a more "clever" way to balance memory reclaim among existing memcgs then fine but trying to achieve that by dynamically interpreting low limits is just an abuse of an existing interface IMO. What has led you to (ab)use low limit in the first place? > We simply test above change by comparing it with current design on a v5.4 based > system in 3GB RAM in bellowing steps, via which we can find that fixed > memory.low have the system experience high memory pressure with holding too > much memory. > > 1. setting up the topology seperatly as [1] > 2. place a memory cost process into B and have it consume 1GB memory > from userspace. > 3. generating global memory pressure via mlock 1GB memory. > 4. watching B's memory.current and PSI_MEM. > 5. repeat 3,4 twice. This is effectively an OOM test, isn't it? Memory low protection will be enforced as long as there is something reclaimable but your memory pressure is unreclaimable due to mlock so it has a stronger guarantee than low limit so the protected memcg is going to be reclaimed. Maybe I am just not following but this makes less and less sense as I am reading through. So either I am missing something really significant or we are just not on the same page. -- Michal Hocko SUSE Labs