[kernel] Change heap alloc for better alignment

Created a new util/node_map.h that implements a map that grows in-place.
Now this is used for tracking blocks' size orders, instead of a header
at the start of the memory block. This allows the whole buddy block to
be allocated, allowing for page-aligned (or greater) blocks to be
requested from the heap.
This commit is contained in:
Justin C. Miller
2022-10-02 17:27:21 -07:00
parent 11b61ab345
commit e90647d498
9 changed files with 518 additions and 144 deletions

View File

@@ -1,6 +1,10 @@
#include <util/hash.h>
#include "test_case.h"
constexpr static uint64_t hash1_expected = 0x3d8342e701016873;
constexpr static uint64_t hash3_expected = 0xf0ac589d837f11b8;
constexpr static uint64_t hash4_expected = 0x034742bc87c5c1bc;
class hash_tests :
public test::fixture
{
@@ -8,19 +12,17 @@ class hash_tests :
TEST_CASE( hash_tests, equality_test64 )
{
const auto hash1 = static_cast<unsigned>("hash1!"_id);
CHECK( hash1 == 210, "hash gave unexpected value");
const uint64_t hash1 = "hash1!"_id;
const uint64_t hash2 = "hash1!"_id;
const uint64_t hash3 = "not hash1!"_id;
const uint64_t hash4 = "another thing that's longer"_id;
const auto hash2 = static_cast<unsigned>("hash1!"_id);
CHECK(hash1 == hash2, "hashes of equal strings should be equal");
const auto hash3 = static_cast<unsigned>("not hash1!"_id);
CHECK(hash1 != hash3, "hashes of different strings should not be equal");
CHECK(hash3 == 37, "hash gave unexpected value");
const auto hash4 = static_cast<unsigned>("another thing that's longer"_id);
CHECK(hash1 != hash4, "hashes of different strings should not be equal");
CHECK(hash4 == 212, "hash gave unexpected value");
CHECK( hash1 == hash1_expected, "hash gave unexpected value");
CHECK( hash1 == hash2, "hashes of equal strings should be equal");
CHECK( hash1 != hash3, "hashes of different strings should not be equal");
CHECK( hash3 == hash3_expected, "hash gave unexpected value");
CHECK( hash1 != hash4, "hashes of different strings should not be equal");
CHECK( hash4 == hash4_expected, "hash gave unexpected value");
}
TEST_CASE( hash_tests, equality_test8 )

View File

@@ -1,5 +1,6 @@
#include <vector>
#include <util/map.h>
#include <util/node_map.h>
#include "test_case.h"
#include "test_rng.h"
@@ -9,9 +10,59 @@ struct map_tests :
{
};
struct map_item
{
uint64_t key;
uint64_t value;
};
uint64_t & get_map_key(map_item &mi) { return mi.key; }
TEST_CASE( map_tests, node_map )
{
util::node_map<uint64_t, map_item> map;
map.insert({12, 14});
map.insert({13, 15});
map.insert({14, 16});
map.insert({15, 17});
map.insert({16, 18});
map.insert({20, 22});
map.insert({24, 26});
CHECK( map.count() == 7, "Map returned incorred count()" );
auto *item = map.find(12);
CHECK( item, "Did not find inserted item" );
CHECK( item && item->key == 12 && item->value == 14,
"Found incorrect item" );
item = map.find(40);
CHECK( !item, "Found non-inserted item" );
bool found = map.erase(12);
CHECK( found, "Failed to delete inserted item" );
item = map.find(12);
CHECK( !item, "Found item after delete" );
// Force the map to grow
map.insert({35, 38});
map.insert({36, 39});
map.insert({37, 40});
CHECK( map.count() == 9, "Map returned incorred count()" );
item = map.find(13);
CHECK( item, "Did not find inserted item after grow()" );
CHECK( item && item->key == 13 && item->value == 15,
"Found incorrect item after grow()" );
}
TEST_CASE( map_tests, insert )
{
test::rng rng {12345};
double foo = 1.02345;
foo *= 4.6e4;
std::vector<int> ints;
for (int i = 0; i < 1000; ++i)