From: Davide Libenzi <davidel@xmailserver.org>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [patch 2/3] MAP_NOZERO - implement sys_brk2()
Date: Tue, 26 Jun 2007 19:44:18 -0700 [thread overview]
Message-ID: <send-serie.davidel@xmailserver.org.29496.1182912260.2> (raw)
The following patch implements the sys_brk2() syscall, that nothing is
other than a sys_brk() with an extra "flags" parameter. This can be used
to pass the new MAP_NOZERO bit, to ask the kernel to hand over non-zero
pages if possible.
Signed-off-by: Davide Libenzi <davidel@xmailserver.org>
- Davide
---
include/linux/mm.h | 3 ++-
include/linux/syscalls.h | 1 +
mm/mmap.c | 22 ++++++++++++++++++----
3 files changed, 21 insertions(+), 5 deletions(-)
Index: linux-2.6.mod/include/linux/mm.h
===================================================================
--- linux-2.6.mod.orig/include/linux/mm.h 2007-06-25 19:27:42.000000000 -0700
+++ linux-2.6.mod/include/linux/mm.h 2007-06-26 18:08:28.000000000 -0700
@@ -1099,7 +1099,8 @@
}
extern int do_munmap(struct mm_struct *, unsigned long, size_t);
-
+extern unsigned long do_brk_flags(unsigned long addr, unsigned long len,
+ unsigned long vmflags);
extern unsigned long do_brk(unsigned long, unsigned long);
/* filemap.c */
Index: linux-2.6.mod/include/linux/syscalls.h
===================================================================
--- linux-2.6.mod.orig/include/linux/syscalls.h 2007-06-25 19:14:49.000000000 -0700
+++ linux-2.6.mod/include/linux/syscalls.h 2007-06-26 18:08:28.000000000 -0700
@@ -263,6 +263,7 @@
asmlinkage long sys_fremovexattr(int fd, char __user *name);
asmlinkage unsigned long sys_brk(unsigned long brk);
+asmlinkage unsigned long sys_brk2(unsigned long brk, unsigned long flags);
asmlinkage long sys_mprotect(unsigned long start, size_t len,
unsigned long prot);
asmlinkage unsigned long sys_mremap(unsigned long addr,
Index: linux-2.6.mod/mm/mmap.c
===================================================================
--- linux-2.6.mod.orig/mm/mmap.c 2007-06-25 19:14:49.000000000 -0700
+++ linux-2.6.mod/mm/mmap.c 2007-06-26 18:08:28.000000000 -0700
@@ -35,6 +35,8 @@
#define arch_mmap_check(addr, len, flags) (0)
#endif
+#define BRK_ALLOWED_FLAGS (VM_NOZERO)
+
static void unmap_region(struct mm_struct *mm,
struct vm_area_struct *vma, struct vm_area_struct *prev,
unsigned long start, unsigned long end);
@@ -234,7 +236,7 @@
return next;
}
-asmlinkage unsigned long sys_brk(unsigned long brk)
+asmlinkage unsigned long sys_brk2(unsigned long brk, unsigned long flags)
{
unsigned long rlim, retval;
unsigned long newbrk, oldbrk;
@@ -271,8 +273,10 @@
if (find_vma_intersection(mm, oldbrk, newbrk+PAGE_SIZE))
goto out;
+ flags = BRK_ALLOWED_FLAGS & calc_vm_flag_bits(flags);
+
/* Ok, looks good - let it rip. */
- if (do_brk(oldbrk, newbrk-oldbrk) != oldbrk)
+ if (do_brk_flags(oldbrk, newbrk-oldbrk, flags) != oldbrk)
goto out;
set_brk:
mm->brk = brk;
@@ -282,6 +286,11 @@
return retval;
}
+asmlinkage unsigned long sys_brk(unsigned long brk)
+{
+ return sys_brk2(brk, 0);
+}
+
#ifdef DEBUG_MM_RB
static int browse_rb(struct rb_root *root)
{
@@ -1863,7 +1872,8 @@
* anonymous maps. eventually we may be able to do some
* brk-specific accounting here.
*/
-unsigned long do_brk(unsigned long addr, unsigned long len)
+unsigned long do_brk_flags(unsigned long addr, unsigned long len,
+ unsigned long vmflags)
{
struct mm_struct * mm = current->mm;
struct vm_area_struct * vma, * prev;
@@ -1882,7 +1892,7 @@
if (is_hugepage_only_range(mm, addr, len))
return -EINVAL;
- flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
+ flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags | vmflags;
error = arch_mmap_check(addr, len, flags);
if (error)
@@ -1959,6 +1969,10 @@
return addr;
}
+unsigned long do_brk(unsigned long addr, unsigned long len)
+{
+ return do_brk_flags(addr, len, 0);
+}
EXPORT_SYMBOL(do_brk);
/* Release all mmaps. */
next reply other threads:[~2007-06-27 2:45 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-27 2:44 Davide Libenzi [this message]
2007-06-27 3:07 ` [patch 2/3] MAP_NOZERO - implement sys_brk2() Rik van Riel
2007-06-27 3:33 ` Davide Libenzi
2007-06-27 3:45 ` Ulrich Drepper
2007-06-27 4:11 ` Rik van Riel
2007-06-27 5:04 ` Ulrich Drepper
2007-06-27 3:48 ` Ulrich Drepper
2007-06-27 3:55 ` Davide Libenzi
2007-06-27 5:02 ` Ulrich Drepper
2007-06-27 12:32 ` Hugh Dickins
2007-06-27 15:59 ` Davide Libenzi
2007-06-27 17:01 ` Ulrich Drepper
2007-06-27 17:43 ` Hugh Dickins
2007-06-27 18:13 ` Davide Libenzi
2007-06-27 18:32 ` Hugh Dickins
2007-06-27 18:45 ` Davide Libenzi
2007-06-27 22:11 ` Nicholas Miell
2007-06-28 0:17 ` Davide Libenzi
2007-06-28 2:58 ` Davide Libenzi
2007-06-30 7:52 ` Andrew Morton
2007-06-27 18:52 ` Ulrich Drepper
2007-06-27 19:32 ` Hugh Dickins
2007-06-27 19:00 ` Rik van Riel
2007-06-27 19:22 ` Davide Libenzi
2007-06-27 16:05 ` Davide Libenzi
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=send-serie.davidel@xmailserver.org.29496.1182912260.2 \
--to=davidel@xmailserver.org \
--cc=linux-kernel@vger.kernel.org \
/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).