Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2695673pxb; Sun, 3 Apr 2022 17:16:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySPwrNDoL6rYE8zsZ44Ati9MMH1QK8vIjmbgwh21V28TpjEQBVF7a+7q5b/+SWggZM/d5X X-Received: by 2002:a17:90b:1c0d:b0:1c7:3b02:aa68 with SMTP id oc13-20020a17090b1c0d00b001c73b02aa68mr23704610pjb.187.1649031410833; Sun, 03 Apr 2022 17:16:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649031410; cv=none; d=google.com; s=arc-20160816; b=a9SuDeBU0USgJE6sgSSpBQH6glZs7DsL4vCQ6xjUAJdvskInOGL5HSZeyvyMIa+PXC k+0lHoeXO3bXpfy5+yKviL19bk68mRfD28dnkNpeYbbq2rDuVgdCtKEBeGfza/GAWk7y b53E+twRpyId0uajuisOhzFmKyzsqJCFEsZfxvKM27jqMe0uQ1PeY/Nb+Fi38fs+Snac xQQSZiB6bKWbmZ2ECtE6dNS6/VT7RNfHScPqkBMnXgSdm/00yTGoBKNZ/jbhpWs3/jJh APiyTj7AVNpcR8+Jw0ufNhDX10oNr74oVhrOnVbx+Ef4ooTTFd8gmzVXmMKfVsUNPSeD j8lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=TX6QX0+HXrSqPnqJDfaKnpAt/asDBfCVYhsU3t5tEcc=; b=EjyOrWqxd0Z0Ab9nUEw9RtZrNaCvdh7y25ckwVixmYHwLe0CUU/0I4NGpNMEW6socp mLkHYErUTtEQm1BDHljCHbXpKTG3I+TaUdlGNknNzQ1V/zfeIfVZ+5Cs9asSU+qeiNNq dit20qL8SamJ1FdyH8uyZIVGG88U3Me889wTZsQK7S8+eCPyPcFhKyxwValgDtpT0itM xCoieiGX1pkvTePzU4Mm3JrgUzizAYxjq3+seaZDgwka25KJt6C/hjaJSQz5EMwCkJFD cReY3sjxASy6nqBa8ExesmuWyeLlHUpmOsxNjfY4otzPTHaVH/F6rHB+TmKFU0s16bX3 B3gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nb3MbJRR; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a9-20020a63d409000000b003816043ef0csi8569982pgh.257.2022.04.03.17.16.36; Sun, 03 Apr 2022 17:16:50 -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=@google.com header.s=20210112 header.b=nb3MbJRR; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240651AbiCaT21 (ORCPT + 99 others); Thu, 31 Mar 2022 15:28:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234433AbiCaT20 (ORCPT ); Thu, 31 Mar 2022 15:28:26 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24FDB1DFDE5 for ; Thu, 31 Mar 2022 12:26:39 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id f38so1209479ybi.3 for ; Thu, 31 Mar 2022 12:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TX6QX0+HXrSqPnqJDfaKnpAt/asDBfCVYhsU3t5tEcc=; b=nb3MbJRRAbBq9xDAD1NkGl6UAAGL0QIEi9Lgjrtb61uhKkmxKE2ynQ1oz3cxOJ6xaL hUw2V2U6RikzGjio0lGQsjrt8P4ZUdwVuQmENM9+qmYF4bLsKGbvRyFMp3dW2EeoZ46q Ozvbohpe3e5Et69346PFXjYvxEjxJx0h9Ow//0q/jX97jqtRytW2dgZWdpfnhKiRImgf BQXQkrxJtZNwtShSr7InkA/MggN0JtZO/Vp/58i4pvPelyqW8S2KgYer5xwnrSWNt5N2 nNQOEBZZndbQX1lmru4YUbyIp57jfGAktPoso00dg+tuqHJv2rO/pqiEAtsT976rgnoq 69NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TX6QX0+HXrSqPnqJDfaKnpAt/asDBfCVYhsU3t5tEcc=; b=ewu7kSRtyi9MgCGORBX40RZDznoIJw+zPL3JnVCmzNca40IcJetHMRhMDGRNxqoC/w aWALyC7zu9ylD6ExUc2Nbl2hs8G6eXAtQEbZLsGnzk5eWYvLuSrWYfftI/jQVzX+Kvoc S/jVD5PpFqPEavQTfe7yRp+JL6bBFe/SlQBbUYaE9RKP331WqZXeIpO5mL72wgWV0jq9 Omz+Yz0SuIlG89DpeNYiipyle+r29WJktW9GQpixLn2FurstHDP5DILeG+KR8aqXWi0J nb1W1d70lbq4M2XP09xrCstRtmcpkdXf6BhtOdGGkTnc6d3vZVGFWBPqnGbsqkOH+UCE XOKQ== X-Gm-Message-State: AOAM530bY68xmfBnr8BaUKDgIuL/8dw6ylIHHHGpwDZjmEyzPyb+OAo9 MEeEIaJbfgYXEtGdLM6iycrREQHegO65FQxjf3nTAA== X-Received: by 2002:a25:608:0:b0:634:5ff5:7c65 with SMTP id 8-20020a250608000000b006345ff57c65mr5199291ybg.282.1648754798107; Thu, 31 Mar 2022 12:26:38 -0700 (PDT) MIME-Version: 1.0 References: <1648713656-24254-1-git-send-email-zhaoyang.huang@unisoc.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 31 Mar 2022 12:26:27 -0700 Message-ID: Subject: Re: [RFC PATCH] cgroup: introduce dynamic protection for memcg To: Michal Hocko Cc: Zhaoyang Huang , "zhaoyang.huang" , Andrew Morton , Johannes Weiner , Vladimir Davydov , "open list:MEMORY MANAGEMENT" , LKML , cgroups mailinglist , Ke Wang Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Thu, Mar 31, 2022 at 4:35 AM 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? IIUC what you are implementing here is a "memory allowance boost" feature and it seems you are implementing it entirely inside the kernel, while only userspace knows when to apply this boost (say at app launch time). This does not make sense to me. > > [...] > > > 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? I had exactly the same thought while reading through this. In Android you would probably need to implement a userspace service which would temporarily relax the memcg limits when required, monitor PSI levels and adjust the limits accordingly. > > -- > Michal Hocko > SUSE Labs