From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1748EC433F5 for ; Sun, 3 Apr 2022 15:05:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51B406B0072; Sun, 3 Apr 2022 11:04:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CA796B0073; Sun, 3 Apr 2022 11:04:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 391BF6B0074; Sun, 3 Apr 2022 11:04:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 2AEFE6B0072 for ; Sun, 3 Apr 2022 11:04:52 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E11C1205C4 for ; Sun, 3 Apr 2022 15:04:41 +0000 (UTC) X-FDA: 79315889562.15.14FDD54 Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173]) by imf12.hostedemail.com (Postfix) with ESMTP id 7158440025 for ; Sun, 3 Apr 2022 15:04:41 +0000 (UTC) Received: by mail-yb1-f173.google.com with SMTP id f38so13382227ybi.3 for ; Sun, 03 Apr 2022 08:04:41 -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=o1a2JVSeIsg2n4ZPERcRwhBo2C98JOFbdzvDc4k4uyY=; b=lPiPbC/t1ZONedq5p4jRaLJSgnXNlu8ckGlSdays2/JRFNJ8SQ22JXehsnSCOBhtRE oQBxdjUsuCd7ZmU+nVc7oWCZNnoynu9fz9eSmY/Duz2fHGiCsVlmHmeJzqIKQh999KLv k4d1agL0ZunXTrAdcC7/I3mWf+udbWmRvNfgdN0IUCDpKwo0j7Aqk4TD3hKC4vwmY6V/ ijxSemBS8EgzN0y9OReOorBobYABLcxH6k1uHuH2f/z6zoO3CO89P+yOqWpnEM8XP2Mo rbpFshHNFodJb+MFXRq6CoFAazWBBDm3vxKlIyvFCnZxDl1mdI1fPhj4yiWNQ7WjczKI QgFQ== 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=o1a2JVSeIsg2n4ZPERcRwhBo2C98JOFbdzvDc4k4uyY=; b=kOcIIFLcWPAB+hjXZovbNRAN1ZxbipFjOXxmYSRzCFX0M6ywBkDRcDoQSfZTozr/sO /vrPdZL/7p7GqIGh/gGYJf+C0LUGd5gFDX0Hm7SRy65tcaAg+3xpvwWdyza4ZvNUHDBZ Qv3uSvDR59x97Rj54m3/SD7wnun1QxHS6P6lvXx7NLL2wCL8VrqHnHde22zgYDFCAn83 9+j/bMavV++jWdJAq3V7oYbM/+nMlrdQLdkYhDoVaYgXAsVBYPB2kTRjHlVop1845k4Z 8Byazpfb8k3uSihHGYxzKygfWGZjyEx1Pl3JaqFYUopqtfcrjXvcZrKn/od8h0t22bQx D/bQ== X-Gm-Message-State: AOAM5327y6cJCvC56qVhhy92I+aGPD428KSecxWsodEgkU6JmAwo0sL5 TIs40MdGCybaSYZnBPzoWRrHJksdL/vsBn36h6bdnQ== X-Google-Smtp-Source: ABdhPJx6EzmSEWE8rVRtD7a3gHc2p3QZhet3QHh22eUylFDpjS2S+FoLE1X153mpIx+V6iPztColsYQlOCd/kjsa5rk= X-Received: by 2002:a25:3852:0:b0:63d:bdb4:d882 with SMTP id f79-20020a253852000000b0063dbdb4d882mr1876485yba.426.1648998280430; Sun, 03 Apr 2022 08:04:40 -0700 (PDT) MIME-Version: 1.0 References: <1648713656-24254-1-git-send-email-zhaoyang.huang@unisoc.com> In-Reply-To: From: Suren Baghdasaryan Date: Sun, 3 Apr 2022 08:04:29 -0700 Message-ID: Subject: Re: [RFC PATCH] cgroup: introduce dynamic protection for memcg To: Zhaoyang Huang 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7158440025 X-Stat-Signature: n5mz3xoh9t3qy1kx7na4b45nxyoqd1o5 X-Rspam-User: Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="lPiPbC/t"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of surenb@google.com designates 209.85.219.173 as permitted sender) smtp.mailfrom=surenb@google.com X-HE-Tag: 1648998281-759262 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, Apr 1, 2022 at 10:18 PM Zhaoyang Huang wrote: > > On Fri, Apr 1, 2022 at 7:34 PM Michal Hocko wrote: > > > > 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. > You are right. This scheme treats the system's memory pressure > equally, no matter if it comes from in-kernel page allocation with > high order or cache drop by IO like things. The decay_factor composed > of PSI_SOME and PSI_FULL which represent the system is tight on > memory, every entity has the obligation to donate to solve this issue. > > > > > > [...] > > > > > > 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. > Yes. As my reply to Suren's comment, even a positive monitor service > which could be aware of the activity starting(APP launching etc) at > the very first time, has to 1. read PSI and memcg->watermark/usage 2. > make a decision. 3. write memcg->memory.low to adjust memory > allowance. Furthermore, monitors could not supervise the APP for whole > life time, while the reclaiming could arise at any time. Ok, sounds like you want this dynamic limit to be active all the time, not only at specific points in the process's life cycle. 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? > > > -- > > Michal Hocko > > SUSE Labs