Skip to content
This repository has been archived by the owner on May 20, 2024. It is now read-only.

Memory Management Ideas

jhaberstro edited this page Mar 24, 2013 · 3 revisions

So, there's basically several layers of the memory management system:

  1. The Physical Memory Manager: This is the lowest level. It essentially keeps track of how much physical memory is available. At startup, the kernel knows where all of the unused memory starts and ends because it also knows exactly how much space the kernel itself uses. The PMM just operates within this range. This is all ready implemented by Xinu; see system/memget.c and system/memfree.c. I believe the common terminology is that the PMM is used to allocate frames (however, it also common for people to just refer to these as pages as well, but I find that confusing since an OS can have a PMM that allocates frames, but not using paging for their virtual memory scheme). It might be a fun project to reimplement the allocation scheme to use a more common/robust scheme (such as slab, buddy, etc..)

  2. The Virtual Memory Manager: This sits above the physical memory manager and it is responsible for mapping and unmapping (physical) frames into (virtual) pages. I.E. this would be the interface to the MMU.

  3. Heap/Malloc: Our highest level, that uses both the PMM and VMM. Essentially malloc is responsible for partitioning and allocating out the virtual address space by requesting frames from the PMM, mapping frames to pages with the VMM, and keeping track of (each process's(?)) used pages. How this layer manages the virtual address space is similar to how the PMM manages the physical address space.

Random Notes

  • I'm still investigating how this fits into processes exactly (for example, there's a "memlist" field in the process/thread structure that I'm wondering if we can use to keep track of each processes allocated pages).

  • A good way to split up work would be to design the interface for each layer and then assign layers to different people (or parts of layers if we want to try a little bit of everything :P).

  • Here's an example interface I snagged from the OSDev forums:

    They are layered, and the units can easily be 4096 bytes.

    [physical page management] // global to the system
    address ppm_alloc(); // single unit of memory
    address ppm_alloc(count); // contiguous units of memory
    address ppm_alloc(where, count); // contiguous units of memory
    [virtual page management] // local to the process/address-space
    address vpm_alloc();
    address vpm_alloc(count);
    address vpm_alloc(where, count);
    [heap management] // local to the process or kernel
    address malloc();
    address free();

    Where the vpm_* set of functions are local to the process/address-space, and there may exist many address-spaces. The ppm_* set of functions are global, while the heap functions are normally local to the image loaded into memory -- or the kernel image in it's little area of memory.

Clone this wiki locally