Version 2 (modified by 10 years ago) (diff) | ,
---|
GIET-VM / Kernel Malloc functions
The kernel_malloc.c and kernel_malloc.h files define the functions used by the kernel to dynamically allocate virtual memory from the kernel heaps distributed in each cluster.
The kernel_heap[x][y] descriptors array is stored in the kernel_data segment in cluster[0][0]. Each entry [x][y] contains a heap descriptor (kernel_heap_t), defining the current heap state in cluster[x][y].
- All kernel_heap[x][y) descriptors must be initialized once by the _heap_init() function.
- All allocated blocks have a size that is a power of 2, larger or equal to MIN_BLOCK_SIZE (typically 64 bytes), and are aligned.
- The memory allocation is done by the _remote_malloc() function, and there is no free mechanism.
- Concurrent dynamic allocation is possible, as each kernel_heap[x][y] descriptor is protected by a specific queuing spin-lock.
access functions
void _heap_init( )
This function initialises the kernel_heap[x][y] descriptors array
- It must exist one heap vseg in each cluster. The vseg length must be a power of 2, and the vseg base address must be aligned.
void* _remote_malloc( unsigned int size, unsigned int x, unsigned int y )
This function uses and updates the kernel_heap[x][y] array, and returns a pointer (virtual address) on a physical memory block located in cluster[x][y].
- size : number of requested bytes
- x : cluster X coordinate
- y : cluster Y coordinate
The block size required can be any value, but the allocated block can be larger: the actual size is the smallest power of 2 value larger or equal to the requested size. The base address is always aligned. If no block satisfying the request is available it returns a NULL pointer.