wiki:kernel_pmem

Physical Memory Allocators

The pmem.c and pmem.h files define the data structures and functions used by the boot-loader to allocate physical memory.

The physical memory allocation is statically done by the boot-loader, and the functions defined here are not used by the kernel.

The physical address format is 40 bits, structured in five fields:

4 4 11 9 12
X Y BPPI SPPI OFFSET
  • The (X,Y) fields define the cluster coordinates in the 2D mesh.
  • The BPPI field is the Big Physical Page Index
  • The SPPI field is the Small Physical Page Index
  • The |X|Y|BPPI|SPPI| concatenation is the PPN (Physical Page Number)

As the physical memory can be distributed in all clusters, there is one physical memory allocator in each cluster, and the allocation state is defined by the boot_pmem_alloc[x][y] array (defined in the boot.c file). As the allocated physical memory is never released, the allocator structure is very simple, and is defined in the pmem_alloc_t structure.

As the boot-loader is executed by one single processor, this structure does not contain any lock protecting exclusive access.

Both small pages allocator and big pages allocators allocate a variable number of CONTIGUOUS pages in the physical space. The first big page in cluster[0][0] is reserved for identity mapping vsegs, and is not allocated by the physical memory allocators.

void _pmem_alloc_init( unsigned int x, unsigned int y, unsigned int base, unsigned int size )

This function initialises the physical memory allocator in cluster (x,y). The pseg base address and the pseg size must be multiple of 2 Mbytes (one big page).

  • base is the pseg local base address (no cluster extension)
  • size is the pseg length (bytes)

The first page in cluster[0][0] is reserved for the boot code identity mapping vsegs.

unsigned int _get_small_ppn( pmem_alloc_t* p, unsigned int n )

This function allocates n contiguous small pages (4 Kbytes), from the physical memory allocator defined by the p pointer. It returns the PPN (28 bits) of the first physical small page. Exit if not enough free space.

unsigned int _get_big_ppn( pmem_alloc_t* p, unsigned int n )

This function allocates n contiguous big pages (2 Mbytes), from the physical memory allocator defined by the p pointer. It returns the PPN (28 bits) of the first physical big page (the SPPI field of the ppn is always 0). Exit if not enough free space.

Last modified 10 years ago Last modified on Oct 5, 2014, 1:25:01 PM