Memory and paging: Difference between revisions

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


Physical memory is divided in several segments that can be used by the system.
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.
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.


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.
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 ===
=== Virtual memory ===
Line 17: Line 20:
=== Memory areas ===
=== 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.
After scanning the linear address space for available physical memory, AMC-OS split the physical memory in two areas :
Each area is characterized in a <tt>MEMORY_AREA</tt> structures with the number and pointers to the used and free blocks they contain, and to the free pages.
* 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.


User memory is always taken first from high memory, then low memory if empty. Kernel memory is always taken only in low memory.
Each area is specified in a <tt>MEMORY_AREA</tt> 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 ===
=== 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.
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 <tt>MEMORY_AREA.ptrFreeBlocks</tt>, and count in <tt>MEMORY_AREA.nbFreeBlocks</tt>.
The pointer to the free blocks list is stored in <tt>MEMORY_AREA.ptrFreeBlocks</tt>, and count in <tt>MEMORY_AREA.nbFreeBlocks</tt>.


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


=== Number of free pages per block ===
=== Number of free pages per block ===

Revision as of 00:01, 20 July 2015

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

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