[PATCH] Try to avoid a pessimistic vmalloc() recursion

From: Eric Dumazet
Date: Mon Oct 09 2006 - 10:48:30 EST


__vmalloc_area_node() is a litle bit pessimist when allocating space for
storing struct page pointers.

When allocating more than 4 MB on ia32, or 2 MB on x86_64,  
__vmalloc_area_node() has to allocate more than PAGE_SIZE bytes to store
pointers to  page structs. This means that two TLB translations are needed to
access data.

This patch tries a kmalloc() call, then only if this first attempt failed, a
vmalloc() is performed. (Later, at vfree() time we chose kfree() or vfree()
with a test on flags & VM_VPAGES : no change is needed)

Most of the time, the first kmalloc() should be OK, so we reduce TLB usage.

Signed-off-by: Eric Dumazet <dada1@xxxxxxxxxxxxx>
--- linux-2.6.18/mm/vmalloc.c 2006-10-09 13:58:13.000000000 +0200
+++ linux-2.6.18-ed/mm/vmalloc.c 2006-10-09 14:04:11.000000000 +0200
@@ -426,12 +426,12 @@
array_size = (nr_pages * sizeof(struct page *));

area->nr_pages = nr_pages;
+ pages = kmalloc_node(array_size, (gfp_mask & ~__GFP_HIGHMEM), node);
/* Please note that the recursion is strictly bounded. */
- if (array_size > PAGE_SIZE) {
+ if (!pages && array_size > PAGE_SIZE) {
pages = __vmalloc_node(array_size, gfp_mask, PAGE_KERNEL, node);
area->flags |= VM_VPAGES;
- } else
- pages = kmalloc_node(array_size, (gfp_mask & ~__GFP_HIGHMEM), node);
+ }
area->pages = pages;
if (!area->pages) {
remove_vm_area(area->addr);