Re: [RFC 4/7] mm: factor out madvise's core functionality
Thread information
[Search the linux-kernel archive]
[RFC 0/7] introduce memory hinting API for external process Minchan Kim ` [RFC 1/7] mm: introduce MADV_COOL Minchan Kim ` Michal Hocko ` Michal Hocko ` Suren Baghdasaryan ` Minchan Kim ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` [RFC 2/7] mm: change PAGEREF_RECLAIM_CLEAN with PAGE_REFRECLAIM Minchan Kim ` Johannes Weiner ` Minchan Kim ` [RFC 3/7] mm: introduce MADV_COLD Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Minchan Kim ` [RFC 4/7] mm: factor out madvise's core functionality Minchan Kim ` Oleksandr Natalenko ` Minchan Kim ` Oleksandr Natalenko [this message] ` Michal Hocko ` Oleksandr Natalenko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` [RFC 5/7] mm: introduce external memory hinting API Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Christian Brauner ` Minchan Kim ` Christian Brauner ` Oleg Nesterov ` Minchan Kim ` Oleg Nesterov ` Minchan Kim ` Michal Hocko ` Minchan Kim ` [RFC 6/7] mm: extend process_madvise syscall to support vector arrary Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Daniel Colascione ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Daniel Colascione ` Michal Hocko ` Minchan Kim ` [RFC 7/7] mm: madvise support MADV_ANONYMOUS_FILTER and MADV_FILE_FILTER Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Daniel Colascione ` Minchan Kim ` Michal Hocko ` Daniel Colascione ` Michal Hocko ` Daniel Colascione ` Michal Hocko ` Daniel Colascione ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Minchan Kim ` Michal Hocko ` Daniel Colascione ` Michal Hocko ` Daniel Colascione ` Michal Hocko ` Minchan Kim ` Minchan Kim ` Daniel Colascione ` Michal Hocko ` Minchan Kim ` Daniel Colascione ` Johannes Weiner ` Minchan Kim ` Minchan Kim ` [RFC 0/7] introduce memory hinting API for external process Anshuman Khandual ` Tim Murray ` Anshuman Khandual ` Minchan Kim ` Michal Hocko ` Anshuman Khandual ` Shakeel Butt ` Brian Geffon ` Michal Hocko ` Oleksandr Natalenko ` Minchan Kim ` Johannes Weiner ` Minchan Kim ` Michal Hocko ` Matthew Wilcox ` Minchan Kim ` Michal Hocko ` Christian Brauner ` Minchan Kim ` Christian Brauner ` Christian Brauner ` Daniel Colascione ` Christian Brauner ` Daniel Colascione ` Christian Brauner ` Daniel Colascione ` Christian Brauner ` Daniel Colascione ` Christian Brauner ` Daniel Colascione ` Minchan Kim ` Minchan Kim ` Minchan Kim ` Christian Brauner ` Oleksandr Natalenko ` Shakeel Butt
From: | Oleksandr Natalenko <oleksandr-AT-redhat.com> | |
To: | Minchan Kim <minchan-AT-kernel.org> | |
Subject: | Re: [RFC 4/7] mm: factor out madvise's core functionality | |
Date: | Tue, 21 May 2019 08:36:28 +0200 | |
Message-ID: | <20190521063628.x2npirvs75jxjilx@butterfly.localdomain> | |
Cc: | Andrew Morton <akpm-AT-linux-foundation.org>, LKML <linux-kernel-AT-vger.kernel.org>, linux-mm <linux-mm-AT-kvack.org>, Michal Hocko <mhocko-AT-suse.com>, Johannes Weiner <hannes-AT-cmpxchg.org>, Tim Murray <timmurray-AT-google.com>, Joel Fernandes <joel-AT-joelfernandes.org>, Suren Baghdasaryan <surenb-AT-google.com>, Daniel Colascione <dancol-AT-google.com>, Shakeel Butt <shakeelb-AT-google.com>, Sonny Rao <sonnyrao-AT-google.com>, Brian Geffon <bgeffon-AT-google.com> |
Hi. On Tue, May 21, 2019 at 10:26:49AM +0900, Minchan Kim wrote: > On Mon, May 20, 2019 at 04:26:33PM +0200, Oleksandr Natalenko wrote: > > Hi. > > > > On Mon, May 20, 2019 at 12:52:51PM +0900, Minchan Kim wrote: > > > This patch factor out madvise's core functionality so that upcoming > > > patch can reuse it without duplication. > > > > > > It shouldn't change any behavior. > > > > > > Signed-off-by: Minchan Kim <minchan@kernel.org> > > > --- > > > mm/madvise.c | 168 +++++++++++++++++++++++++++------------------------ > > > 1 file changed, 89 insertions(+), 79 deletions(-) > > > > > > diff --git a/mm/madvise.c b/mm/madvise.c > > > index 9a6698b56845..119e82e1f065 100644 > > > --- a/mm/madvise.c > > > +++ b/mm/madvise.c > > > @@ -742,7 +742,8 @@ static long madvise_dontneed_single_vma(struct vm_area_struct *vma, > > > return 0; > > > } > > > > > > -static long madvise_dontneed_free(struct vm_area_struct *vma, > > > +static long madvise_dontneed_free(struct task_struct *tsk, > > > + struct vm_area_struct *vma, > > > struct vm_area_struct **prev, > > > unsigned long start, unsigned long end, > > > int behavior) > > > @@ -754,8 +755,8 @@ static long madvise_dontneed_free(struct vm_area_struct *vma, > > > if (!userfaultfd_remove(vma, start, end)) { > > > *prev = NULL; /* mmap_sem has been dropped, prev is stale */ > > > > > > - down_read(¤t->mm->mmap_sem); > > > - vma = find_vma(current->mm, start); > > > + down_read(&tsk->mm->mmap_sem); > > > + vma = find_vma(tsk->mm, start); > > > if (!vma) > > > return -ENOMEM; > > > if (start < vma->vm_start) { > > > @@ -802,7 +803,8 @@ static long madvise_dontneed_free(struct vm_area_struct *vma, > > > * Application wants to free up the pages and associated backing store. > > > * This is effectively punching a hole into the middle of a file. > > > */ > > > -static long madvise_remove(struct vm_area_struct *vma, > > > +static long madvise_remove(struct task_struct *tsk, > > > + struct vm_area_struct *vma, > > > struct vm_area_struct **prev, > > > unsigned long start, unsigned long end) > > > { > > > @@ -836,13 +838,13 @@ static long madvise_remove(struct vm_area_struct *vma, > > > get_file(f); > > > if (userfaultfd_remove(vma, start, end)) { > > > /* mmap_sem was not released by userfaultfd_remove() */ > > > - up_read(¤t->mm->mmap_sem); > > > + up_read(&tsk->mm->mmap_sem); > > > } > > > error = vfs_fallocate(f, > > > FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, > > > offset, end - start); > > > fput(f); > > > - down_read(¤t->mm->mmap_sem); > > > + down_read(&tsk->mm->mmap_sem); > > > return error; > > > } > > > > > > @@ -916,12 +918,13 @@ static int madvise_inject_error(int behavior, > > > #endif > > > > What about madvise_inject_error() and get_user_pages_fast() in it > > please? > > Good point. Maybe, there more places where assume context is "current" so > I'm thinking to limit hints we could allow from external process. > It would be better for maintainance point of view in that we could know > the workload/usecases when someone ask new advises from external process > without making every hints works both contexts. Well, for madvise_inject_error() we still have a remote variant of get_user_pages(), and that should work, no? Regarding restricting the hints, I'm definitely interested in having remote MADV_MERGEABLE/MADV_UNMERGEABLE. But, OTOH, doing it via remote madvise() introduces another issue with traversing remote VMAs reliably. IIUC, one can do this via userspace by parsing [s]maps file only, which is not very consistent, and once some range is parsed, and then it is immediately gone, a wrong hint will be sent. Isn't this a problem we should worry about? > > Thanks. -- Best regards, Oleksandr Natalenko (post-factum) Senior Software Maintenance Engineer