Memory and paging: Difference between revisions

From AMC-OS Developers
Jump to navigation Jump to search
No edit summary
Line 17: Line 17:


== Physical memory management ==
== Physical memory management ==
For more information on physical memory initialization, refer to [[Memmory Initialization]] article.


=== Memory areas ===
=== Memory areas ===

Revision as of 17:29, 18 April 2020

Memory model

Physical memory

Physical memory is divided in several segments that can be used by the system. During initialization phase, the system scan the linear address space for the available segments. In a standard PC, there are typically two segments : the first megabyte of memory (generally only the first 640Kbytes as BIOS, ROMs and video memory are mapped in the last 384Kbytes) and the memory above 1MB. In some cases, there also can be a hole in the 15-16M adressing space, or memory reserved for PCI addressing space. During the scan, the system counts the number of available blocks in each segment.

AMC-OS split the physical memory in two areas :

  • low memory reserved for kernel usage (will also be referred as kernel memory);
  • high memory for processes (will also be referred as user memory).

These two areas are divided in contiguous blocks of 256Kbytes by default, themselves being divided in 4Kbytes pages. To reduce the amount of memory used by the system, the blocks are activated on demand, and only then divided in pages.

Virtual memory

Physical memory management

For more information on physical memory initialization, refer to Memmory 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 area is specified in a MEMORY_AREA structure. It contains :

  • 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.

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).