From: Eric B Munson <emunson@akamai.com>
To: "Kirill A. Shutemov" <kirill@shutemov.name>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Jonathan Corbet <corbet@lwn.net>,
Vlastimil Babka <vbabka@suse.cz>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH V4 3/6] mm: gup: Add mm_lock_present()
Date: Wed, 22 Jul 2015 10:11:33 -0400 [thread overview]
Message-ID: <20150722141133.GC2859@akamai.com> (raw)
In-Reply-To: <20150722111317.GB8630@node.dhcp.inet.fi>
[-- Attachment #1: Type: text/plain, Size: 4224 bytes --]
On Wed, 22 Jul 2015, Kirill A. Shutemov wrote:
> On Tue, Jul 21, 2015 at 03:59:38PM -0400, Eric B Munson wrote:
> > The upcoming mlock(MLOCK_ONFAULT) implementation will need a way to
> > request that all present pages in a range are locked without faulting in
> > pages that are not present. This logic is very close to what the
> > __mm_populate() call handles without faulting pages so the patch pulls
> > out the pieces that can be shared and adds mm_lock_present() to gup.c.
> > The following patch will call it from do_mlock() when MLOCK_ONFAULT is
> > specified.
> >
> > Signed-off-by: Eric B Munson <emunson@akamai.com>
> > Cc: Jonathan Corbet <corbet@lwn.net>
> > Cc: Vlastimil Babka <vbabka@suse.cz>
> > Cc: linux-mm@kvack.org
> > Cc: linux-kernel@vger.kernel.org
> > ---
> > mm/gup.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
> > 1 file changed, 157 insertions(+), 15 deletions(-)
>
> I don't like that you've copy-pasted a lot of code. I think it can be
> solved with new foll flags.
>
> Totally untested patch below split out mlock part of FOLL_POPULATE into
> new FOLL_MLOCK flag. FOLL_POPULATE | FOLL_MLOCK will do what currently
> FOLL_POPULATE does. The new MLOCK_ONFAULT can use just FOLL_MLOCK. It will
> not trigger fault in.
I originally tried to do this by adding a check for VM_LOCKONFAULT in
__get_user_pages() before the call to faultin_page() which would goto
next_page if LOCKONFAULT was specified. With the early out in
__get_user_pages(), all of the tests using lock on fault failed to lock
pages. I will try with a new FOLL flag and see if that can work out.
>
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index c3a2b37365f6..c3834cddfcc7 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2002,6 +2002,7 @@ static inline struct page *follow_page(struct vm_area_struct *vma,
> #define FOLL_NUMA 0x200 /* force NUMA hinting page fault */
> #define FOLL_MIGRATION 0x400 /* wait for page to replace migration entry */
> #define FOLL_TRIED 0x800 /* a retry, previous pass started an IO */
> +#define FOLL_MLOCK 0x1000 /* mlock the page if the VMA is VM_LOCKED */
>
> typedef int (*pte_fn_t)(pte_t *pte, pgtable_t token, unsigned long addr,
> void *data);
> diff --git a/mm/gup.c b/mm/gup.c
> index a798293fc648..4c7ff23947b9 100644
> --- a/mm/gup.c
> +++ b/mm/gup.c
> @@ -129,7 +129,7 @@ retry:
> */
> mark_page_accessed(page);
> }
> - if ((flags & FOLL_POPULATE) && (vma->vm_flags & VM_LOCKED)) {
> + if ((flags & FOLL_MLOCK) && (vma->vm_flags & VM_LOCKED)) {
> /*
> * The preliminary mapping check is mainly to avoid the
> * pointless overhead of lock_page on the ZERO_PAGE
> @@ -299,6 +299,9 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
> unsigned int fault_flags = 0;
> int ret;
>
> + /* mlock present pages, but not fault in new one */
> + if ((*flags & (FOLL_POPULATE | FOLL_MLOCK)) == FOLL_MLOCK)
> + return -ENOENT;
> /* For mm_populate(), just skip the stack guard page. */
> if ((*flags & FOLL_POPULATE) &&
> (stack_guard_page_start(vma, address) ||
> @@ -890,7 +893,7 @@ long populate_vma_page_range(struct vm_area_struct *vma,
> VM_BUG_ON_VMA(end > vma->vm_end, vma);
> VM_BUG_ON_MM(!rwsem_is_locked(&mm->mmap_sem), mm);
>
> - gup_flags = FOLL_TOUCH | FOLL_POPULATE;
> + gup_flags = FOLL_TOUCH | FOLL_POPULATE | FOLL_MLOCK;
> /*
> * We want to touch writable mappings with a write fault in order
> * to break COW, except for shared mappings because these don't COW
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 8f9a334a6c66..9eeb3bd304fc 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -1306,7 +1306,7 @@ struct page *follow_trans_huge_pmd(struct vm_area_struct *vma,
> pmd, _pmd, 1))
> update_mmu_cache_pmd(vma, addr, pmd);
> }
> - if ((flags & FOLL_POPULATE) && (vma->vm_flags & VM_LOCKED)) {
> + if ((flags & FOLL_MLOCK) && (vma->vm_flags & VM_LOCKED)) {
> if (page->mapping && trylock_page(page)) {
> lru_add_drain();
> if (page->mapping)
>
> --
> Kirill A. Shutemov
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
next prev parent reply other threads:[~2015-07-22 14:11 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-21 19:59 [PATCH V4 0/6] Allow user to request memory to be locked on page fault Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-21 19:59 ` [PATCH V4 1/6] mm: mlock: Refactor mlock, munlock, and munlockall code Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-22 10:42 ` Kirill A. Shutemov
2015-07-22 10:42 ` Kirill A. Shutemov
2015-07-22 14:04 ` Eric B Munson
2015-07-21 19:59 ` [PATCH V4 2/6] mm: mlock: Add new mlock, munlock, and munlockall system calls Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-21 20:44 ` Andrew Morton
2015-07-21 20:44 ` Andrew Morton
2015-07-21 20:44 ` Andrew Morton
2015-07-21 20:44 ` Andrew Morton
2015-07-22 1:25 ` Michael Ellerman
2015-07-22 1:25 ` Michael Ellerman
2015-07-22 1:25 ` Michael Ellerman
2015-07-22 1:25 ` Michael Ellerman
2015-07-22 14:15 ` Eric B Munson
2015-07-22 14:15 ` Eric B Munson
2015-07-22 14:15 ` Eric B Munson
2015-07-23 6:58 ` Ralf Baechle
2015-07-23 6:58 ` Ralf Baechle
2015-07-23 6:58 ` Ralf Baechle
2015-07-23 6:58 ` Ralf Baechle
2015-07-23 6:58 ` Ralf Baechle
2015-07-23 6:58 ` Ralf Baechle
2015-07-24 14:39 ` Eric B Munson
2015-07-24 14:39 ` Eric B Munson
2015-07-24 14:39 ` Eric B Munson
2015-07-24 14:39 ` Eric B Munson
[not found] ` <20150724143936.GE9203-JqFfY2XvxFXQT0dZR+AlfA@public.gmane.org>
2015-07-24 15:46 ` Guenter Roeck
2015-07-24 15:46 ` Guenter Roeck
2015-07-24 15:46 ` Guenter Roeck
2015-07-24 15:46 ` Guenter Roeck
2015-07-24 15:46 ` Guenter Roeck
2015-07-24 15:53 ` Eric B Munson
2015-07-24 15:53 ` Eric B Munson
2015-07-24 15:53 ` Eric B Munson
2015-07-24 15:53 ` Eric B Munson
2015-07-22 9:16 ` Vlastimil Babka
2015-07-22 9:16 ` Vlastimil Babka
2015-07-22 9:16 ` Vlastimil Babka
2015-07-22 9:16 ` Vlastimil Babka
2015-07-22 9:16 ` Vlastimil Babka
2015-07-22 14:05 ` Eric B Munson
2015-07-22 14:05 ` Eric B Munson
2015-07-22 14:05 ` Eric B Munson
2015-07-22 14:05 ` Eric B Munson
2015-07-22 14:05 ` Eric B Munson
2015-07-21 19:59 ` [PATCH V4 3/6] mm: gup: Add mm_lock_present() Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-22 11:13 ` Kirill A. Shutemov
2015-07-22 11:13 ` Kirill A. Shutemov
2015-07-22 14:11 ` Eric B Munson [this message]
2015-07-21 19:59 ` [PATCH V4 4/6] mm: mlock: Introduce VM_LOCKONFAULT and add mlock flags to enable it Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-22 10:03 ` Vlastimil Babka
2015-07-22 10:03 ` Vlastimil Babka
2015-07-22 10:03 ` Vlastimil Babka
2015-07-22 18:43 ` Eric B Munson
2015-07-22 18:43 ` Eric B Munson
2015-07-23 10:03 ` Vlastimil Babka
2015-07-23 10:03 ` Vlastimil Babka
2015-07-23 10:03 ` Vlastimil Babka
2015-07-23 15:21 ` Eric B Munson
2015-07-23 15:21 ` Eric B Munson
2015-07-21 19:59 ` [PATCH V4 5/6] mm: mmap: Add mmap flag to request VM_LOCKONFAULT Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-21 19:59 ` Eric B Munson
2015-07-22 11:25 ` Kirill A. Shutemov
2015-07-22 11:25 ` Kirill A. Shutemov
2015-07-22 11:25 ` Kirill A. Shutemov
2015-07-22 14:32 ` Eric B Munson
2015-07-22 14:32 ` Eric B Munson
2015-07-22 15:45 ` Kirill A. Shutemov
2015-07-22 15:45 ` Kirill A. Shutemov
2015-07-22 15:45 ` Kirill A. Shutemov
2015-07-21 19:59 ` [PATCH V4 6/6] selftests: vm: Add tests for lock on fault Eric B Munson
2015-07-21 19:59 ` Eric B Munson
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=20150722141133.GC2859@akamai.com \
--to=emunson@akamai.com \
--cc=akpm@linux-foundation.org \
--cc=corbet@lwn.net \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=vbabka@suse.cz \
/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.