Major refactor of snmalloc (#343)
# Pagemap The Pagemap now stores all the meta-data for the object allocation. The meta-data in the pagemap is effectively a triple of the sizeclass, the remote allocator, and a pointer to a 64 byte block of meta-data for this chunk of memory. By storing the pointer to a block, it allows the pagemap to handle multiple slab sizes without branching on the fast path. There is one entry in the pagemap per 16KiB of address space, but by using the same entry in the pagemap for 4 adjacent entries, then we can treat a 64KiB range can be treated as a single slab of allocations. This change also means there is almost no capability amplification required by the implementation on CHERI for finding meta-data. The only amplification is required, when we change the way a chunk is used to a size of object allocation. # Backend There is a second major aspect of the refactor that there is now a narrow API that abstracts the Pagemap, PAL and address space management. This should better enable the compartmentalisation and makes it easier to produce alternative backends for various research directions. This is a template parameter that can be used to specialised by the front-end in different ways. # Thread local state The thread local state has been refactored into two components, one (called 'localalloc') that is stored directly in the TLS and is constant initialised, and one that is allocated in the address space (called 'coreallloc') which is lazily created and pooled. # Difference This removes Superslabs/Medium slabs as there meta-data is now part of the pagemap.
This commit is contained in:
committed by
GitHub
parent
18d7cc99b6
commit
f0e2ab702a
@@ -19,7 +19,7 @@ class Queue
|
||||
|
||||
Node* new_node(size_t size)
|
||||
{
|
||||
auto result = (Node*)ThreadAlloc::get()->alloc(size);
|
||||
auto result = (Node*)ThreadAlloc::get().alloc(size);
|
||||
result->next = nullptr;
|
||||
return result;
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
return false;
|
||||
|
||||
Node* next = head->next;
|
||||
ThreadAlloc::get()->dealloc(head);
|
||||
ThreadAlloc::get().dealloc(head);
|
||||
head = next;
|
||||
return true;
|
||||
}
|
||||
@@ -107,58 +107,61 @@ int main(int argc, char** argv)
|
||||
{
|
||||
opt::Opt opt(argc, argv);
|
||||
|
||||
if constexpr (pal_supports<LowMemoryNotification, GlobalVirtual::Pal>)
|
||||
{
|
||||
register_for_pal_notifications<GlobalVirtual>();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Pal does not support low-memory notification! Test not run"
|
||||
<< std::endl;
|
||||
return 0;
|
||||
}
|
||||
// TODO reinstate
|
||||
|
||||
#ifdef NDEBUG
|
||||
# if defined(WIN32) && !defined(SNMALLOC_VA_BITS_64)
|
||||
std::cout << "32-bit windows not supported for this test." << std::endl;
|
||||
# else
|
||||
// if constexpr (pal_supports<LowMemoryNotification, GlobalVirtual::Pal>)
|
||||
// {
|
||||
// register_for_pal_notifications<GlobalVirtual>();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// std::cout << "Pal does not support low-memory notification! Test not
|
||||
// run"
|
||||
// << std::endl;
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
bool interactive = opt.has("--interactive");
|
||||
// #ifdef NDEBUG
|
||||
// # if defined(WIN32) && !defined(SNMALLOC_VA_BITS_64)
|
||||
// std::cout << "32-bit windows not supported for this test." << std::endl;
|
||||
// # else
|
||||
|
||||
Queue allocations;
|
||||
// bool interactive = opt.has("--interactive");
|
||||
|
||||
std::cout
|
||||
<< "Expected use:" << std::endl
|
||||
<< " run first instances with --interactive. Wait for first to print "
|
||||
<< std::endl
|
||||
<< " 'No allocations left. Press any key to terminate'" << std::endl
|
||||
<< "watch working set, and start second instance working set of first "
|
||||
<< "should drop to almost zero," << std::endl
|
||||
<< "and second should climb to physical ram." << std::endl
|
||||
<< std::endl;
|
||||
// Queue allocations;
|
||||
|
||||
setup();
|
||||
// std::cout
|
||||
// << "Expected use:" << std::endl
|
||||
// << " run first instances with --interactive. Wait for first to print "
|
||||
// << std::endl
|
||||
// << " 'No allocations left. Press any key to terminate'" << std::endl
|
||||
// << "watch working set, and start second instance working set of first "
|
||||
// << "should drop to almost zero," << std::endl
|
||||
// << "and second should climb to physical ram." << std::endl
|
||||
// << std::endl;
|
||||
|
||||
for (size_t i = 0; i < 10; i++)
|
||||
{
|
||||
reach_pressure(allocations);
|
||||
std::cout << "Pressure " << i << std::endl;
|
||||
// setup();
|
||||
|
||||
reduce_pressure(allocations);
|
||||
}
|
||||
// for (size_t i = 0; i < 10; i++)
|
||||
// {
|
||||
// reach_pressure(allocations);
|
||||
// std::cout << "Pressure " << i << std::endl;
|
||||
|
||||
// Deallocate everything
|
||||
while (allocations.try_remove())
|
||||
;
|
||||
// reduce_pressure(allocations);
|
||||
// }
|
||||
|
||||
if (interactive)
|
||||
{
|
||||
std::cout << "No allocations left. Press any key to terminate" << std::endl;
|
||||
getchar();
|
||||
}
|
||||
# endif
|
||||
#else
|
||||
std::cout << "Release test only." << std::endl;
|
||||
#endif
|
||||
// // Deallocate everything
|
||||
// while (allocations.try_remove())
|
||||
// ;
|
||||
|
||||
// if (interactive)
|
||||
// {
|
||||
// std::cout << "No allocations left. Press any key to terminate" <<
|
||||
// std::endl; getchar();
|
||||
// }
|
||||
// # endif
|
||||
// #else
|
||||
// std::cout << "Release test only." << std::endl;
|
||||
// #endif
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user