Memory and paging

From AMC-OS Developers
Revision as of 15:05, 24 August 2014 by Kindman (talk | contribs) (Created page with " == Memory model == === Physical memory === Physical memory is divided in several segments that can be used by the system. During initialization phase, the system checks the...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Memory model

Physical memory

Physical memory is divided in several segments that can be used by the system. During initialization phase, the system checks the different segments. There are typically two segments, the first megabyte of memory and the upper memory. In some cases, there also can be a hole in the 15-16M adressing space, or for PCI address space. In the same time, the system count the number of blocks (256K by default) in each segment.

The physical memory is split by the system in two areas, low memory reserved for kernel usage (that will also be referred as "kernel memory") and high memory for processes. These two areas are divided in contiguous blocks, themselves being divided in pages. To reduce the amount of memory used by the system, the blocks are activated on demand, and then divided in pages.

Virtual memory

Physical memory management

Memory areas

The low memory area must be at least 4MB large, and its size is proportional to the total amount of physical memory available. Each area is characterized in a MEMORY_AREA structures with the number and pointers to the used and free blocks they contain, and to the free pages.

User memory is always taken first from high memory, then low memory if empty. Kernel memory is always taken only in low memory.

Free blocks list

The free blocks list is a linked list of the InactiveMemory structure. It contains the pointer to the free block, the number of contiguous free blocks and 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 number of block, 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).