1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:38:11 +00:00

Kernel: Remove ContiguousVMObject, let AnonymousVMObject do the job

We don't need an entirely separate VMObject subclass to influence the
location of the physical pages.

Instead, we simply allocate enough physically contiguous memory first,
and then pass it to the AnonymousVMObject constructor that takes a span
of physical pages.
This commit is contained in:
Andreas Kling 2021-07-25 18:37:11 +02:00
parent 9a701eafc4
commit 6a537ceef1
10 changed files with 18 additions and 89 deletions

View file

@ -70,6 +70,14 @@ RefPtr<AnonymousVMObject> AnonymousVMObject::try_create_with_size(size_t size, A
return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(size, commit));
}
RefPtr<AnonymousVMObject> AnonymousVMObject::try_create_physically_contiguous_with_size(size_t size)
{
auto contiguous_physical_pages = MM.allocate_contiguous_supervisor_physical_pages(size);
if (contiguous_physical_pages.is_empty())
return {};
return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(contiguous_physical_pages.span()));
}
RefPtr<AnonymousVMObject> AnonymousVMObject::try_create_purgeable_with_size(size_t size, AllocationStrategy commit)
{
if (commit == AllocationStrategy::Reserve || commit == AllocationStrategy::AllocateNow) {

View file

@ -38,6 +38,7 @@ public:
static RefPtr<AnonymousVMObject> try_create_for_physical_range(PhysicalAddress paddr, size_t size);
static RefPtr<AnonymousVMObject> try_create_with_physical_pages(Span<NonnullRefPtr<PhysicalPage>>);
static RefPtr<AnonymousVMObject> try_create_purgeable_with_size(size_t, AllocationStrategy);
static RefPtr<AnonymousVMObject> try_create_physically_contiguous_with_size(size_t);
virtual RefPtr<VMObject> try_clone() override;
[[nodiscard]] NonnullRefPtr<PhysicalPage> allocate_committed_page(Badge<Region>);

View file

@ -1,44 +0,0 @@
/*
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/VM/ContiguousVMObject.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/PhysicalPage.h>
namespace Kernel {
RefPtr<ContiguousVMObject> ContiguousVMObject::try_create_with_size(size_t size)
{
auto contiguous_physical_pages = MM.allocate_contiguous_supervisor_physical_pages(size);
if (contiguous_physical_pages.is_empty())
return {};
return adopt_ref_if_nonnull(new (nothrow) ContiguousVMObject(size, contiguous_physical_pages));
}
ContiguousVMObject::ContiguousVMObject(size_t size, NonnullRefPtrVector<PhysicalPage>& contiguous_physical_pages)
: VMObject(size)
{
for (size_t i = 0; i < page_count(); i++) {
physical_pages()[i] = contiguous_physical_pages[i];
dbgln_if(CONTIGUOUS_VMOBJECT_DEBUG, "Contiguous page[{}]: {}", i, physical_pages()[i]->paddr());
}
}
ContiguousVMObject::ContiguousVMObject(ContiguousVMObject const& other)
: VMObject(other)
{
}
ContiguousVMObject::~ContiguousVMObject()
{
}
RefPtr<VMObject> ContiguousVMObject::try_clone()
{
VERIFY_NOT_REACHED();
}
}

View file

@ -1,34 +0,0 @@
/*
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/PhysicalAddress.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/VMObject.h>
namespace Kernel {
class ContiguousVMObject final : public VMObject {
public:
virtual ~ContiguousVMObject() override;
static RefPtr<ContiguousVMObject> try_create_with_size(size_t);
private:
explicit ContiguousVMObject(size_t, NonnullRefPtrVector<PhysicalPage>&);
explicit ContiguousVMObject(ContiguousVMObject const&);
virtual StringView class_name() const override { return "ContiguousVMObject"sv; }
virtual RefPtr<VMObject> try_clone() override;
ContiguousVMObject& operator=(ContiguousVMObject const&) = delete;
ContiguousVMObject& operator=(ContiguousVMObject&&) = delete;
ContiguousVMObject(ContiguousVMObject&&) = delete;
virtual bool is_contiguous() const override { return true; }
};
}

View file

@ -17,7 +17,6 @@
#include <Kernel/Sections.h>
#include <Kernel/StdLib.h>
#include <Kernel/VM/AnonymousVMObject.h>
#include <Kernel/VM/ContiguousVMObject.h>
#include <Kernel/VM/MemoryManager.h>
#include <Kernel/VM/PageDirectory.h>
#include <Kernel/VM/PhysicalRegion.h>
@ -705,7 +704,7 @@ OwnPtr<Region> MemoryManager::allocate_contiguous_kernel_region(size_t size, Str
auto range = kernel_page_directory().range_allocator().allocate_anywhere(size);
if (!range.has_value())
return {};
auto vmobject = ContiguousVMObject::try_create_with_size(size);
auto vmobject = AnonymousVMObject::try_create_physically_contiguous_with_size(size);
if (!vmobject) {
kernel_page_directory().range_allocator().deallocate(range.value());
return {};