1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Remove mem.PageOrder

Since the goal is to bootstrap the runtime's slab-like allocator the kernel
should only deal with managing allocations at a single page level.
This commit is contained in:
Achilleas Anagnostopoulos
2017-06-17 07:11:08 +01:00
parent 1d11af21c2
commit c0a9e07e83
7 changed files with 20 additions and 44 deletions

View File

@@ -9,13 +9,7 @@ import (
)
var (
// EarlyAllocator points to a static instance of the boot memory allocator
// which is used to bootstrap the kernel before initializing a more
// advanced memory allocator.
EarlyAllocator BootMemAllocator
errBootAllocUnsupportedPageSize = &kernel.Error{Module: "boot_mem_alloc", Message: "allocator only support allocation requests of order(0)"}
errBootAllocOutOfMemory = &kernel.Error{Module: "boot_mem_alloc", Message: "out of memory"}
errBootAllocOutOfMemory = &kernel.Error{Module: "boot_mem_alloc", Message: "out of memory"}
)
// BootMemAllocator implements a rudimentary physical memory allocator which is used
@@ -63,13 +57,8 @@ func (alloc *BootMemAllocator) Init() {
// AllocFrame scans the system memory regions reported by the bootloader and
// reserves the next available free frame.
//
// AllocFrame returns an error if no more memory can be allocated or when the
// requested page order is > 0.
func (alloc *BootMemAllocator) AllocFrame(order mem.PageOrder) (pmm.Frame, *kernel.Error) {
if order > 0 {
return pmm.InvalidFrame, errBootAllocUnsupportedPageSize
}
// AllocFrame returns an error if no more memory can be allocated.
func (alloc *BootMemAllocator) AllocFrame() (pmm.Frame, *kernel.Error) {
var (
foundPageIndex int64 = -1
regionStartPageIndex, regionEndPageIndex int64

View File

@@ -36,7 +36,7 @@ func TestBootMemoryAllocator(t *testing.T) {
allocFrameCount uint64
)
for alloc.Init(); ; allocFrameCount++ {
frame, err := alloc.AllocFrame(mem.PageOrder(0))
frame, err := alloc.AllocFrame()
if err != nil {
if err == errBootAllocOutOfMemory {
break
@@ -57,11 +57,6 @@ func TestBootMemoryAllocator(t *testing.T) {
if allocFrameCount != totalFreeFrames {
t.Fatalf("expected allocator to allocate %d frames; allocated %d", totalFreeFrames, allocFrameCount)
}
// This allocator only works with order(0) blocks
if frame, err := alloc.AllocFrame(mem.PageOrder(1)); err != errBootAllocUnsupportedPageSize || frame.Valid() {
t.Fatalf("expected allocator to return errBootAllocUnsupportedPageSize and an invalid frame when requested to allocate a block with order > 0; got %v, %v", err, frame)
}
}
var (