Author Topic: Memory Management Notes  (Read 4368 times)

0 Members and 1 Guest are viewing this topic.

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Memory Management Notes
« on: February 14, 2006, 09:26:20 pm »
Memory Management in Optimix:

Our Memory Manager will have three compoenents

- Physical
- Virtual
- Linear

Physical is initialized first and it is located in a "physHeap" right after the kernel in memory, it provides
two functions (physAlloc() and physFree(unsigned long addr)) they deal with serving up 4KB physical pages of memory.

Paging is initialized next which uses Physical to help map PageTables which are non present and it will free pages
which are being overwritten (If they are found present by the Mapper, it is unmapped then free'd)

Linear is what comes after Paging, it is the "Kernel Memory Manager" since it manages the kernel heap (Virtual)
and is what the C Std Lib "malloc" and friends wrap around.

The good thing about having these three components is they are completely transparent from eachother.
Physical is never used out of Paging (Actually the cool part is we selfmap the Physical heap to the same virt addr, so we can continue to use it for paging even after we enable paging which may be good for things like spawning tasks), Paging is never used
other than spawning/deleting tasks and threads and of course Page faults.

The only thing in the end widely used is the Linear Manager which is the end result after all this shifting and mapping.

One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: Memory Management Notes
« Reply #1 on: February 17, 2006, 06:17:28 am »
Code: [Select]
/*  Optimix Operating System
 *  optimix/kernel/mm/phys.c
 * 
 *  Copyright (C) 2005,2006 Nelson Carrillo
 */

#include <optimix/mm/phys.h>

extern keEnd;

static int allocTimes = 0;

void* physAlloc()
{
int tmpAlloc;

memoryBlock* memBlock = (memoryBlock*)keEnd;
memoryBlock* memBest = NULL;

if (allocTimes == 0)
{
memBlock->used = true;
memBest = memBlock;

return (void*)memBest;
} else {
tmpAlloc = allocTimes;

while (tmpAlloc < 0)
{
if (memBlock->used = false)
{
memBest = memBlock;
break;
}

memBlock = (void*)memBlock + sizeof(memoryBlock) + 4096;
tmpAlloc--;
}

if (memBest == NULL)
return NULL

return (void*)memBest;
}
}

void physFree( void* addr)
{
memoryBlock block;

if (addr == NULL) return;

block = (void*)addr - sizeof(memoryBlock);

block->used = false;

return;
}

Implemented an (untested) physical memory manager. Serves up 4KB pages of physical memory.
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling