Skip to content

Commit

Permalink
[PATCH] vmalloc: optimization, cleanup, bugfixes
Browse files Browse the repository at this point in the history
- reorder 'struct vm_struct' to speedup lookups on CPUS with small cache
  lines.  The fields 'next,addr,size' should be now in the same cache line,
  to speedup lookups.

- One minor cleanup in __get_vm_area_node()

- Bugfixes in vmalloc_user() and vmalloc_32_user() NULL returns from
  __vmalloc() and __find_vm_area() were not tested.

[akpm@osdl.org: remove redundant BUG_ONs]
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Cc: Nick Piggin <nickpiggin@yahoo.com.au>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Eric Dumazet authored and Linus Torvalds committed Nov 13, 2006
1 parent 088406b commit 2b4ac44
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
3 changes: 2 additions & 1 deletion include/linux/vmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ struct vm_area_struct;
#endif

struct vm_struct {
/* keep next,addr,size together to speedup lookups */
struct vm_struct *next;
void *addr;
unsigned long size;
unsigned long flags;
struct page **pages;
unsigned int nr_pages;
unsigned long phys_addr;
struct vm_struct *next;
};

/*
Expand Down
26 changes: 13 additions & 13 deletions mm/vmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,8 @@ static struct vm_struct *__get_vm_area_node(unsigned long size, unsigned long fl
if (unlikely(!area))
return NULL;

if (unlikely(!size)) {
kfree (area);
if (unlikely(!size))
return NULL;
}

/*
* We always allocate a guard page.
Expand Down Expand Up @@ -532,11 +530,12 @@ void *vmalloc_user(unsigned long size)
void *ret;

ret = __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
write_lock(&vmlist_lock);
area = __find_vm_area(ret);
area->flags |= VM_USERMAP;
write_unlock(&vmlist_lock);

if (ret) {
write_lock(&vmlist_lock);
area = __find_vm_area(ret);
area->flags |= VM_USERMAP;
write_unlock(&vmlist_lock);
}
return ret;
}
EXPORT_SYMBOL(vmalloc_user);
Expand Down Expand Up @@ -605,11 +604,12 @@ void *vmalloc_32_user(unsigned long size)
void *ret;

ret = __vmalloc(size, GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL);
write_lock(&vmlist_lock);
area = __find_vm_area(ret);
area->flags |= VM_USERMAP;
write_unlock(&vmlist_lock);

if (ret) {
write_lock(&vmlist_lock);
area = __find_vm_area(ret);
area->flags |= VM_USERMAP;
write_unlock(&vmlist_lock);
}
return ret;
}
EXPORT_SYMBOL(vmalloc_32_user);
Expand Down

0 comments on commit 2b4ac44

Please sign in to comment.