Implemented the new physical page allocator API.

This commit is contained in:
Jonas 'Sortie' Termansen 2011-08-22 21:08:39 +02:00
parent d392045559
commit b80195dc19
3 changed files with 64 additions and 13 deletions

View File

@ -46,12 +46,15 @@ namespace Sortix
size_t ContinuousPages; size_t ContinuousPages;
}; };
// Refers to private assembly functions.
addr_t GetPrivate();
void PutPrivate(addr_t page);
void Fragmentize(); void Fragmentize();
UnallocPage* volatile UnallocatedPage; // Must have this name and namespace due to assembly. UnallocPage* volatile UnallocatedPage; // Must have this name and namespace due to assembly.
size_t PagesTotal; size_t pagesTotal;
//size_t PagesUsed; size_t pagesUsed;
//size_t PagesFree; size_t pagesFree;
const size_t UnallocPageMagic = 0xABBAACDC; // Must this value due to assembly const size_t UnallocPageMagic = 0xABBAACDC; // Must this value due to assembly
@ -59,7 +62,7 @@ namespace Sortix
void Init(multiboot_info_t* BootInfo) void Init(multiboot_info_t* BootInfo)
{ {
UnallocatedPage = NULL; UnallocatedPage = NULL;
PagesTotal = 0; pagesTotal = 0;
if ( !( BootInfo->flags & MULTIBOOT_INFO_MEM_MAP ) ) if ( !( BootInfo->flags & MULTIBOOT_INFO_MEM_MAP ) )
{ {
@ -136,23 +139,70 @@ namespace Sortix
Page->Next = UnallocatedPage; Page->Next = UnallocatedPage;
Page->ContinuousPages = Entries[I].Length - 1; Page->ContinuousPages = Entries[I].Length - 1;
PagesTotal += Entries[I].Length; pagesTotal += Entries[I].Length;
UnallocatedPage = Page; UnallocatedPage = Page;
} }
} }
if ( PagesTotal == 0 ) { Panic("memorymanagement.cpp: no RAM were available for paging"); } if ( pagesTotal == 0 ) { Panic("memorymanagement.cpp: no RAM were available for paging"); }
// Alright, time to make our linked list into a lot of small entries. // Alright, time to make our linked list into a lot of small entries.
// This speeds up the system when it's fully up and running. It only // This speeds up the system when it's fully up and running. It only
// takes a few miliseconds to run this operation on my laptop. // takes a few miliseconds to run this operation on my laptop.
Fragmentize(); Fragmentize();
pagesFree = pagesTotal;
pagesUsed = 0;
ASSERT(pagesFree + pagesUsed == pagesTotal);
#ifndef PLATFORM_SERIAL #ifndef PLATFORM_SERIAL
//Log::PrintF("%zu pages are available for paging (%zu MiB RAM)\n", PagesTotal, PagesTotal >> 8 /* * 0x1000 / 1024 / 1024*/); //Log::PrintF("%zu pages are available for paging (%zu MiB RAM)\n", PagesTotal, PagesTotal >> 8 /* * 0x1000 / 1024 / 1024*/);
#endif #endif
} }
addr_t Get()
{
addr_t result = GetPrivate();
if ( result != 0 )
{
ASSERT(pagesFree > 0);
pagesUsed++;
pagesFree--;
}
else
{
ASSERT(pagesFree == 0);
}
ASSERT(pagesFree + pagesUsed == pagesTotal);
return result;
}
void Put(addr_t page)
{
pagesFree++;
pagesUsed--;
PutPrivate(page);
}
void Insert(addr_t page)
{
pagesFree++;
pagesTotal++;
PutPrivate(page);
}
void GetStats(size_t* pagesize, size_t* numfree, size_t* numused)
{
*pagesize = 4096UL;
*numfree = pagesFree;
*numused = pagesUsed;
}
} }
namespace VirtualMemory namespace VirtualMemory

View File

@ -85,7 +85,8 @@ namespace Sortix
// (there is no RAM). You can then add memory where you desire. You can take // (there is no RAM). You can then add memory where you desire. You can take
// a physical page and put it in several places, and you can even add // a physical page and put it in several places, and you can even add
// permissions to it (read-only, read-write, kernel-only). Naturally, the // permissions to it (read-only, read-write, kernel-only). Naturally, the
// amount of physical pages is a limit (out of memory). // amount of physical pages is a limit (out of memory), but using swapping
// and a not-RAM storage unit, we could have potentially much more memory.
// //
// There can exist several virtual address spaces, and it is possible for // There can exist several virtual address spaces, and it is possible for
// them to share physical pages. Each process in the system has its own // them to share physical pages. Each process in the system has its own

View File

@ -83,9 +83,9 @@ FragDone:
pop %ebx pop %ebx
ret ret
.globl _ZN6Sortix4Page3GetEv .globl _ZN6Sortix4Page10GetPrivateEv
.type _ZN6Sortix4Page3GetEv, @function # namespace Sortix { void Paging::Allocate(); } .type _ZN6Sortix4Page10GetPrivateEv, @function # namespace Sortix { void Paging::Allocate(); }
_ZN6Sortix4Page3GetEv: _ZN6Sortix4Page10GetPrivateEv:
# Load the front of our linked list. # Load the front of our linked list.
mov _ZN6Sortix4Page15UnallocatedPageE, %eax # Load UnallocPage* Sortix::Page::UnallocatedPage mov _ZN6Sortix4Page15UnallocatedPageE, %eax # Load UnallocPage* Sortix::Page::UnallocatedPage
@ -141,9 +141,9 @@ OutOfMem:
movl $0, %eax movl $0, %eax
ret ret
.globl _ZN6Sortix4Page3PutEm .globl _ZN6Sortix4Page10PutPrivateEm
.type _ZN6Sortix4Page3PutEm, @function # namespace Sortix { void Paging::Free(void* Page); } .type _ZN6Sortix4Page10PutPrivateEm, @function # namespace Sortix { void Paging::Free(void* Page); }
_ZN6Sortix4Page3PutEm: _ZN6Sortix4Page10PutPrivateEm:
push %esi push %esi
mov _ZN6Sortix4Page15UnallocatedPageE, %eax # Load UnallocPage* Sortix::Page::UnallocatedPage mov _ZN6Sortix4Page15UnallocatedPageE, %eax # Load UnallocPage* Sortix::Page::UnallocatedPage
mov 0x8(%esp), %edx mov 0x8(%esp), %edx