From b881b2639dabca022af444b8e8c97b1622b3879a Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Mon, 1 Jun 2020 23:40:19 -0700 Subject: [PATCH] [kernel] Remove last of old allocator interface Removing the `allocator.h` file defining the `kutil::allocator` interface, now that explicit allocators are not being passed around. Also removed the unused `frame_allocator::raw_allocator` class and `kutil::invalid_allocator` object. Tags: memory --- src/kernel/frame_allocator.cpp | 26 ++-------------- src/kernel/frame_allocator.h | 17 ---------- src/kernel/scheduler.h | 1 - src/libraries/kutil/heap_allocator.cpp | 17 ---------- src/libraries/kutil/include/kutil/allocator.h | 31 ------------------- .../kutil/include/kutil/heap_allocator.h | 8 ++--- src/libraries/kutil/include/kutil/vector.h | 1 - src/libraries/kutil/include/kutil/vm_space.h | 1 - 8 files changed, 5 insertions(+), 97 deletions(-) delete mode 100644 src/libraries/kutil/include/kutil/allocator.h diff --git a/src/kernel/frame_allocator.cpp b/src/kernel/frame_allocator.cpp index f4ecd1f..bee3d72 100644 --- a/src/kernel/frame_allocator.cpp +++ b/src/kernel/frame_allocator.cpp @@ -1,3 +1,4 @@ +#include "kernel_memory.h" #include "kutil/assert.h" #include "kutil/memory.h" #include "frame_allocator.h" @@ -17,30 +18,7 @@ frame_block::compare(const frame_block *rhs) const } -frame_allocator::raw_alloc::raw_alloc(frame_allocator &fa) : m_fa(fa) {} - -void * -frame_allocator::raw_alloc::allocate(size_t size) -{ - kassert(size <= frame_size, "Raw allocator only allocates a single page"); - - uintptr_t addr = 0; - if (size <= frame_size) - m_fa.allocate(1, &addr); - return reinterpret_cast(addr + page_offset); -} - -void -frame_allocator::raw_alloc::free(void *p) -{ - m_fa.free(reinterpret_cast(p), 1); -} - - -frame_allocator::frame_allocator() : - m_raw_alloc(*this) -{ -} +frame_allocator::frame_allocator() {} size_t frame_allocator::allocate(size_t count, uintptr_t *address) diff --git a/src/kernel/frame_allocator.h b/src/kernel/frame_allocator.h index 412c4b0..ada2c5f 100644 --- a/src/kernel/frame_allocator.h +++ b/src/kernel/frame_allocator.h @@ -4,7 +4,6 @@ #include -#include "kutil/allocator.h" #include "kutil/linked_list.h" struct frame_block; @@ -30,23 +29,7 @@ public: /// \arg count The number of frames to be freed void free(uintptr_t address, size_t count); - /// Get a memory allocator that allocates raw pages - /// \returns The allocator ojbect - kutil::allocator & raw_allocator() { return m_raw_alloc; } - private: - class raw_alloc : - public kutil::allocator - { - public: - raw_alloc(frame_allocator &fa); - virtual void * allocate(size_t size) override; - virtual void free(void *p) override; - private: - frame_allocator &m_fa; - }; - - raw_alloc m_raw_alloc; frame_block_list m_free; ///< Free frames list frame_allocator(const frame_allocator &) = delete; diff --git a/src/kernel/scheduler.h b/src/kernel/scheduler.h index 245673f..d9f77d5 100644 --- a/src/kernel/scheduler.h +++ b/src/kernel/scheduler.h @@ -3,7 +3,6 @@ /// The task scheduler and related definitions #include -#include "kutil/allocator.h" #include "process.h" class lapic; diff --git a/src/libraries/kutil/heap_allocator.cpp b/src/libraries/kutil/heap_allocator.cpp index 2cc60ca..4da4b54 100644 --- a/src/libraries/kutil/heap_allocator.cpp +++ b/src/libraries/kutil/heap_allocator.cpp @@ -157,21 +157,4 @@ heap_allocator::pop_free(unsigned size) return block; } - -class invalid_allocator : - public allocator -{ -public: - virtual void * allocate(size_t) override { - kassert(false, "Attempting to allocate from allocator::invalid"); - return nullptr; - } - - virtual void free(void *) override { - kassert(false, "Attempting to free from allocator::invalid"); - } -} _invalid_allocator; - -allocator &allocator::invalid = _invalid_allocator; - } // namespace kutil diff --git a/src/libraries/kutil/include/kutil/allocator.h b/src/libraries/kutil/include/kutil/allocator.h deleted file mode 100644 index b7420fe..0000000 --- a/src/libraries/kutil/include/kutil/allocator.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -/// \file allocator.h -/// Allocator interface - -#include -#include "kernel_memory.h" - -namespace kutil { - -class allocator -{ -public: - /// Allocate memory. - /// \arg length The amount of memory to allocate, in bytes - /// \returns A pointer to the allocated memory, or nullptr if - /// allocation failed. - virtual void * allocate(size_t size) = 0; - - /// Free a previous allocation. - /// \arg p A pointer previously retuned by allocate() - virtual void free(void *p) = 0; - - template - inline T * allocate(unsigned count) { - return reinterpret_cast(allocate(count * sizeof(T))); - } - - static allocator &invalid; -}; - -} // namespace kutil diff --git a/src/libraries/kutil/include/kutil/heap_allocator.h b/src/libraries/kutil/include/kutil/heap_allocator.h index b74b8d2..379a5ce 100644 --- a/src/libraries/kutil/include/kutil/heap_allocator.h +++ b/src/libraries/kutil/include/kutil/heap_allocator.h @@ -3,14 +3,12 @@ /// A buddy allocator for a memory heap #include -#include "kutil/allocator.h" namespace kutil { /// Allocator for a given heap range -class heap_allocator : - public allocator +class heap_allocator { public: /// Default constructor creates a valid but empty heap. @@ -25,11 +23,11 @@ public: /// \arg length The amount of memory to allocate, in bytes /// \returns A pointer to the allocated memory, or nullptr if /// allocation failed. - virtual void * allocate(size_t length) override; + virtual void * allocate(size_t length); /// Free a previous allocation. /// \arg p A pointer previously retuned by allocate() - virtual void free(void *p) override; + virtual void free(void *p); /// Minimum block size is (2^min_size). Must be at least 6. static const unsigned min_size = 6; diff --git a/src/libraries/kutil/include/kutil/vector.h b/src/libraries/kutil/include/kutil/vector.h index c9152e4..ce0eaf4 100644 --- a/src/libraries/kutil/include/kutil/vector.h +++ b/src/libraries/kutil/include/kutil/vector.h @@ -4,7 +4,6 @@ #include #include -#include "kutil/allocator.h" #include "kutil/memory.h" namespace kutil { diff --git a/src/libraries/kutil/include/kutil/vm_space.h b/src/libraries/kutil/include/kutil/vm_space.h index cf135ae..feeb341 100644 --- a/src/libraries/kutil/include/kutil/vm_space.h +++ b/src/libraries/kutil/include/kutil/vm_space.h @@ -3,7 +3,6 @@ /// Structure for tracking a range of virtual memory addresses #include -#include "kutil/allocator.h" #include "kutil/avl_tree.h" namespace kutil {