Re: A question about memory fragmentation

From: Francis Galiegue (fg@mandrakesoft.com)
Date: Tue Nov 07 2000 - 11:47:10 EST


On Tue, 7 Nov 2000, Abel Muņoz Alcaraz wrote:

>
> my question is about memory fragmentation when I allocate and free a lot of
> small memory pieces in a kernel module.
> Can it do a memory fragmentation problem?
> Can I solve it using 'linux/list.h' API?

Fragmentation is not really an issue there. Linux maintains a pool of pages of
different sizes, and you will be allocated a page with the next size superior
to what you ask for. Sizes are all powers of two, so the worst case would be
that you ask 2^n+1 bytes and get a 2^(n+1) size page. When you free such a
page, it is merged if needed with a coalescent page and put back in the "upper
size" pool (not sure about this, though). So, no fragmentation is to be feared.

As to whether you use list.h or not, it really doesn't have any influence,
except that the list.h implementation is the preferred and standard way to make
doubly linked lists under Linux.

So, no, there's no need to allocate one big pool and manage it yourself. Also
remember that you can only kmalloc() up to 128k - if you want to allocate
bigger amounts of memory, use vmalloc().

Another solution: create your own slab cache for your objects.

-- 
Francis Galiegue, fg@mandrakesoft.com
"Programming is a race between programmers, who try and make more and more
idiot-proof software, and universe, which produces more and more remarkable
idiots. Until now, universe leads the race"  -- R. Cook

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Tue Nov 07 2000 - 21:00:22 EST