From d9d33627223f4b713b0ca17ccd99b6a15c89745e Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Thu, 10 Feb 2022 19:39:17 +0200 Subject: [PATCH] Kernel: Make SharedInodeVMObject pages Bitmap allocation OOM-fallible --- Kernel/Memory/InodeVMObject.cpp | 8 ++++---- Kernel/Memory/InodeVMObject.h | 4 ++-- Kernel/Memory/PrivateInodeVMObject.cpp | 14 ++++++++------ Kernel/Memory/PrivateInodeVMObject.h | 4 ++-- Kernel/Memory/SharedInodeVMObject.cpp | 14 ++++++++------ Kernel/Memory/SharedInodeVMObject.h | 4 ++-- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Kernel/Memory/InodeVMObject.cpp b/Kernel/Memory/InodeVMObject.cpp index 96424544166..a072968d852 100644 --- a/Kernel/Memory/InodeVMObject.cpp +++ b/Kernel/Memory/InodeVMObject.cpp @@ -9,17 +9,17 @@ namespace Kernel::Memory { -InodeVMObject::InodeVMObject(Inode& inode, FixedArray>&& new_physical_pages) +InodeVMObject::InodeVMObject(Inode& inode, FixedArray>&& new_physical_pages, Bitmap dirty_pages) : VMObject(move(new_physical_pages)) , m_inode(inode) - , m_dirty_pages(Bitmap::try_create(page_count(), false).release_value_but_fixme_should_propagate_errors()) + , m_dirty_pages(move(dirty_pages)) { } -InodeVMObject::InodeVMObject(InodeVMObject const& other, FixedArray>&& new_physical_pages) +InodeVMObject::InodeVMObject(InodeVMObject const& other, FixedArray>&& new_physical_pages, Bitmap dirty_pages) : VMObject(move(new_physical_pages)) , m_inode(other.m_inode) - , m_dirty_pages(Bitmap::try_create(page_count(), false).release_value_but_fixme_should_propagate_errors()) + , m_dirty_pages(move(dirty_pages)) { for (size_t i = 0; i < page_count(); ++i) m_dirty_pages.set(i, other.m_dirty_pages.get(i)); diff --git a/Kernel/Memory/InodeVMObject.h b/Kernel/Memory/InodeVMObject.h index 33898faf109..6f9500c9336 100644 --- a/Kernel/Memory/InodeVMObject.h +++ b/Kernel/Memory/InodeVMObject.h @@ -28,8 +28,8 @@ public: u32 executable_mappings() const; protected: - explicit InodeVMObject(Inode&, FixedArray>&&); - explicit InodeVMObject(InodeVMObject const&, FixedArray>&&); + explicit InodeVMObject(Inode&, FixedArray>&&, Bitmap dirty_pages); + explicit InodeVMObject(InodeVMObject const&, FixedArray>&&, Bitmap dirty_pages); InodeVMObject& operator=(InodeVMObject const&) = delete; InodeVMObject& operator=(InodeVMObject&&) = delete; diff --git a/Kernel/Memory/PrivateInodeVMObject.cpp b/Kernel/Memory/PrivateInodeVMObject.cpp index adc965b7912..623e02776f5 100644 --- a/Kernel/Memory/PrivateInodeVMObject.cpp +++ b/Kernel/Memory/PrivateInodeVMObject.cpp @@ -12,22 +12,24 @@ namespace Kernel::Memory { ErrorOr> PrivateInodeVMObject::try_create_with_inode(Inode& inode) { auto new_physical_pages = TRY(VMObject::try_create_physical_pages(inode.size())); - return adopt_nonnull_ref_or_enomem(new (nothrow) PrivateInodeVMObject(inode, move(new_physical_pages))); + auto dirty_pages = TRY(Bitmap::try_create(new_physical_pages.size(), false)); + return adopt_nonnull_ref_or_enomem(new (nothrow) PrivateInodeVMObject(inode, move(new_physical_pages), move(dirty_pages))); } ErrorOr> PrivateInodeVMObject::try_clone() { auto new_physical_pages = TRY(this->try_clone_physical_pages()); - return adopt_nonnull_ref_or_enomem(new (nothrow) PrivateInodeVMObject(*this, move(new_physical_pages))); + auto dirty_pages = TRY(Bitmap::try_create(new_physical_pages.size(), false)); + return adopt_nonnull_ref_or_enomem(new (nothrow) PrivateInodeVMObject(*this, move(new_physical_pages), move(dirty_pages))); } -PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, FixedArray>&& new_physical_pages) - : InodeVMObject(inode, move(new_physical_pages)) +PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, FixedArray>&& new_physical_pages, Bitmap dirty_pages) + : InodeVMObject(inode, move(new_physical_pages), move(dirty_pages)) { } -PrivateInodeVMObject::PrivateInodeVMObject(PrivateInodeVMObject const& other, FixedArray>&& new_physical_pages) - : InodeVMObject(other, move(new_physical_pages)) +PrivateInodeVMObject::PrivateInodeVMObject(PrivateInodeVMObject const& other, FixedArray>&& new_physical_pages, Bitmap dirty_pages) + : InodeVMObject(other, move(new_physical_pages), move(dirty_pages)) { } diff --git a/Kernel/Memory/PrivateInodeVMObject.h b/Kernel/Memory/PrivateInodeVMObject.h index b3efadcc7ee..6b480832e39 100644 --- a/Kernel/Memory/PrivateInodeVMObject.h +++ b/Kernel/Memory/PrivateInodeVMObject.h @@ -23,8 +23,8 @@ public: private: virtual bool is_private_inode() const override { return true; } - explicit PrivateInodeVMObject(Inode&, FixedArray>&&); - explicit PrivateInodeVMObject(PrivateInodeVMObject const&, FixedArray>&&); + explicit PrivateInodeVMObject(Inode&, FixedArray>&&, Bitmap dirty_pages); + explicit PrivateInodeVMObject(PrivateInodeVMObject const&, FixedArray>&&, Bitmap dirty_pages); virtual StringView class_name() const override { return "PrivateInodeVMObject"sv; } diff --git a/Kernel/Memory/SharedInodeVMObject.cpp b/Kernel/Memory/SharedInodeVMObject.cpp index 650455ef065..fdda7d78608 100644 --- a/Kernel/Memory/SharedInodeVMObject.cpp +++ b/Kernel/Memory/SharedInodeVMObject.cpp @@ -16,7 +16,8 @@ ErrorOr> SharedInodeVMObject::try_create_with if (auto shared_vmobject = inode.shared_vmobject()) return shared_vmobject.release_nonnull(); auto new_physical_pages = TRY(VMObject::try_create_physical_pages(size)); - auto vmobject = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SharedInodeVMObject(inode, move(new_physical_pages)))); + auto dirty_pages = TRY(Bitmap::try_create(new_physical_pages.size(), false)); + auto vmobject = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) SharedInodeVMObject(inode, move(new_physical_pages), move(dirty_pages)))); vmobject->inode().set_shared_vmobject(*vmobject); return vmobject; } @@ -24,16 +25,17 @@ ErrorOr> SharedInodeVMObject::try_create_with ErrorOr> SharedInodeVMObject::try_clone() { auto new_physical_pages = TRY(this->try_clone_physical_pages()); - return adopt_nonnull_ref_or_enomem(new (nothrow) SharedInodeVMObject(*this, move(new_physical_pages))); + auto dirty_pages = TRY(Bitmap::try_create(new_physical_pages.size(), false)); + return adopt_nonnull_ref_or_enomem(new (nothrow) SharedInodeVMObject(*this, move(new_physical_pages), move(dirty_pages))); } -SharedInodeVMObject::SharedInodeVMObject(Inode& inode, FixedArray>&& new_physical_pages) - : InodeVMObject(inode, move(new_physical_pages)) +SharedInodeVMObject::SharedInodeVMObject(Inode& inode, FixedArray>&& new_physical_pages, Bitmap dirty_pages) + : InodeVMObject(inode, move(new_physical_pages), move(dirty_pages)) { } -SharedInodeVMObject::SharedInodeVMObject(SharedInodeVMObject const& other, FixedArray>&& new_physical_pages) - : InodeVMObject(other, move(new_physical_pages)) +SharedInodeVMObject::SharedInodeVMObject(SharedInodeVMObject const& other, FixedArray>&& new_physical_pages, Bitmap dirty_pages) + : InodeVMObject(other, move(new_physical_pages), move(dirty_pages)) { } diff --git a/Kernel/Memory/SharedInodeVMObject.h b/Kernel/Memory/SharedInodeVMObject.h index 2c38eead016..75d3637808a 100644 --- a/Kernel/Memory/SharedInodeVMObject.h +++ b/Kernel/Memory/SharedInodeVMObject.h @@ -23,8 +23,8 @@ public: private: virtual bool is_shared_inode() const override { return true; } - explicit SharedInodeVMObject(Inode&, FixedArray>&&); - explicit SharedInodeVMObject(SharedInodeVMObject const&, FixedArray>&&); + explicit SharedInodeVMObject(Inode&, FixedArray>&&, Bitmap dirty_pages); + explicit SharedInodeVMObject(SharedInodeVMObject const&, FixedArray>&&, Bitmap dirty_pages); virtual StringView class_name() const override { return "SharedInodeVMObject"sv; }