mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:48:12 +00:00
LibWeb: Make VM allocation atomic for kernel regions
Instead of first allocating the VM range, and then inserting a region with that range into the MM region tree, we now do both things in a single atomic operation: - RegionTree::place_anywhere(Region&, size, alignment) - RegionTree::place_specifically(Region&, address, size) To reduce the number of things we do while locking the region tree, we also require callers to provide a constructed Region object.
This commit is contained in:
parent
cbf52d474c
commit
e852a69a06
7 changed files with 85 additions and 57 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <AK/Format.h>
|
||||
#include <Kernel/Memory/MemoryManager.h>
|
||||
#include <Kernel/Memory/RegionTree.h>
|
||||
#include <Kernel/Random.h>
|
||||
|
||||
|
@ -142,10 +143,28 @@ ErrorOr<VirtualRange> RegionTree::try_allocate_randomized(size_t size, size_t al
|
|||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<Region>> RegionTree::allocate_unbacked_anywhere(size_t size, size_t alignment)
|
||||
{
|
||||
auto region = TRY(Region::create_unbacked());
|
||||
TRY(place_anywhere(*region, size, alignment));
|
||||
return region;
|
||||
}
|
||||
|
||||
ErrorOr<void> RegionTree::place_anywhere(Region& region, size_t size, size_t alignment)
|
||||
{
|
||||
SpinlockLocker locker(m_lock);
|
||||
auto range = TRY(try_allocate_anywhere(size, alignment));
|
||||
return Region::create_unbacked(range);
|
||||
region.m_range = range;
|
||||
m_regions.insert(region.vaddr().get(), region);
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> RegionTree::place_specifically(Region& region, VirtualRange const& range)
|
||||
{
|
||||
SpinlockLocker locker(m_lock);
|
||||
auto allocated_range = TRY(try_allocate_specific(range.base(), range.size()));
|
||||
region.m_range = allocated_range;
|
||||
m_regions.insert(region.vaddr().get(), region);
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue