Commit ed205520 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Use address hint in mmap for search

From: Andi Kleen <ak@suse.de>

When the user gave an address hint in mmap use it as starting point for the
search for !MAP_FIXED.

Currently it is only checked directly and when already used the free area
cache is used as starting point.  With this change you can use mmap(4096,
....) to e.g.  get the lowest free address in your address space, which is
sometimes useful.  For example on x86-64 glibc wants to preferably allocate
thread local data in the first 4GB but use higher addresses when this is
not possible.

This can be a bit more costly in CPU time because it may have to skip over
more VMAs, but gives better semantics for most cases.  Most programs pass
NULL as hint anyways so it won't make any difference for them.

I did it for the generic mmap and for x86-64 for now.  Also minor white
space fixes for x86-64.
parent c7f6fcf5
...@@ -105,13 +105,13 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, ...@@ -105,13 +105,13 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
return -ENOMEM; return -ENOMEM;
if (addr) { if (addr) {
addr = PAGE_ALIGN(addr); addr = PAGE_ALIGN(addr);
vma = find_vma(mm, addr); vma = find_vma(mm, addr);
if (end - len >= addr && if (end - len >= addr &&
(!vma || addr + len <= vma->vm_start)) (!vma || addr + len <= vma->vm_start))
return addr; return addr;
} } else
addr = mm->free_area_cache; addr = mm->free_area_cache;
if (addr < begin) if (addr < begin)
addr = begin; addr = begin;
start_addr = addr; start_addr = addr;
......
...@@ -743,8 +743,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, ...@@ -743,8 +743,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
if (TASK_SIZE - len >= addr && if (TASK_SIZE - len >= addr &&
(!vma || addr + len <= vma->vm_start)) (!vma || addr + len <= vma->vm_start))
return addr; return addr;
} } else
start_addr = addr = mm->free_area_cache; addr = mm->free_area_cache;
start_addr = addr;
full_search: full_search:
for (vma = find_vma(mm, addr); ; vma = vma->vm_next) { for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment