linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Eric B Munson <emunson@akamai.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Vlastimil Babka <vbabka@suse.cz>,
	"Kirill A. Shutemov" <kirill@shutemov.name>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 1/6] mm: mlock: Refactor mlock, munlock, and munlockall code
Date: Wed, 12 Aug 2015 11:42:41 +0200	[thread overview]
Message-ID: <20150812094241.GC14940@dhcp22.suse.cz> (raw)
In-Reply-To: <1439097776-27695-2-git-send-email-emunson@akamai.com>

On Sun 09-08-15 01:22:51, Eric B Munson wrote:
> Extending the mlock system call is very difficult because it currently
> does not take a flags argument.  A later patch in this set will extend
> mlock to support a middle ground between pages that are locked and
> faulted in immediately and unlocked pages.  To pave the way for the new
> system call, the code needs some reorganization so that all the actual
> entry point handles is checking input and translating to VMA flags.

OK, I find the reorganized code more readable.

> Signed-off-by: Eric B Munson <emunson@akamai.com>
> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Acked-by: Vlastimil Babka <vbabka@suse.cz>
> Cc: Michal Hocko <mhocko@suse.cz>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: "Kirill A. Shutemov" <kirill@shutemov.name>
> Cc: linux-mm@kvack.org
> Cc: linux-kernel@vger.kernel.org

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  mm/mlock.c | 30 +++++++++++++++++-------------
>  1 file changed, 17 insertions(+), 13 deletions(-)
> 
> diff --git a/mm/mlock.c b/mm/mlock.c
> index 6fd2cf1..5692ee5 100644
> --- a/mm/mlock.c
> +++ b/mm/mlock.c
> @@ -553,7 +553,8 @@ out:
>  	return ret;
>  }
>  
> -static int do_mlock(unsigned long start, size_t len, int on)
> +static int apply_vma_lock_flags(unsigned long start, size_t len,
> +				vm_flags_t flags)
>  {
>  	unsigned long nstart, end, tmp;
>  	struct vm_area_struct * vma, * prev;
> @@ -575,14 +576,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
>  		prev = vma;
>  
>  	for (nstart = start ; ; ) {
> -		vm_flags_t newflags;
> -
> -		/* Here we know that  vma->vm_start <= nstart < vma->vm_end. */
> +		vm_flags_t newflags = vma->vm_flags & ~VM_LOCKED;
>  
> -		newflags = vma->vm_flags & ~VM_LOCKED;
> -		if (on)
> -			newflags |= VM_LOCKED;
> +		newflags |= flags;
>  
> +		/* Here we know that  vma->vm_start <= nstart < vma->vm_end. */
>  		tmp = vma->vm_end;
>  		if (tmp > end)
>  			tmp = end;
> @@ -604,7 +602,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
>  	return error;
>  }
>  
> -SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
> +static int do_mlock(unsigned long start, size_t len, vm_flags_t flags)
>  {
>  	unsigned long locked;
>  	unsigned long lock_limit;
> @@ -628,7 +626,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
>  
>  	/* check against resource limits */
>  	if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
> -		error = do_mlock(start, len, 1);
> +		error = apply_vma_lock_flags(start, len, flags);
>  
>  	up_write(&current->mm->mmap_sem);
>  	if (error)
> @@ -640,6 +638,11 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
>  	return 0;
>  }
>  
> +SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
> +{
> +	return do_mlock(start, len, VM_LOCKED);
> +}
> +
>  SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
>  {
>  	int ret;
> @@ -648,13 +651,13 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
>  	start &= PAGE_MASK;
>  
>  	down_write(&current->mm->mmap_sem);
> -	ret = do_mlock(start, len, 0);
> +	ret = apply_vma_lock_flags(start, len, 0);
>  	up_write(&current->mm->mmap_sem);
>  
>  	return ret;
>  }
>  
> -static int do_mlockall(int flags)
> +static int apply_mlockall_flags(int flags)
>  {
>  	struct vm_area_struct * vma, * prev = NULL;
>  
> @@ -662,6 +665,7 @@ static int do_mlockall(int flags)
>  		current->mm->def_flags |= VM_LOCKED;
>  	else
>  		current->mm->def_flags &= ~VM_LOCKED;
> +
>  	if (flags == MCL_FUTURE)
>  		goto out;
>  
> @@ -703,7 +707,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
>  
>  	if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
>  	    capable(CAP_IPC_LOCK))
> -		ret = do_mlockall(flags);
> +		ret = apply_mlockall_flags(flags);
>  	up_write(&current->mm->mmap_sem);
>  	if (!ret && (flags & MCL_CURRENT))
>  		mm_populate(0, TASK_SIZE);
> @@ -716,7 +720,7 @@ SYSCALL_DEFINE0(munlockall)
>  	int ret;
>  
>  	down_write(&current->mm->mmap_sem);
> -	ret = do_mlockall(0);
> +	ret = apply_mlockall_flags(0);
>  	up_write(&current->mm->mmap_sem);
>  	return ret;
>  }
> -- 
> 1.9.1

-- 
Michal Hocko
SUSE Labs

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2015-08-12  9:42 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-09  5:22 [PATCH v7 0/6] Allow user to request memory to be locked on page fault Eric B Munson
2015-08-09  5:22 ` [PATCH v7 1/6] mm: mlock: Refactor mlock, munlock, and munlockall code Eric B Munson
2015-08-12  9:42   ` Michal Hocko [this message]
2015-08-09  5:22 ` [PATCH v7 2/6] mm: mlock: Add new mlock system call Eric B Munson
2015-08-12  9:45   ` Michal Hocko
2015-08-09  5:22 ` [PATCH v7 3/6] mm: Introduce VM_LOCKONFAULT Eric B Munson
2015-08-12 11:59   ` Michal Hocko
2015-08-19 21:33     ` Eric B Munson
2015-08-20  7:53       ` Vlastimil Babka
2015-08-20  7:56       ` Michal Hocko
2015-08-20 17:03         ` Eric B Munson
2015-08-21  7:25           ` Michal Hocko
2015-08-21 18:31             ` Eric B Munson
2015-08-24 10:17               ` Konstantin Khlebnikov
2015-08-24 13:30                 ` Vlastimil Babka
2015-08-24 13:50                   ` Konstantin Khlebnikov
2015-08-24 14:27                     ` Vlastimil Babka
2015-08-24 15:09                       ` Eric B Munson
2015-08-24 15:46                         ` Konstantin Khlebnikov
2015-08-24 15:55                           ` Eric B Munson
2015-08-24 16:22                             ` Konstantin Khlebnikov
2015-08-24 17:00                               ` Eric B Munson
2015-08-24 18:53                                 ` Konstantin Khlebnikov
2015-08-24 20:26                                   ` Eric B Munson
2015-08-25 13:41               ` Michal Hocko
2015-08-25 13:55                 ` Vlastimil Babka
2015-08-25 14:29                   ` Michal Hocko
2015-08-25 13:58                 ` Konstantin Khlebnikov
2015-08-25 14:29                 ` Eric B Munson
2015-08-25 18:58                   ` Michal Hocko
2015-08-25 19:03                     ` Eric B Munson
2015-08-26  7:20                       ` Michal Hocko
2015-08-26 15:35                         ` Vlastimil Babka
2015-08-09  5:22 ` [PATCH v7 4/6] mm: mlock: Add mlock flags to enable VM_LOCKONFAULT usage Eric B Munson
2015-08-09  5:22 ` [PATCH v7 5/6] selftests: vm: Add tests for lock on fault Eric B Munson
2015-08-09  5:22 ` [PATCH v7 6/6] mips: Add entry for new mlock2 syscall 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=20150812094241.GC14940@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=emunson@akamai.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox