[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJuCfpFL_7Zk4Nk5E_kCSnsCsXgmWGW9R3AnXW-T5EH7URUkRg@mail.gmail.com>
Date: Fri, 6 Aug 2021 09:07:28 -0700
From: Suren Baghdasaryan <surenb@...gle.com>
To: Michal Hocko <mhocko@...e.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>,
David Rientjes <rientjes@...gle.com>,
Matthew Wilcox <willy@...radead.org>,
Johannes Weiner <hannes@...xchg.org>,
Roman Gushchin <guro@...com>, Rik van Riel <riel@...riel.com>,
Minchan Kim <minchan@...nel.org>,
Christian Brauner <christian@...uner.io>,
Christoph Hellwig <hch@...radead.org>,
Oleg Nesterov <oleg@...hat.com>,
David Hildenbrand <david@...hat.com>,
Jann Horn <jannh@...gle.com>,
Shakeel Butt <shakeelb@...gle.com>,
Andy Lutomirski <luto@...nel.org>,
Christian Brauner <christian.brauner@...ntu.com>,
Florian Weimer <fweimer@...hat.com>,
Jan Engelhardt <jengelh@...i.de>,
Tim Murray <timmurray@...gle.com>,
Linux API <linux-api@...r.kernel.org>,
linux-mm <linux-mm@...ck.org>,
LKML <linux-kernel@...r.kernel.org>,
kernel-team <kernel-team@...roid.com>
Subject: Re: [PATCH v7 1/2] mm: introduce process_mrelease system call
On Thu, Aug 5, 2021 at 11:40 PM Michal Hocko <mhocko@...e.com> wrote:
>
> On Thu 05-08-21 10:08:58, Suren Baghdasaryan wrote:
> [...]
> > + /*
> > + * If the task is dying and in the process of releasing its memory
> > + * then get its mm.
> > + */
> > + p = find_lock_task_mm(task);
> > + if (!p) {
> > + ret = -ESRCH;
> > + goto put_pid;
> > + }
> > + if (task != p) {
> > + get_task_struct(p);
> > + put_task_struct(task);
> > + task = p;
> > + }
>
> Why do you need to take a reference to the p here? You are under
> task_lock so this will not go away and you only need p to get your mm.
True.
>
> > +
> > + /* If the work has been done already, just exit with success */
> > + if (test_bit(MMF_OOM_SKIP, &task->mm->flags))
> > + goto put_task;
>
> You want to release the task_lock
Missed it again :(
>
> > +
> > + if (task_will_free_mem(task) && (task->flags & PF_KTHREAD) == 0) {
>
> you want task_will_free_mem(p) and what is the point of the PF_KTHREAD
> check?
Yeah, looks like task_will_free_mem() covers that case already.
>
> > + mm = task->mm;
> > + mmget(mm);
>
> All you need is to make sure mm will not get released under your feet
> once task_lock is released so mmgrab is the right thing to do here. The
> address space can be torn down in parallel and that is OK and desirable.
>
> I think you really want something like this:
>
> if (flags)
> return -EINVAL;
>
> pid = pidfd_get_pid(fd, &f_flags);
> if (IS_ERR(pid))
> return PTR_ERR(pid);
> task = get_pid_task(pid, PIDTYPE_PID);
> if (!task) {
> ret = -ESRCH;
> goto put_pid;
> }
>
> /*
> * Make sure to chose a thread which still has a reference to mm
> * during the group exit
> */
> p = find_lock_task_mm(task);
> if (!p) {
> ret = -ESRCH;
> goto put_task;
> }
>
> mm = task->mm;
> mmgrab(mm);
> reap = true;
> /* If the work has been done already, just exit with success */
> if (test_bit(MMF_OOM_SKIP, &mm->flags)) {
> reap = false;
> } else if (!task_will_free_mem(p)) {
> reap = false;
> ret = -EINVAL;
> }
> task_unlock(p);
>
> if (!reap)
> goto dropmm;;
>
> /* Do the work*/
>
>
> dropmm:
> mmdrop(mm);
> put_task:
> put_task(task);
> put_pid:
> put_pid(pid);
>
> return ret;
>
This is indeed simpler to follow. I'll adopt your version. Thanks!
> --
> Michal Hocko
> SUSE Labs
Powered by blists - more mailing lists