Pergunta

I am going through the perf source in linux kernel source to find out how user space probing is implemented. At many places, I encountered this :

zalloc(sizeof(struct __event_package) * npevs);

I think its located in zlib library (for fedora 18). Can anybody tell me how this zalloc helps in allocating memory? Thanks in advance...

Foi útil?

Solução

You can refer this link:

The allocation is the same as any other heap allocation. In the kernel space, heap is divided into many freelists, and each freelist has blocks of same sizes connected in a linked list.

For eg:
Freelist1 - 4 bytes/block x 10 blocks
Freelist2 - 8 bytes/block x 10 blocks
Freelist3 - 16 bytes/block x 10 blocks
....
Freelist10 - 1024 bytes/block x 10 blocks

Each free list represents slabs (slab allocator) and make use of buddy system

So, when one does a zalloc, it first decides which size freelist can fulfill this request and then finds a free blocks from it.

In some custom kernel implementations, heap is divided amongst kernel & other services. In that case, *alloc needs to know which heap to access to fulfill the request.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top