# HG changeset patch # User Paul Boddie # Date 1612391628 -3600 # Node ID 2392a95024c11ced6de798e5b73e154421d74164 # Parent 5ffdabc875ca5a8a460c5c8e36072dcd88f18c00 Removed the largely superfluous memory map functionality. diff -r 5ffdabc875ca -r 2392a95024c1 Makefile --- a/Makefile Wed Feb 03 22:22:30 2021 +0100 +++ b/Makefile Wed Feb 03 23:33:48 2021 +0100 @@ -42,7 +42,7 @@ PLAIN_SRC_CC_dstest_server = \ access_map.cc accessing.cc accessor.cc \ dstest_server.cc flexpage.cc file_pager.cc \ - ipc.cc memory.cc memory_map.cc \ + ipc.cc memory.cc \ opener_resource.cc opener_context_resource.cc \ page_mapper.cc page_queue.cc pager.cc pages.cc paging.cc \ region.cc resource_server.cc simple_pager.cc \ diff -r 5ffdabc875ca -r 2392a95024c1 memory.cc --- a/memory.cc Wed Feb 03 22:22:30 2021 +0100 +++ b/memory.cc Wed Feb 03 23:33:48 2021 +0100 @@ -1,12 +1,6 @@ #include "memory.h" -#include "memory_map.h" - - -/* Global memory allocator. */ - -extern Allocator allocator; - +#include /* Initialise the memory pool with an optional 'limit' in pages. */ @@ -23,6 +17,24 @@ _limited = false; } +/* Allocate a block of the given 'size'. */ + +Region *Memory::allocate(offset_t size) +{ + /* Attempt to allocate aligned memory. */ + + void *current; + + /* Make the size appropriate for the invocation. */ + + size = round_multiple(size, PAGE_SIZE); + + if (posix_memalign(¤t, size, size)) + return NULL; + + return new Region((offset_t) current, (offset_t) current + size); +} + /* Allocate a new region of the given 'size' rounded to the nearest page. */ Region *Memory::region(offset_t size) @@ -38,7 +50,7 @@ { /* Attempt to allocate aligned memory. */ - Region *region = allocator.region(rounded); + Region *region = allocate(rounded); if (region == NULL) return NULL; @@ -72,8 +84,6 @@ if (_limited) _limit += pages; - allocator.remove(region); - delete region; } diff -r 5ffdabc875ca -r 2392a95024c1 memory.h --- a/memory.h Wed Feb 03 22:22:30 2021 +0100 +++ b/memory.h Wed Feb 03 23:33:48 2021 +0100 @@ -25,6 +25,8 @@ explicit Memory(); + Region *allocate(offset_t size); + Region *region(offset_t size); Region *region(); diff -r 5ffdabc875ca -r 2392a95024c1 memory_map.cc --- a/memory_map.cc Wed Feb 03 22:22:30 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -#include - -#include "memory_map.h" -#include "memory_utils.h" - - - -/* Global memory allocator. */ - -Allocator allocator; - - - -/* Region management. */ - -void MemoryMap::insert(Region *region) -{ - std::lock_guard guard(_lock); - - _regions.insert(_MemoryMapEntry(region->start, region)); -} - -void MemoryMap::remove(Region *region) -{ - std::lock_guard guard(_lock); - - _MemoryMap::iterator entry = _regions.find(region->start); - - if (entry != _regions.end()) - _regions.erase(entry); -} - -/* Show the memory state. */ - -void MemoryMap::show(std::ostringstream &buffer) -{ - std::lock_guard guard(_lock); - - _MemoryMap::iterator it; - - buffer << "Mem: "; - - for (it = _regions.begin(); it != _regions.end(); it++) - { - it->second->state.show(buffer); - buffer << " "; - } - - buffer << std::endl; -} - - - -/* Allocate a block of the given 'size'. */ - -Region *Allocator::region(offset_t size) -{ - /* Attempt to allocate aligned memory. */ - - void *current; - - /* Make the size appropriate for the invocation. */ - - size = round_multiple(size, PAGE_SIZE); - - if (posix_memalign(¤t, size, size)) - return NULL; - - Region *region = new Region((offset_t) current, (offset_t) current + size); - - insert(region); - return region; -} - -/* Release the allocated 'region'. */ - -void Allocator::release(Region *region) -{ - remove(region); - delete region; -} - -// vim: tabstop=4 expandtab shiftwidth=4 diff -r 5ffdabc875ca -r 2392a95024c1 memory_map.h --- a/memory_map.h Wed Feb 03 22:22:30 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "region.h" -#include "types.h" - - - -/* Memory map entry. */ - -typedef std::map _MemoryMap; -typedef std::pair _MemoryMapEntry; - - - -/* Memory organised as a collection of regions. */ - -class MemoryMap -{ -protected: - std::mutex _lock; - _MemoryMap _regions; - -public: - /* Region maintenance. */ - - void insert(Region *region); - - void remove(Region *region); - - /* Debugging methods. */ - - void show(std::ostringstream &buffer); -}; - - - -/* An allocator abstraction. */ - -class Allocator : public MemoryMap -{ -public: - Region *region(offset_t size); - - void release(Region *region); -}; - -// vim: tabstop=4 expandtab shiftwidth=4