1.1 --- a/Makefile Sat Mar 20 16:53:21 2021 +0100
1.2 +++ b/Makefile Sat Mar 20 17:05:31 2021 +0100
1.3 @@ -49,7 +49,7 @@
1.4 PLAIN_SRC_CC_common_server = \
1.5 access_map.cc accessing.cc accessor.cc \
1.6 flexpage.cc file_pager.cc ipc.cc \
1.7 - memory.cc memory_incremental.cc memory_preallocated.cc \
1.8 + memory_incremental.cc memory_preallocated.cc \
1.9 opener_resource.cc opener_context_resource.cc \
1.10 page_mapper.cc page_queue.cc pager.cc pages.cc paging.cc \
1.11 region.cc resource_server.cc simple_pager.cc
2.1 --- a/memory.cc Sat Mar 20 16:53:21 2021 +0100
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,31 +0,0 @@
2.4 -#include "memory.h"
2.5 -
2.6 -#include <stdlib.h>
2.7 -
2.8 -
2.9 -/* Initialise the memory pool with an optional 'limit' in pages. */
2.10 -
2.11 -Memory::Memory(offset_t region_size)
2.12 -: _region_size(region_size)
2.13 -{
2.14 -}
2.15 -
2.16 -/* Allocate a block of the given 'size'. */
2.17 -
2.18 -Region *Memory::allocate(offset_t size)
2.19 -{
2.20 - /* Attempt to allocate aligned memory. */
2.21 -
2.22 - void *current;
2.23 -
2.24 - /* Make the size appropriate for the invocation. */
2.25 -
2.26 - size = round_multiple(size, PAGE_SIZE);
2.27 -
2.28 - if (posix_memalign(¤t, size, size))
2.29 - return NULL;
2.30 -
2.31 - return new Region((offset_t) current, (offset_t) current + size);
2.32 -}
2.33 -
2.34 -// vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/memory.h Sat Mar 20 16:53:21 2021 +0100
3.2 +++ b/memory.h Sat Mar 20 17:05:31 2021 +0100
3.3 @@ -18,9 +18,10 @@
3.4 offset_t _region_size;
3.5
3.6 public:
3.7 - explicit Memory(offset_t region_size=PAGE_SIZE);
3.8 -
3.9 - virtual Region *allocate(offset_t size);
3.10 + explicit Memory(offset_t region_size=PAGE_SIZE)
3.11 + : _region_size(region_size)
3.12 + {
3.13 + }
3.14
3.15 virtual Region *region() = 0;
3.16
4.1 --- a/memory_incremental.cc Sat Mar 20 16:53:21 2021 +0100
4.2 +++ b/memory_incremental.cc Sat Mar 20 17:05:31 2021 +0100
4.3 @@ -1,5 +1,7 @@
4.4 #include "memory_incremental.h"
4.5
4.6 +#include <stdlib.h>
4.7 +
4.8 /* Initialise the memory pool with an optional 'limit' in pages. */
4.9
4.10 MemoryIncremental::MemoryIncremental(unsigned int limit, offset_t region_size)
4.11 @@ -14,6 +16,24 @@
4.12 _limited = false;
4.13 }
4.14
4.15 +/* Allocate a block of the given 'size'. */
4.16 +
4.17 +Region *MemoryIncremental::allocate(offset_t size)
4.18 +{
4.19 + /* Attempt to allocate aligned memory. */
4.20 +
4.21 + void *current;
4.22 +
4.23 + /* Make the size appropriate for the invocation. */
4.24 +
4.25 + size = round_multiple(size, PAGE_SIZE);
4.26 +
4.27 + if (posix_memalign(¤t, size, size))
4.28 + return NULL;
4.29 +
4.30 + return new Region((offset_t) current, (offset_t) current + size);
4.31 +}
4.32 +
4.33 /* Allocate a new region of the configured size rounded to the nearest page. */
4.34
4.35 Region *MemoryIncremental::region()
5.1 --- a/memory_incremental.h Sat Mar 20 16:53:21 2021 +0100
5.2 +++ b/memory_incremental.h Sat Mar 20 17:05:31 2021 +0100
5.3 @@ -12,6 +12,8 @@
5.4 unsigned int _limit;
5.5 bool _limited;
5.6
5.7 + virtual Region *allocate(offset_t size);
5.8 +
5.9 public:
5.10 explicit MemoryIncremental(unsigned int limit, offset_t region_size=PAGE_SIZE);
5.11
6.1 --- a/memory_preallocated.cc Sat Mar 20 16:53:21 2021 +0100
6.2 +++ b/memory_preallocated.cc Sat Mar 20 17:05:31 2021 +0100
6.3 @@ -1,23 +1,43 @@
6.4 #include "memory_preallocated.h"
6.5
6.6 +#include <stdlib.h>
6.7 +
6.8 /* Initialise the memory pool with a mandatory 'limit' in pages. */
6.9
6.10 MemoryPreallocated::MemoryPreallocated(unsigned int limit, offset_t region_size)
6.11 : Memory(region_size), _limit(limit)
6.12 {
6.13 - while (limit > 0)
6.14 - {
6.15 - Region *r = region();
6.16 + /* Allocate all memory at once, rounding each unit to the nearest page
6.17 + size. */
6.18 +
6.19 + offset_t rounded_size = round_multiple(region_size, PAGE_SIZE);
6.20 + offset_t total_size = limit * rounded_size;
6.21 + offset_t current;
6.22
6.23 - if (r != NULL)
6.24 - _free.push_back(r);
6.25 - else
6.26 - break;
6.27 + if (posix_memalign((void **) ¤t, total_size, total_size))
6.28 + return;
6.29 +
6.30 + /* Split the memory up into separate regions. */
6.31
6.32 + while (limit)
6.33 + {
6.34 + _free.push_back(new Region(current, current + rounded_size));
6.35 + current += rounded_size;
6.36 limit--;
6.37 }
6.38 }
6.39
6.40 +/* Free all allocated regions. */
6.41 +
6.42 +MemoryPreallocated::~MemoryPreallocated()
6.43 +{
6.44 + for (std::list<Region *>::iterator it = _free.begin(); it != _free.end(); it++)
6.45 + delete *it;
6.46 +
6.47 + for (std::set<Region *>::iterator it = _used.begin(); it != _used.end(); it++)
6.48 + delete *it;
6.49 +}
6.50 +
6.51 /* Allocate a new region of the configured size rounded to the nearest page. */
6.52
6.53 Region *MemoryPreallocated::region()
7.1 --- a/memory_preallocated.h Sat Mar 20 16:53:21 2021 +0100
7.2 +++ b/memory_preallocated.h Sat Mar 20 17:05:31 2021 +0100
7.3 @@ -19,6 +19,8 @@
7.4 public:
7.5 explicit MemoryPreallocated(unsigned int limit, offset_t region_size=PAGE_SIZE);
7.6
7.7 + virtual ~MemoryPreallocated();
7.8 +
7.9 virtual Region *region();
7.10
7.11 virtual void release(Region *region);