Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1783235pxb; Sat, 2 Apr 2022 03:26:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqYi6eOKoRr+LQd/MhhA062+I+DnQKsi5QfcHTG8BpMEKNJ875KicEH5YHbvb/1v8m67rA X-Received: by 2002:a17:902:e889:b0:151:a56d:eb8f with SMTP id w9-20020a170902e88900b00151a56deb8fmr14293001plg.142.1648895213689; Sat, 02 Apr 2022 03:26:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648895213; cv=none; d=google.com; s=arc-20160816; b=XxKqaF5wbRyN7JVqaQgfHQxeuCatKL8pkEsG/Z7yKiI7EsIYbRaeV+E+ifkL5mW4nJ ngM7BFeCXqI4iYSEYNNerwvDzcWgTFY6lB8GBmAe5PwS1mObCCjERJbx3rP4xBq2V16L Ywuo9/8npsXTUQfFun3+VdLK/A/g2mS8wxmIhus3m/5lb9ExXd/+enLLnwiTOmcOHfpl F6ohbL8gFyriv+GiG1h0o1ve7yU5C3hBr4ZE5OV3WGAmlNODnbyLHAWpUczlqJbv+US7 E128YBqUc2ekRh2yuYA3LhE8SWkgKDxkSYaMqxEJyEDBM2qL7xmoQKORdoLEfIrhzRTH fOzg== 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=5dbe41dvMeibhzpqOSIQnkhPlg4dZw5Ah44FWg9H4CM=; b=WYcJdHChd3MKkQqnf6YTG6kZlmkC2aJ2gl/X+w5aYp6N2AzElQgfGL/3oTUnf4eRzJ tNNZUtOtH6FJFnIBRVBGwi5U9GDyl0HFa6i+Pv/hnakoSIuNWEhzX2d/bVKWHHJ1h9w6 5e0r2eovIOupxgiqVpyS9WmATd+UMc7itoOV0ApfxYOcYjGjb7aLlFIjd+eRZIZsUvRk 1iXJ16pVGZBjlw4TqAhbU4u9fWNarbg4UOkKe2XU67lpdDSeXk3YAfhUlBId4QAlxsPc XP/5OGJKc8teeBno7OJgshSz3v+Xb4M7TPqkU2eMsFVvF0wIybnHDfspmOFlfhaZpyOY JtAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NNOnVEr1; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c19-20020a637253000000b003821c6a6897si4940209pgn.758.2022.04.02.03.26.39; Sat, 02 Apr 2022 03:26:53 -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=@gmail.com header.s=20210112 header.b=NNOnVEr1; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243874AbiDABxk (ORCPT + 99 others); Thu, 31 Mar 2022 21:53:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243869AbiDABxi (ORCPT ); Thu, 31 Mar 2022 21:53:38 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C5B82571B9; Thu, 31 Mar 2022 18:51:50 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id 10so1070210qtz.11; Thu, 31 Mar 2022 18:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5dbe41dvMeibhzpqOSIQnkhPlg4dZw5Ah44FWg9H4CM=; b=NNOnVEr19neIM7273P28aPKE9z7zRSXH889QcLQTa17aFwCGYWyoOjGZq7agLkuR/A InpsvR1AP9H4yyco9jZiHjV6ZXr5gY1eGXsQGrPfsBBBZQXLq5eU/0eZYY9xusv5Y5g5 ul3y4ser5TjHRk3ToUENstkT9vmPN3sTyG72qBStx5y0JCsDie9YO3bY7Va16uEWEnog 2X9qzH7FSmwQh4flfr7TTaXc0I0+v06FBNUjYcZ5ljTCckVrBAWJiLuFlbaTR99p32Ue HqIx2lCXjUKa0VFbqMXi0SFcKPClu1rvpWyXp2Tn82RQZjlsU4/psD1MUh3FmLarTCaF Ycyw== 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=5dbe41dvMeibhzpqOSIQnkhPlg4dZw5Ah44FWg9H4CM=; b=KbaevM0w1sqrQyTWiBBmr3HzlbIk1aVYKw4qMfcxdV+LG/L6+ZUMq8yuQBlLSB05kT EHiC61VabIR1RU6nozHQpdN59xzJ9jEvCQ73uLQAQlGf1zmEVYepTNHZHuxQjpUiIQUV 32cimOIvucJXtzSXC+1Sqh2z5N9MSpNa5ICWFEzx3WltSmqlEqf9dvrW0h1USzH/gOoB O8m4jCP4EGCsW4Y7KGblza3bIe0JXtLkTL+KU56yF+NJeMesEbc4dNQ6hKCnM16YKne0 uXUnMVI1qmNAi+6FsqgdhgC8/cGU3bjQS8A4LTcixLbmHPKp7X2lh/Oi1M9BkA9+8FAt GZxQ== X-Gm-Message-State: AOAM530SN6X/cnKHvJcsa9/sEJsznqmJFRirgQ9J9e98Rc1eMMsV+eTp 0aYlM09O6BXCDVks878hmQ9PR0zWG4QlE7vyY6R6SVCnC3+GmQ== X-Received: by 2002:a05:622a:1013:b0:2e1:c9c0:9831 with SMTP id d19-20020a05622a101300b002e1c9c09831mr6891444qte.245.1648777909152; Thu, 31 Mar 2022 18:51:49 -0700 (PDT) MIME-Version: 1.0 References: <1648713656-24254-1-git-send-email-zhaoyang.huang@unisoc.com> In-Reply-To: From: Zhaoyang Huang Date: Fri, 1 Apr 2022 09:51:21 +0800 Message-ID: Subject: Re: [RFC PATCH] cgroup: introduce dynamic protection for memcg To: Suren Baghdasaryan Cc: Michal Hocko , "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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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, Apr 1, 2022 at 3:26 AM Suren Baghdasaryan wrote: > > 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. I am wondering if it could be more helpful to apply this patch on the background services(system_server etc) than APP, while the latter ones are persistent to the system. > > > > > [...] > > > > 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. As my response to Michal's comment. Userspace monitors introduce latency. Take LMKD as an example, it is actually driven by the PSI_POLL_PERIOD_XXX_MS after first wakeup, which means PSI_WINDOW_SIZE_MS could be too big to rely on. IMHO, with regards to the responding time, LMKD is less efficient than lmk driver but more strong in strategy things. I would like to test this patch in real android's work load and feedback in next version. > > > > > -- > > Michal Hocko > > SUSE Labs