• Dave Hansen's avatar
    lib: flexible array implementation · 534acc05
    Dave Hansen authored
    Once a structure goes over PAGE_SIZE*2, we see occasional allocation
    failures.  Some people have chosen to switch over to things like vmalloc()
    that will let them keep array-like access to such a large structures.
    But, vmalloc() has plenty of downsides.
    
    Here's an alternative.  I think it's what Andrew was suggesting here:
    
    	http://lkml.org/lkml/2009/7/2/518
    
    I call it a flexible array.  It does all of its work in PAGE_SIZE bits, so
    never does an order>0 allocation.  The base level has
    PAGE_SIZE-2*sizeof(int) bytes of storage for pointers to the second level.
     So, with a 32-bit arch, you get about 4MB (4183112 bytes) of total
    storage when the objects pack nicely into a page.  It is half that on
    64-bit because the pointers are twice the size.  There's a table detailing
    this in the code.
    
    There are kerneldocs for the functions, but here's an
    overview:
    
    flex_array_alloc() - dynamically allocate a base structure
    flex_array_free() - free the array and all of the
    		    second-...
    534acc05
Makefile 3.26 KB