[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Ykb4DVt0eKrstDWv@dhcp22.suse.cz>
Date: Fri, 1 Apr 2022 15:03:09 +0200
From: Michal Hocko <mhocko@...e.com>
To: Yosry Ahmed <yosryahmed@...gle.com>
Cc: Wei Xu <weixugc@...gle.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Johannes Weiner <hannes@...xchg.org>,
Shakeel Butt <shakeelb@...gle.com>,
David Rientjes <rientjes@...gle.com>,
Tejun Heo <tj@...nel.org>, Zefan Li <lizefan.x@...edance.com>,
Roman Gushchin <roman.gushchin@...ux.dev>,
cgroups@...r.kernel.org, linux-doc@...r.kernel.org,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Linux MM <linux-mm@...ck.org>,
Jonathan Corbet <corbet@....net>, Yu Zhao <yuzhao@...gle.com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Greg Thelen <gthelen@...gle.com>
Subject: Re: [PATCH resend] memcg: introduce per-memcg reclaim interface
On Fri 01-04-22 02:17:28, Yosry Ahmed wrote:
> On Thu, Mar 31, 2022 at 8:38 PM Wei Xu <weixugc@...gle.com> wrote:
> >
> > On Thu, Mar 31, 2022 at 5:33 PM Andrew Morton <akpm@...ux-foundation.org> wrote:
> > >
> > > On Thu, 31 Mar 2022 08:41:51 +0000 Yosry Ahmed <yosryahmed@...gle.com> wrote:
> > >
> > > > --- a/mm/memcontrol.c
> > > > +++ b/mm/memcontrol.c
> > > > @@ -6355,6 +6355,38 @@ static ssize_t memory_oom_group_write(struct kernfs_open_file *of,
> > > > return nbytes;
> > > > }
> > > >
> > > > +static ssize_t memory_reclaim(struct kernfs_open_file *of, char *buf,
> > > > + size_t nbytes, loff_t off)
> > > > +{
> > > > + struct mem_cgroup *memcg = mem_cgroup_from_css(of_css(of));
> > > > + unsigned int nr_retries = MAX_RECLAIM_RETRIES;
> > > > + unsigned long nr_to_reclaim, nr_reclaimed = 0;
> > > > + int err;
> > > > +
> > > > + buf = strstrip(buf);
> > > > + err = page_counter_memparse(buf, "", &nr_to_reclaim);
> > > > + if (err)
> > > > + return err;
> > > > +
> > > > + while (nr_reclaimed < nr_to_reclaim) {
> > > > + unsigned long reclaimed;
> > > > +
> > > > + if (signal_pending(current))
> > > > + break;
> > > > +
> > > > + reclaimed = try_to_free_mem_cgroup_pages(memcg,
> > > > + nr_to_reclaim - nr_reclaimed,
> > > > + GFP_KERNEL, true);
> > > > +
> > > > + if (!reclaimed && !nr_retries--)
> > > > + break;
> > > > +
> > > > + nr_reclaimed += reclaimed;
> > > > + }
> > >
> > > Is there any way in which this can be provoked into triggering the
> > > softlockup detector?
> >
> > memory.reclaim is similar to memory.high w.r.t. reclaiming memory,
> > except that memory.reclaim is stateless, while the kernel remembers
> > the state set by memory.high. So memory.reclaim should not bring in
> > any new risks of triggering soft lockup, if any.
Memory reclaim already has cond_resched even if there is nothing
reclaimable. See shrink_node_memcgs
> > > Is it optimal to do the MAX_RECLAIM_RETRIES loop in the kernel?
> > > Would additional flexibility be gained by letting userspace handle
> > > retrying?
> >
> > I agree it is better to retry from the userspace.
>
> Thanks Andrew and Wei for looking at this. IIUC the
> MAX_RECLAIM_RETRIES loop was modeled after the loop in memory.high as
> well. Is there a reason why it should be different here?
No, I would go with the same approach other interfaces use. I am not a
great fan of MAX_RECLAIM_RETRIES - especially when we have a bail out on
signals - but if we are to change this then let's do it consisently.
--
Michal Hocko
SUSE Labs
Powered by blists - more mailing lists