What is the difference between l4dm_mem_allocate, l4slab_alloc, malloc
Bjoern Doebel
doebel at os.inf.tu-dresden.de
Wed Sep 12 16:21:30 CEST 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
> In the l4vfs source code I am sure that the malloc function could be used in
> the L4 programming. But I also find two functions named l4dm_mem_allocate
> and l4slab_alloc. It seems that both of them could also allocate memory as
> malloc does.
> What is the difference between the 3 functions? Which one is fastest? Please
> help me.
malloc() is provided by a standard C library. It typically mmap()s some
anonymous memory and then performs memory allocation within this area. If
the mmapped area is full, another piece of memory is retrieved.
So, what libC needs to implement malloc() is a means to retrieve some
memory from the underlying system. Our underlying L4 system's memory
management is based on dataspaces provided by dataspace managers [1]. This
is where l4dm_mem_allocate() comes in. It is used to allocate a dataspace
from a dataspace manager (DSM). The DSM backs its dataspaces, e.g., dm_phys
uses physical memory for that. The dataspace you get from your DSM is then
attached to your local address space using l4rm_attach() -
l4dm_mem_allocate() does this internally for you.
Regarding speed: If you only do one allocation in your application, then
both variants will be nearly the same speed, because malloc() will need to
get backing storage using l4dm_mem_allocate(), or something similiar,
first. This incorporates IPC to the dataspace manager and may include some
page fault IPC(s) to your pager if you use the L4RM_MAP flag to map the new
dataspace immediately.
If you perform multiple allocations, malloc() will probably be faster in
most cases, because it only performs bookkeeping inside your task, invoking
no task switches, system calls etc.
l4slab_alloc() comes from the L4 Slab implementation - this is an
implementation of slab caches, which are described in [2]. Slabs are a fast
way to allocate memory if you are dynamically allocating and freeing many
same-sized small objects (e.g., objects of the same type). The slab
implementation also uses dataspaces as underlying storage.
Regards
Bjoern
[1] L4Env dataspaces documentation
http://os.inf.tu-dresden.de/l4env/doc/html/dm_phys/index.html
[2] J. Bonwick: "The slab allocator: an object-caching kernel memory
allocator"
http://www.usenix.org/publications/library/proceedings/bos94/full_papers/bonwick.ps
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFG5/XqP5ijxgQLUNkRAgztAJ9CJUS3YaixOhUl/N97UtlyWYU/pwCfZzJa
Njw+GcN+EpDuZrccR7Wa4U4=
=7cfq
-----END PGP SIGNATURE-----
More information about the l4-hackers
mailing list