mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
faa6395a11
This commit introduces VMObject::remap_regions_single_page(). This method remaps a single page in all regions associated with a VMObject. This is intended to be a more efficient replacement for remap_regions() in cases where only a single page needs to be remapped. This commit also updates the cow page fault handling code to use this new method.
58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Singleton.h>
|
|
#include <Kernel/Memory/MemoryManager.h>
|
|
#include <Kernel/Memory/VMObject.h>
|
|
|
|
namespace Kernel::Memory {
|
|
|
|
static Singleton<SpinlockProtected<VMObject::AllInstancesList, LockRank::None>> s_all_instances;
|
|
|
|
SpinlockProtected<VMObject::AllInstancesList, LockRank::None>& VMObject::all_instances()
|
|
{
|
|
return s_all_instances;
|
|
}
|
|
|
|
ErrorOr<FixedArray<RefPtr<PhysicalRAMPage>>> VMObject::try_clone_physical_pages() const
|
|
{
|
|
return m_physical_pages.clone();
|
|
}
|
|
|
|
ErrorOr<FixedArray<RefPtr<PhysicalRAMPage>>> VMObject::try_create_physical_pages(size_t size)
|
|
{
|
|
return FixedArray<RefPtr<PhysicalRAMPage>>::create(ceil_div(size, static_cast<size_t>(PAGE_SIZE)));
|
|
}
|
|
|
|
VMObject::VMObject(FixedArray<RefPtr<PhysicalRAMPage>>&& new_physical_pages)
|
|
: m_physical_pages(move(new_physical_pages))
|
|
{
|
|
all_instances().with([&](auto& list) { list.append(*this); });
|
|
}
|
|
|
|
VMObject::~VMObject()
|
|
{
|
|
VERIFY(m_regions.is_empty());
|
|
}
|
|
|
|
void VMObject::remap_regions()
|
|
{
|
|
for_each_region([](Region& region) {
|
|
region.remap();
|
|
});
|
|
}
|
|
|
|
bool VMObject::remap_regions_one_page(size_t page_index, NonnullRefPtr<PhysicalRAMPage> page)
|
|
{
|
|
bool success = true;
|
|
for_each_region([&](Region& region) {
|
|
if (!region.remap_vmobject_page(page_index, *page))
|
|
success = false;
|
|
});
|
|
return success;
|
|
}
|
|
|
|
}
|