From: Michel Lespinasse <walken@google.com>
To: Andy Lutomirski <luto@amacapital.net>,
Ingo Molnar <mingo@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>,
Hugh Dickins <hughd@google.com>, Jorn_Engel <joern@logfs.org>,
Rik van Riel <riel@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH 6/9] mm: use mm_populate() for mremap() of VM_LOCKED vmas
Date: Thu, 20 Dec 2012 16:49:54 -0800 [thread overview]
Message-ID: <1356050997-2688-7-git-send-email-walken@google.com> (raw)
In-Reply-To: <1356050997-2688-1-git-send-email-walken@google.com>
Signed-off-by: Michel Lespinasse <walken@google.com>
---
mm/mremap.c | 25 +++++++++++++------------
1 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/mm/mremap.c b/mm/mremap.c
index 1b61c2d3307a..c5a8bf344b1f 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -208,7 +208,7 @@ unsigned long move_page_tables(struct vm_area_struct *vma,
static unsigned long move_vma(struct vm_area_struct *vma,
unsigned long old_addr, unsigned long old_len,
- unsigned long new_len, unsigned long new_addr)
+ unsigned long new_len, unsigned long new_addr, bool *locked)
{
struct mm_struct *mm = vma->vm_mm;
struct vm_area_struct *new_vma;
@@ -299,9 +299,7 @@ static unsigned long move_vma(struct vm_area_struct *vma,
if (vm_flags & VM_LOCKED) {
mm->locked_vm += new_len >> PAGE_SHIFT;
- if (new_len > old_len)
- mlock_vma_pages_range(new_vma, new_addr + old_len,
- new_addr + new_len);
+ *locked = true;
}
return new_addr;
@@ -366,9 +364,8 @@ Eagain:
return ERR_PTR(-EAGAIN);
}
-static unsigned long mremap_to(unsigned long addr,
- unsigned long old_len, unsigned long new_addr,
- unsigned long new_len)
+static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
+ unsigned long new_addr, unsigned long new_len, bool *locked)
{
struct mm_struct *mm = current->mm;
struct vm_area_struct *vma;
@@ -418,7 +415,7 @@ static unsigned long mremap_to(unsigned long addr,
if (ret & ~PAGE_MASK)
goto out1;
- ret = move_vma(vma, addr, old_len, new_len, new_addr);
+ ret = move_vma(vma, addr, old_len, new_len, new_addr, locked);
if (!(ret & ~PAGE_MASK))
goto out;
out1:
@@ -456,6 +453,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
struct vm_area_struct *vma;
unsigned long ret = -EINVAL;
unsigned long charged = 0;
+ bool locked = false;
down_write(¤t->mm->mmap_sem);
@@ -478,7 +476,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
if (flags & MREMAP_FIXED) {
if (flags & MREMAP_MAYMOVE)
- ret = mremap_to(addr, old_len, new_addr, new_len);
+ ret = mremap_to(addr, old_len, new_addr, new_len,
+ &locked);
goto out;
}
@@ -520,8 +519,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
vm_stat_account(mm, vma->vm_flags, vma->vm_file, pages);
if (vma->vm_flags & VM_LOCKED) {
mm->locked_vm += pages;
- mlock_vma_pages_range(vma, addr + old_len,
- addr + new_len);
+ locked = true;
+ new_addr = addr;
}
ret = addr;
goto out;
@@ -547,11 +546,13 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
goto out;
}
- ret = move_vma(vma, addr, old_len, new_len, new_addr);
+ ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
}
out:
if (ret & ~PAGE_MASK)
vm_unacct_memory(charged);
up_write(¤t->mm->mmap_sem);
+ if (locked && new_len > old_len)
+ mm_populate(new_addr + old_len, new_len - old_len);
return ret;
}
--
1.7.7.3
--
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>
next prev parent reply other threads:[~2012-12-21 0:50 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-21 0:49 [PATCH 0/9] Avoid populating unbounded num of ptes with mmap_sem held Michel Lespinasse
2012-12-21 0:49 ` [PATCH 1/9] mm: make mlockall preserve flags other than VM_LOCKED in def_flags Michel Lespinasse
2012-12-22 4:25 ` Rik van Riel
2012-12-21 0:49 ` [PATCH 2/9] mm: remap_file_pages() fixes Michel Lespinasse
2013-01-03 0:31 ` Rik van Riel
2012-12-21 0:49 ` [PATCH 3/9] mm: introduce mm_populate() for populating new vmas Michel Lespinasse
2013-01-03 2:14 ` Rik van Riel
2012-12-21 0:49 ` [PATCH 4/9] mm: use mm_populate() for blocking remap_file_pages() Michel Lespinasse
2013-01-03 2:25 ` Rik van Riel
2013-03-10 18:55 ` Tommi Rantala
2013-03-11 23:03 ` Andrew Morton
2013-03-12 0:24 ` Michel Lespinasse
2013-03-12 4:23 ` Hillf Danton
2013-03-12 5:01 ` Michel Lespinasse
2013-03-12 20:47 ` Andrew Morton
2012-12-21 0:49 ` [PATCH 5/9] mm: use mm_populate() when adjusting brk with MCL_FUTURE in effect Michel Lespinasse
2013-01-03 2:56 ` Rik van Riel
2012-12-21 0:49 ` Michel Lespinasse [this message]
2013-01-03 5:47 ` [PATCH 6/9] mm: use mm_populate() for mremap() of VM_LOCKED vmas Rik van Riel
2012-12-21 0:49 ` [PATCH 7/9] mm: remove flags argument to mmap_region Michel Lespinasse
2013-01-03 5:49 ` Rik van Riel
2012-12-21 0:49 ` [PATCH 8/9] mm: directly use __mlock_vma_pages_range() in find_extend_vma() Michel Lespinasse
2013-01-03 5:50 ` Rik van Riel
2012-12-21 0:49 ` [PATCH 9/9] mm: introduce VM_POPULATE flag to better deal with racy userspace programs Michel Lespinasse
2013-01-03 6:20 ` Rik van Riel
2012-12-21 10:46 ` [PATCH 0/9] Avoid populating unbounded num of ptes with mmap_sem held Michel Lespinasse
2012-12-22 15:02 ` Greg Ungerer
2013-01-23 13:37 ` Greg Ungerer
2012-12-22 0:36 ` Andy Lutomirski
2012-12-22 0:59 ` Michel Lespinasse
2012-12-22 1:09 ` Andy Lutomirski
2012-12-22 1:59 ` Michel Lespinasse
2012-12-22 2:16 ` Andy Lutomirski
2012-12-22 9:37 ` Michel Lespinasse
2012-12-22 9:45 ` [PATCH 10/9] mm: make do_mmap_pgoff return populate as a size in bytes, not as a bool Michel Lespinasse
2013-01-03 6:21 ` Rik van Riel
2013-01-03 18:54 ` Andy Lutomirski
2013-01-03 18:56 ` [PATCH 0/9] Avoid populating unbounded num of ptes with mmap_sem held Andy Lutomirski
2013-01-04 18:16 ` Andy Lutomirski
2013-01-04 22:58 ` Michel Lespinasse
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=1356050997-2688-7-git-send-email-walken@google.com \
--to=walken@google.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=joern@logfs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=riel@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).