Skip to content

Commit

Permalink
mm: search from free_area_cache for the bigger size
Browse files Browse the repository at this point in the history
If the required size is bigger than cached_hole_size it is better to
search from free_area_cache - it is easier to get a free region,
specifically for the 64 bit process whose address space is large enough

Do it just as hugetlb_get_unmapped_area_topdown() in arch/x86/mm/hugetlbpage.c

Signed-off-by: Xiao Guangrong <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Hillf Danton <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: KAMEZAWA Hiroyuki <[email protected]>
Cc: Rik van Riel <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Xiao Guangrong authored and torvalds committed Mar 22, 2012
1 parent f44d219 commit b716ad9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
34 changes: 17 additions & 17 deletions arch/x86/kernel/sys_x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
{
struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
unsigned long addr = addr0;
unsigned long addr = addr0, start_addr;

/* requested length too big for entire address space */
if (len > TASK_SIZE)
Expand Down Expand Up @@ -223,25 +223,14 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
mm->free_area_cache = mm->mmap_base;
}

try_again:
/* either no address requested or can't fit in requested address hole */
addr = mm->free_area_cache;

/* make sure it can fit in the remaining address space */
if (addr > len) {
unsigned long tmp_addr = align_addr(addr - len, filp,
ALIGN_TOPDOWN);

vma = find_vma(mm, tmp_addr);
if (!vma || tmp_addr + len <= vma->vm_start)
/* remember the address as a hint for next time */
return mm->free_area_cache = tmp_addr;
}

if (mm->mmap_base < len)
goto bottomup;
start_addr = addr = mm->free_area_cache;

addr = mm->mmap_base-len;
if (addr < len)
goto fail;

addr -= len;
do {
addr = align_addr(addr, filp, ALIGN_TOPDOWN);

Expand All @@ -263,6 +252,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
addr = vma->vm_start-len;
} while (len < vma->vm_start);

fail:
/*
* if hint left us with no space for the requested
* mapping then try again:
*/
if (start_addr != mm->mmap_base) {
mm->free_area_cache = mm->mmap_base;
mm->cached_hole_size = 0;
goto try_again;
}

bottomup:
/*
* A failed mmap() very likely causes application failure,
Expand Down
36 changes: 21 additions & 15 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,7 +1442,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
{
struct vm_area_struct *vma;
struct mm_struct *mm = current->mm;
unsigned long addr = addr0;
unsigned long addr = addr0, start_addr;

/* requested length too big for entire address space */
if (len > TASK_SIZE)
Expand All @@ -1466,22 +1466,14 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
mm->free_area_cache = mm->mmap_base;
}

try_again:
/* either no address requested or can't fit in requested address hole */
addr = mm->free_area_cache;
start_addr = addr = mm->free_area_cache;

/* make sure it can fit in the remaining address space */
if (addr > len) {
vma = find_vma(mm, addr-len);
if (!vma || addr <= vma->vm_start)
/* remember the address as a hint for next time */
return (mm->free_area_cache = addr-len);
}

if (mm->mmap_base < len)
goto bottomup;

addr = mm->mmap_base-len;
if (addr < len)
goto fail;

addr -= len;
do {
/*
* Lookup failure means no vma is above this address,
Expand All @@ -1501,7 +1493,21 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
addr = vma->vm_start-len;
} while (len < vma->vm_start);

bottomup:
fail:
/*
* if hint left us with no space for the requested
* mapping then try again:
*
* Note: this is different with the case of bottomup
* which does the fully line-search, but we use find_vma
* here that causes some holes skipped.
*/
if (start_addr != mm->mmap_base) {
mm->free_area_cache = mm->mmap_base;
mm->cached_hole_size = 0;
goto try_again;
}

/*
* A failed mmap() very likely causes application failure,
* so fall back to the bottom-up function here. This scenario
Expand Down

0 comments on commit b716ad9

Please sign in to comment.