Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1208870pxb; Fri, 1 Apr 2022 07:26:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFRhkl+DlmPgxWO7+q8EyTwc/WL/ylEs3x9OnD+UHhriQohXcVfQCOrlIWIZ9i9/I4bLSQ X-Received: by 2002:a63:b555:0:b0:398:4ca1:4be0 with SMTP id u21-20020a63b555000000b003984ca14be0mr15282604pgo.294.1648823183874; Fri, 01 Apr 2022 07:26:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648823183; cv=none; d=google.com; s=arc-20160816; b=iktI3B3oZ5GhOOuj1C28LgJkjMmJbLY5xWGU5OkrolGPrIprgPXaGgPbgjRoIXwZvP OmGcA3EedckTTdgyo6Sh3p4MyvwJqG0oV5VPQs/MRGeEfw6ebfykTkxItOAzKPH45jSi Ddy46mkc1jNpCe2mPXn46azJPXMXuYHzckwavABXDFmpyfDZXcqf1XkxnAkf3tRWlcO0 +si/wLj3yjJpEINQVROsXbrXM2D6Owdj8fImRdNKEMAjMS0UOEwqGK9B2o26+42lBLEf oZV8RrwsRgp1AiHgv0HHyoFqe5DJ8PM0KBRtRkGvY+WKJqx1bCdqAMlNlEjbk+jYyXQ3 lMcA== 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=3HQl64Cj0Sry5BnIv1XFR1Ee5SQlSyhmW0GaIDy+uVE=; b=MRw9PfGZo3wQ1Re0B6A3G2K6MD/oASK92YCMFlTpnKVJtot1WHNcClY5wrFm2zHegu yBJ32mBbdRcEutV6cg7V0crnztHMLGSDRUzpfjDucLvg3MJt8Rbgjkqhm0Wfbtybz/Uu sssgbs1boP+Jrsl82dwmuFExjRjidu5p8Y9sp+Nd2GkLbvkcjEc9GS5mTh58jRjSiBfO fWl/8xTg9Y5+grSaiHg3TkRjcdHemFGk9LGDvPLwvIk53aiYnaOGENnyau1oMiWpuqMl JEIwKDo0MYQpTBMPPAEE1qUBR47+Dmox+wo+no+XFYwk5sQGxriNfBTAE/2t3qfmwcCq hIUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Tp5z97a7; 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=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c1-20020a056a000ac100b004fa3a8e0012si2707254pfl.201.2022.04.01.07.26.09; Fri, 01 Apr 2022 07:26:23 -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=@suse.com header.s=susede1 header.b=Tp5z97a7; 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=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345527AbiDALgL (ORCPT + 99 others); Fri, 1 Apr 2022 07:36:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238883AbiDALgI (ORCPT ); Fri, 1 Apr 2022 07:36:08 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8F111D2515; Fri, 1 Apr 2022 04:34:18 -0700 (PDT) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 9400D21612; Fri, 1 Apr 2022 11:34:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1648812857; 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=3HQl64Cj0Sry5BnIv1XFR1Ee5SQlSyhmW0GaIDy+uVE=; b=Tp5z97a7IRx4XlEC6GyhubhMP7XO835TkZauXZwpC7ZQJFRKX//ek5wrKndXyxVFeNEoFG 9NtJ35eph7ci1tGFEr8/JVi+qFNRmQ+UyR91XoyjdMpraNHYez3uoMRJ0MZcodv2TvjQrG VT3nfHf4Ec2ivQNFi09Dxw9fhlOUc2k= 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 0D02BA3B88; Fri, 1 Apr 2022 11:34:15 +0000 (UTC) Date: Fri, 1 Apr 2022 13:34:13 +0200 From: Michal Hocko To: Zhaoyang Huang Cc: "zhaoyang.huang" , Andrew Morton , Johannes Weiner , Suren Baghdasaryan , Vladimir Davydov , "open list:MEMORY MANAGEMENT" , LKML , cgroups@vger.kernel.org, Ke Wang Subject: Re: [RFC PATCH] cgroup: introduce dynamic protection for memcg Message-ID: References: <1648713656-24254-1-git-send-email-zhaoyang.huang@unisoc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Fri 01-04-22 09:34:02, Zhaoyang Huang wrote: > On Thu, Mar 31, 2022 at 7:35 PM Michal Hocko wrote: > > > > On Thu 31-03-22 19:18:58, Zhaoyang Huang wrote: > > > On Thu, Mar 31, 2022 at 5:01 PM Michal Hocko wrote: > > > > > > > > On Thu 31-03-22 16:00:56, zhaoyang.huang wrote: > > > > > From: Zhaoyang Huang > > > > > > > > > > For some kind of memcg, the usage is varies greatly from scenarios. Such as > > > > > multimedia app could have the usage range from 50MB to 500MB, which generated > > > > > by loading an special algorithm into its virtual address space and make it hard > > > > > to protect the expanded usage without userspace's interaction. > > > > > > > > Do I get it correctly that the concern you have is that you do not know > > > > how much memory your workload will need because that depends on some > > > > parameters? > > > right. such as a camera APP will expand the usage from 50MB to 500MB > > > because of launching a special function(face beauty etc need special > > > algorithm) > > > > > > > > > Furthermore, fixed > > > > > memory.low is a little bit against its role of soft protection as it will response > > > > > any system's memory pressure in same way. > > > > > > > > Could you be more specific about this as well? > > > As the camera case above, if we set memory.low as 200MB to keep the > > > APP run smoothly, the system will experience high memory pressure when > > > another high load APP launched simultaneously. I would like to have > > > camera be reclaimed under this scenario. > > > > OK, so you effectivelly want to keep the memory protection when there is > > a "normal" memory pressure but want to relax the protection on other > > high memory utilization situations? > > > > How do you exactly tell a difference between a steady memory pressure > > (say stream IO on the page cache) from "high load APP launched"? Should > > you reduce the protection on the stram IO situation as well? > We can take either system's io_wait or PSI_IO into consideration for these. I do not follow. Let's say you have a stream IO workload which is mostly RO. Reclaiming those pages means effectivelly to drop them from the cache so there is no IO involved during the reclaim. This will generate a constant flow of reclaim that shouldn't normally affect other workloads (as long as kswapd keeps up with the IO pace). How does your scheme cope with this scenario? My understanding is that it will simply relax the protection. > > [...] > > > > One very important thing that I am missing here is the overall objective of this > > > > tuning. From the above it seems that you want to (ab)use memory->low to > > > > protect some portion of the charged memory and that the protection > > > > shrinks over time depending on the the global PSI metrict and time. > > > > But why this is a good thing? > > > 'Good' means it meets my original goal of keeping the usage during a > > > period of time and responding to the system's memory pressure. For an > > > android like system, memory is almost forever being in a tight status > > > no matter how many RAM it has. What we need from memcg is more than > > > control and grouping, we need it to be more responsive to the system's > > > load and could sacrifice its usage under certain criteria. > > > > Why existing tools/APIs are insufficient for that? You can watch for > > both global and memcg memory pressure including PSI metrics and update > > limits dynamically. Why is it necessary to put such a logic into the > > kernel? > Poll and then React method in userspace requires a polling interval > and response time. Take PSI as an example, it polls ten times during > POLLING_INTERVAL while just report once, which introduce latency in > some extend. Do workload transitions happen so often in your situation that the interval really matters? As Suren already pointed out starting a new application is usually an explicit event which can pro-activelly update limits. -- Michal Hocko SUSE Labs