All of lore.kernel.org
 help / color / mirror / Atom feed
From: Suren Baghdasaryan <surenb@google.com>
To: Zhaoyang Huang <huangzhaoyang@gmail.com>
Cc: Michal Hocko <mhocko@suse.com>,
	"zhaoyang.huang" <zhaoyang.huang@unisoc.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Vladimir Davydov <vdavydov.dev@gmail.com>,
	"open list:MEMORY MANAGEMENT" <linux-mm@kvack.org>,
	LKML <linux-kernel@vger.kernel.org>,
	cgroups mailinglist <cgroups@vger.kernel.org>,
	Ke Wang <ke.wang@unisoc.com>
Subject: Re: [RFC PATCH] cgroup: introduce dynamic protection for memcg
Date: Sun, 3 Apr 2022 08:04:29 -0700	[thread overview]
Message-ID: <CAJuCfpHneDZMXO_MmQDPA+igAOdAPRUChiq+zftFXGfDzPHNhQ@mail.gmail.com> (raw)
In-Reply-To: <CAGWkznF7cSyPU0ceYwH6zweJzf-X1bQnS6AJ2-J+WEL0u8jzng@mail.gmail.com>

On Fri, Apr 1, 2022 at 10:18 PM Zhaoyang Huang <huangzhaoyang@gmail.com> wrote:
>
> On Fri, Apr 1, 2022 at 7:34 PM Michal Hocko <mhocko@suse.com> wrote:
> >
> > On Fri 01-04-22 09:34:02, Zhaoyang Huang wrote:
> > > On Thu, Mar 31, 2022 at 7:35 PM Michal Hocko <mhocko@suse.com> wrote:
> > > >
> > > > On Thu 31-03-22 19:18:58, Zhaoyang Huang wrote:
> > > > > On Thu, Mar 31, 2022 at 5:01 PM Michal Hocko <mhocko@suse.com> wrote:
> > > > > >
> > > > > > On Thu 31-03-22 16:00:56, zhaoyang.huang wrote:
> > > > > > > From: Zhaoyang Huang <zhaoyang.huang@unisoc.com>
> > > > > > >
> > > > > > > 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

WARNING: multiple messages have this Message-ID (diff)
From: Suren Baghdasaryan <surenb-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
To: Zhaoyang Huang <huangzhaoyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Michal Hocko <mhocko-IBi9RG/b67k@public.gmane.org>,
	"zhaoyang.huang"
	<zhaoyang.huang-1tVvrHeaX6nQT0dZR+AlfA@public.gmane.org>,
	Andrew Morton
	<akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org>,
	Johannes Weiner <hannes-druUgvl0LCNAfugRpC6u6w@public.gmane.org>,
	Vladimir Davydov
	<vdavydov.dev-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	"open list:MEMORY MANAGEMENT"
	<linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org>,
	LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	cgroups mailinglist
	<cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Ke Wang <ke.wang-1tVvrHeaX6nQT0dZR+AlfA@public.gmane.org>
Subject: Re: [RFC PATCH] cgroup: introduce dynamic protection for memcg
Date: Sun, 3 Apr 2022 08:04:29 -0700	[thread overview]
Message-ID: <CAJuCfpHneDZMXO_MmQDPA+igAOdAPRUChiq+zftFXGfDzPHNhQ@mail.gmail.com> (raw)
In-Reply-To: <CAGWkznF7cSyPU0ceYwH6zweJzf-X1bQnS6AJ2-J+WEL0u8jzng-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On Fri, Apr 1, 2022 at 10:18 PM Zhaoyang Huang <huangzhaoyang-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> On Fri, Apr 1, 2022 at 7:34 PM Michal Hocko <mhocko-IBi9RG/b67k@public.gmane.org> wrote:
> >
> > On Fri 01-04-22 09:34:02, Zhaoyang Huang wrote:
> > > On Thu, Mar 31, 2022 at 7:35 PM Michal Hocko <mhocko-IBi9RG/b67k@public.gmane.org> wrote:
> > > >
> > > > On Thu 31-03-22 19:18:58, Zhaoyang Huang wrote:
> > > > > On Thu, Mar 31, 2022 at 5:01 PM Michal Hocko <mhocko-IBi9RG/b67k@public.gmane.org> wrote:
> > > > > >
> > > > > > On Thu 31-03-22 16:00:56, zhaoyang.huang wrote:
> > > > > > > From: Zhaoyang Huang <zhaoyang.huang-1tVvrHeaX6nQT0dZR+AlfA@public.gmane.org>
> > > > > > >
> > > > > > > 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

  reply	other threads:[~2022-04-03 15:04 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-31  8:00 [RFC PATCH] cgroup: introduce dynamic protection for memcg zhaoyang.huang
2022-03-31  8:00 ` zhaoyang.huang
2022-03-31  9:01 ` Michal Hocko
2022-03-31  9:01   ` Michal Hocko
2022-03-31 11:18   ` Zhaoyang Huang
2022-03-31 11:18     ` Zhaoyang Huang
2022-03-31 11:35     ` Michal Hocko
2022-03-31 11:35       ` Michal Hocko
2022-03-31 19:26       ` Suren Baghdasaryan
2022-03-31 19:26         ` Suren Baghdasaryan
2022-04-01  1:51         ` Zhaoyang Huang
2022-04-01  1:51           ` Zhaoyang Huang
2022-04-01  4:46           ` Suren Baghdasaryan
2022-04-01  4:46             ` Suren Baghdasaryan
2022-04-02  3:21             ` Zhaoyang Huang
2022-04-02  3:21               ` Zhaoyang Huang
2022-04-01  1:34       ` Zhaoyang Huang
2022-04-01  1:34         ` Zhaoyang Huang
2022-04-01 11:34         ` Michal Hocko
2022-04-01 11:34           ` Michal Hocko
2022-04-02  5:18           ` Zhaoyang Huang
2022-04-02  5:18             ` Zhaoyang Huang
2022-04-03 15:04             ` Suren Baghdasaryan [this message]
2022-04-03 15:04               ` Suren Baghdasaryan
2022-04-04  2:33               ` Zhaoyang Huang
2022-04-04  2:33                 ` Zhaoyang Huang
2022-04-04  8:51                 ` Michal Hocko
2022-04-04  8:51                   ` Michal Hocko
2022-04-04  9:07                   ` Zhaoyang Huang
2022-04-04  9:07                     ` Zhaoyang Huang
2022-04-04  9:23                     ` Zhaoyang Huang
2022-04-04  9:23                       ` Zhaoyang Huang
2022-04-04  9:32                       ` Michal Hocko
2022-04-04  9:32                         ` Michal Hocko
2022-04-04  9:36                         ` Michal Hocko
2022-04-04  9:36                           ` Michal Hocko
2022-04-04 11:35                           ` Zhaoyang Huang
2022-04-04 11:23                         ` Zhaoyang Huang
2022-04-04 11:23                           ` Zhaoyang Huang
2022-04-04 12:29                           ` Michal Hocko
2022-04-04 12:29                             ` Michal Hocko
2022-04-04 13:14                             ` Zhaoyang Huang
2022-04-04 13:14                               ` Zhaoyang Huang
2022-04-05 12:08                               ` Michal Hocko
2022-04-05 12:08                                 ` Michal Hocko
2022-04-06  2:11                                 ` Zhaoyang Huang
2022-04-06  2:11                                   ` Zhaoyang Huang
2022-04-07  7:40                                   ` Michal Hocko
2022-04-07  7:40                                     ` Michal Hocko
2022-04-07  8:59                                     ` Zhaoyang Huang
2022-04-07  9:44                                       ` Michal Hocko
2022-04-07  9:44                                         ` Michal Hocko
2022-04-07 12:36                                         ` Zhaoyang Huang
2022-04-07 12:36                                           ` Zhaoyang Huang
2022-04-07 14:14                                           ` Michal Hocko
2022-04-07 14:14                                             ` Michal Hocko
2022-04-06  8:21                                 ` Zhaoyang Huang
2022-04-06  8:21                                   ` Zhaoyang Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJuCfpHneDZMXO_MmQDPA+igAOdAPRUChiq+zftFXGfDzPHNhQ@mail.gmail.com \
    --to=surenb@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=huangzhaoyang@gmail.com \
    --cc=ke.wang@unisoc.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=vdavydov.dev@gmail.com \
    --cc=zhaoyang.huang@unisoc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.