Commit 34d07177 authored by Michel Lespinasse's avatar Michel Lespinasse Committed by Benjamin Herrenschmidt

mm: remove free_area_cache use in powerpc architecture

As all other architectures have been converted to use vm_unmapped_area(),
we are about to retire the free_area_cache.

This change simply removes the use of that cache in
slice_get_unmapped_area(), which will most certainly have a
performance cost. Next one will convert that function to use the
vm_unmapped_area() infrastructure and regain the performance.
Signed-off-by: default avatarMichel Lespinasse <walken@google.com>
Acked-by: default avatarRik van Riel <riel@redhat.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
parent 3925f46b
...@@ -99,8 +99,7 @@ extern unsigned long slice_get_unmapped_area(unsigned long addr, ...@@ -99,8 +99,7 @@ extern unsigned long slice_get_unmapped_area(unsigned long addr,
unsigned long len, unsigned long len,
unsigned long flags, unsigned long flags,
unsigned int psize, unsigned int psize,
int topdown, int topdown);
int use_cache);
extern unsigned int get_slice_psize(struct mm_struct *mm, extern unsigned int get_slice_psize(struct mm_struct *mm,
unsigned long addr); unsigned long addr);
......
...@@ -742,7 +742,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, ...@@ -742,7 +742,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
struct hstate *hstate = hstate_file(file); struct hstate *hstate = hstate_file(file);
int mmu_psize = shift_to_mmu_psize(huge_page_shift(hstate)); int mmu_psize = shift_to_mmu_psize(huge_page_shift(hstate));
return slice_get_unmapped_area(addr, len, flags, mmu_psize, 1, 0); return slice_get_unmapped_area(addr, len, flags, mmu_psize, 1);
} }
#endif #endif
......
...@@ -240,23 +240,15 @@ static void slice_convert(struct mm_struct *mm, struct slice_mask mask, int psiz ...@@ -240,23 +240,15 @@ static void slice_convert(struct mm_struct *mm, struct slice_mask mask, int psiz
static unsigned long slice_find_area_bottomup(struct mm_struct *mm, static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
unsigned long len, unsigned long len,
struct slice_mask available, struct slice_mask available,
int psize, int use_cache) int psize)
{ {
struct vm_area_struct *vma; struct vm_area_struct *vma;
unsigned long start_addr, addr; unsigned long addr;
struct slice_mask mask; struct slice_mask mask;
int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT);
if (use_cache) { addr = TASK_UNMAPPED_BASE;
if (len <= mm->cached_hole_size) {
start_addr = addr = TASK_UNMAPPED_BASE;
mm->cached_hole_size = 0;
} else
start_addr = addr = mm->free_area_cache;
} else
start_addr = addr = TASK_UNMAPPED_BASE;
full_search:
for (;;) { for (;;) {
addr = _ALIGN_UP(addr, 1ul << pshift); addr = _ALIGN_UP(addr, 1ul << pshift);
if ((TASK_SIZE - len) < addr) if ((TASK_SIZE - len) < addr)
...@@ -272,63 +264,24 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm, ...@@ -272,63 +264,24 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT); addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
continue; continue;
} }
if (!vma || addr + len <= vma->vm_start) { if (!vma || addr + len <= vma->vm_start)
/*
* Remember the place where we stopped the search:
*/
if (use_cache)
mm->free_area_cache = addr + len;
return addr; return addr;
}
if (use_cache && (addr + mm->cached_hole_size) < vma->vm_start)
mm->cached_hole_size = vma->vm_start - addr;
addr = vma->vm_end; addr = vma->vm_end;
} }
/* Make sure we didn't miss any holes */
if (use_cache && start_addr != TASK_UNMAPPED_BASE) {
start_addr = addr = TASK_UNMAPPED_BASE;
mm->cached_hole_size = 0;
goto full_search;
}
return -ENOMEM; return -ENOMEM;
} }
static unsigned long slice_find_area_topdown(struct mm_struct *mm, static unsigned long slice_find_area_topdown(struct mm_struct *mm,
unsigned long len, unsigned long len,
struct slice_mask available, struct slice_mask available,
int psize, int use_cache) int psize)
{ {
struct vm_area_struct *vma; struct vm_area_struct *vma;
unsigned long addr; unsigned long addr;
struct slice_mask mask; struct slice_mask mask;
int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT); int pshift = max_t(int, mmu_psize_defs[psize].shift, PAGE_SHIFT);
/* check if free_area_cache is useful for us */
if (use_cache) {
if (len <= mm->cached_hole_size) {
mm->cached_hole_size = 0;
mm->free_area_cache = mm->mmap_base;
}
/* 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) {
addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
mask = slice_range_to_mask(addr, len);
if (slice_check_fit(mask, available) &&
slice_area_is_free(mm, addr, len))
/* remember the address as a hint for
* next time
*/
return (mm->free_area_cache = addr);
}
}
addr = mm->mmap_base; addr = mm->mmap_base;
while (addr > len) { while (addr > len) {
/* Go down by chunk size */ /* Go down by chunk size */
...@@ -352,16 +305,8 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm, ...@@ -352,16 +305,8 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
* return with success: * return with success:
*/ */
vma = find_vma(mm, addr); vma = find_vma(mm, addr);
if (!vma || (addr + len) <= vma->vm_start) { if (!vma || (addr + len) <= vma->vm_start)
/* remember the address as a hint for next time */
if (use_cache)
mm->free_area_cache = addr;
return addr; return addr;
}
/* remember the largest hole we saw so far */
if (use_cache && (addr + mm->cached_hole_size) < vma->vm_start)
mm->cached_hole_size = vma->vm_start - addr;
/* try just below the current vma->vm_start */ /* try just below the current vma->vm_start */
addr = vma->vm_start; addr = vma->vm_start;
...@@ -373,28 +318,18 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm, ...@@ -373,28 +318,18 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
* can happen with large stack limits and large mmap() * can happen with large stack limits and large mmap()
* allocations. * allocations.
*/ */
addr = slice_find_area_bottomup(mm, len, available, psize, 0); return slice_find_area_bottomup(mm, len, available, psize);
/*
* Restore the topdown base:
*/
if (use_cache) {
mm->free_area_cache = mm->mmap_base;
mm->cached_hole_size = ~0UL;
}
return addr;
} }
static unsigned long slice_find_area(struct mm_struct *mm, unsigned long len, static unsigned long slice_find_area(struct mm_struct *mm, unsigned long len,
struct slice_mask mask, int psize, struct slice_mask mask, int psize,
int topdown, int use_cache) int topdown)
{ {
if (topdown) if (topdown)
return slice_find_area_topdown(mm, len, mask, psize, use_cache); return slice_find_area_topdown(mm, len, mask, psize);
else else
return slice_find_area_bottomup(mm, len, mask, psize, use_cache); return slice_find_area_bottomup(mm, len, mask, psize);
} }
#define or_mask(dst, src) do { \ #define or_mask(dst, src) do { \
...@@ -415,7 +350,7 @@ static unsigned long slice_find_area(struct mm_struct *mm, unsigned long len, ...@@ -415,7 +350,7 @@ static unsigned long slice_find_area(struct mm_struct *mm, unsigned long len,
unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
unsigned long flags, unsigned int psize, unsigned long flags, unsigned int psize,
int topdown, int use_cache) int topdown)
{ {
struct slice_mask mask = {0, 0}; struct slice_mask mask = {0, 0};
struct slice_mask good_mask; struct slice_mask good_mask;
...@@ -430,8 +365,8 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, ...@@ -430,8 +365,8 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
BUG_ON(mm->task_size == 0); BUG_ON(mm->task_size == 0);
slice_dbg("slice_get_unmapped_area(mm=%p, psize=%d...\n", mm, psize); slice_dbg("slice_get_unmapped_area(mm=%p, psize=%d...\n", mm, psize);
slice_dbg(" addr=%lx, len=%lx, flags=%lx, topdown=%d, use_cache=%d\n", slice_dbg(" addr=%lx, len=%lx, flags=%lx, topdown=%d\n",
addr, len, flags, topdown, use_cache); addr, len, flags, topdown);
if (len > mm->task_size) if (len > mm->task_size)
return -ENOMEM; return -ENOMEM;
...@@ -503,8 +438,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, ...@@ -503,8 +438,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
/* Now let's see if we can find something in the existing /* Now let's see if we can find something in the existing
* slices for that size * slices for that size
*/ */
newaddr = slice_find_area(mm, len, good_mask, psize, topdown, newaddr = slice_find_area(mm, len, good_mask, psize, topdown);
use_cache);
if (newaddr != -ENOMEM) { if (newaddr != -ENOMEM) {
/* Found within the good mask, we don't have to setup, /* Found within the good mask, we don't have to setup,
* we thus return directly * we thus return directly
...@@ -536,8 +470,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, ...@@ -536,8 +470,7 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
* anywhere in the good area. * anywhere in the good area.
*/ */
if (addr) { if (addr) {
addr = slice_find_area(mm, len, good_mask, psize, topdown, addr = slice_find_area(mm, len, good_mask, psize, topdown);
use_cache);
if (addr != -ENOMEM) { if (addr != -ENOMEM) {
slice_dbg(" found area at 0x%lx\n", addr); slice_dbg(" found area at 0x%lx\n", addr);
return addr; return addr;
...@@ -547,15 +480,14 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len, ...@@ -547,15 +480,14 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
/* Now let's see if we can find something in the existing slices /* Now let's see if we can find something in the existing slices
* for that size plus free slices * for that size plus free slices
*/ */
addr = slice_find_area(mm, len, potential_mask, psize, topdown, addr = slice_find_area(mm, len, potential_mask, psize, topdown);
use_cache);
#ifdef CONFIG_PPC_64K_PAGES #ifdef CONFIG_PPC_64K_PAGES
if (addr == -ENOMEM && psize == MMU_PAGE_64K) { if (addr == -ENOMEM && psize == MMU_PAGE_64K) {
/* retry the search with 4k-page slices included */ /* retry the search with 4k-page slices included */
or_mask(potential_mask, compat_mask); or_mask(potential_mask, compat_mask);
addr = slice_find_area(mm, len, potential_mask, psize, addr = slice_find_area(mm, len, potential_mask, psize,
topdown, use_cache); topdown);
} }
#endif #endif
...@@ -586,8 +518,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, ...@@ -586,8 +518,7 @@ unsigned long arch_get_unmapped_area(struct file *filp,
unsigned long flags) unsigned long flags)
{ {
return slice_get_unmapped_area(addr, len, flags, return slice_get_unmapped_area(addr, len, flags,
current->mm->context.user_psize, current->mm->context.user_psize, 0);
0, 1);
} }
unsigned long arch_get_unmapped_area_topdown(struct file *filp, unsigned long arch_get_unmapped_area_topdown(struct file *filp,
...@@ -597,8 +528,7 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, ...@@ -597,8 +528,7 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp,
const unsigned long flags) const unsigned long flags)
{ {
return slice_get_unmapped_area(addr0, len, flags, return slice_get_unmapped_area(addr0, len, flags,
current->mm->context.user_psize, current->mm->context.user_psize, 1);
1, 1);
} }
unsigned int get_slice_psize(struct mm_struct *mm, unsigned long addr) unsigned int get_slice_psize(struct mm_struct *mm, unsigned long addr)
......
...@@ -352,7 +352,7 @@ static unsigned long spufs_get_unmapped_area(struct file *file, ...@@ -352,7 +352,7 @@ static unsigned long spufs_get_unmapped_area(struct file *file,
/* Else, try to obtain a 64K pages slice */ /* Else, try to obtain a 64K pages slice */
return slice_get_unmapped_area(addr, len, flags, return slice_get_unmapped_area(addr, len, flags,
MMU_PAGE_64K, 1, 0); MMU_PAGE_64K, 1);
} }
#endif /* CONFIG_SPU_FS_64K_LS */ #endif /* CONFIG_SPU_FS_64K_LS */
......
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