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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



__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 <[email protected]>
--- 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);

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux