Memory and paging: Difference between revisions

From AMC-OS Developers
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
Line 32: Line 32:
A free pages per block table is created to be able to put back in free blocks list a block that has all its pages free.
A free pages per block table is created to be able to put back in free blocks list a block that has all its pages free.
It is a simple table indexed by the block number, containing for each entry an unsigned byte with the number of free pages. Obviously, there can't be more than 256 pages per block (64 by default).
It is a simple table indexed by the block number, containing for each entry an unsigned byte with the number of free pages. Obviously, there can't be more than 256 pages per block (64 by default).
== Kernel memory allocation procedures ==

Latest revision as of 11:52, 3 September 2022

Physical memory management

For more information on physical memory initialization, refer to Memory initialization article.

Memory areas

After scanning the linear address space for available physical memory, AMC-OS split the physical memory in two areas :

  • The low memory area must be at least 4Mbytes large, and its size is proportional to the total amount of physical memory available. This area is also referred as kernel memory as the physical memory is available from all page directories at kernel privilege.
  • The high memory area contains all the remaining memory and is used for user memory.

Each memory area is divided in blocks of 256Kbytes, and is specified in a MEMORY_AREA structure containing :

  • the number and pointers to the used blocks they contain;
  • the number and pointers to the free blocks they contain;
  • the number and pointers to the free pages.

User memory can be taken from low memory if high memory is exhausted.

Blocks management

Free blocks list

By default, each memory area is divided in blocks of 256 Kbytes. A new block is activated and divided in free pages, if there are no more free pages available in the area. Free blocks are stored in the free blocks list, a linked list of the InactiveMemory structure. It contains :

  • the pointer to the free block;
  • the number of contiguous free blocks;
  • the pointer to the next structure.

During initialization phase, we pre-allocate the maximum of free blocks structures that can be necessary, ie half the number of blocks. This list of free blocks structures is also a linked list to accelerate allocating and freeing processes.

The pointer to the free blocks list is stored in MEMORY_AREA.ptrFreeBlocks, and count in MEMORY_AREA.nbFreeBlocks.

The pointer to the free blocks structures list is stored in MEMORY_ptrInactiveFreeBlocksStruct, and count in MEMORY_nbInactiveFreeBlocksStruct.

Number of free pages per block

A free pages per block table is created to be able to put back in free blocks list a block that has all its pages free. It is a simple table indexed by the block number, containing for each entry an unsigned byte with the number of free pages. Obviously, there can't be more than 256 pages per block (64 by default).

Kernel memory allocation procedures