wiki:kernel_malloc

Version 8 (modified by alain, 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 are initialized by the _heap_init() function, called by the _kernel_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.

void _heap_init( )

This function initialises the kernel_heap[X_SIZE][Y_SIZE] descriptors array for all clusters containing a global vseg with the VOBJ_TYPE_HEAP. The vseg length must be a power of 2, and the vseg base address must be aligned.If there is no kernel heap in a cluster[x][y], the heap_size field of the descriptor is 0, and any kernel request to allocate memory creates a GIET error.

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 requested block size can be any value, but the allocated block can be larger than requested: 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.