Serenity Operating System
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Kernel: Split InodeVMObject into two subclasses

We now have PrivateInodeVMObject and SharedInodeVMObject, corresponding
to MAP_PRIVATE and MAP_SHARED respectively.

Note that PrivateInodeVMObject is not used yet.

+371 -166
+2
Kernel/Makefile
··· 101 101 TTY/VirtualConsole.o \ 102 102 Thread.o \ 103 103 VM/AnonymousVMObject.o \ 104 + VM/InodeVMObject.o \ 104 105 VM/MemoryManager.o \ 105 106 VM/PageDirectory.o \ 106 107 VM/PhysicalPage.o \ 107 108 VM/PhysicalRegion.o \ 108 109 VM/PurgeableVMObject.o \ 110 + VM/PrivateInodeVMObject.o \ 109 111 VM/RangeAllocator.o \ 110 112 VM/Region.o \ 111 113 VM/SharedInodeVMObject.o \
+2 -2
Kernel/Process.cpp
··· 663 663 } 664 664 } 665 665 if (mode & PURGE_ALL_CLEAN_INODE) { 666 - NonnullRefPtrVector<SharedInodeVMObject> vmobjects; 666 + NonnullRefPtrVector<InodeVMObject> vmobjects; 667 667 { 668 668 InterruptDisabler disabler; 669 669 MM.for_each_vmobject([&](auto& vmobject) { 670 670 if (vmobject.is_inode()) 671 - vmobjects.append(static_cast<SharedInodeVMObject&>(vmobject)); 671 + vmobjects.append(static_cast<InodeVMObject&>(vmobject)); 672 672 return IterationDecision::Continue; 673 673 }); 674 674 }
+182
Kernel/VM/InodeVMObject.cpp
··· 1 + /* 2 + * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 + * All rights reserved. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions are met: 7 + * 8 + * 1. Redistributions of source code must retain the above copyright notice, this 9 + * list of conditions and the following disclaimer. 10 + * 11 + * 2. Redistributions in binary form must reproduce the above copyright notice, 12 + * this list of conditions and the following disclaimer in the documentation 13 + * and/or other materials provided with the distribution. 14 + * 15 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 + */ 26 + 27 + #include <Kernel/FileSystem/Inode.h> 28 + #include <Kernel/VM/InodeVMObject.h> 29 + #include <Kernel/VM/MemoryManager.h> 30 + #include <Kernel/VM/Region.h> 31 + 32 + namespace Kernel { 33 + 34 + InodeVMObject::InodeVMObject(Inode& inode, size_t size) 35 + : VMObject(size) 36 + , m_inode(inode) 37 + , m_dirty_pages(page_count(), false) 38 + { 39 + } 40 + 41 + InodeVMObject::InodeVMObject(const InodeVMObject& other) 42 + : VMObject(other) 43 + , m_inode(other.m_inode) 44 + { 45 + } 46 + 47 + InodeVMObject::~InodeVMObject() 48 + { 49 + } 50 + 51 + size_t InodeVMObject::amount_clean() const 52 + { 53 + size_t count = 0; 54 + ASSERT(page_count() == (size_t)m_dirty_pages.size()); 55 + for (size_t i = 0; i < page_count(); ++i) { 56 + if (!m_dirty_pages.get(i) && m_physical_pages[i]) 57 + ++count; 58 + } 59 + return count * PAGE_SIZE; 60 + } 61 + 62 + size_t InodeVMObject::amount_dirty() const 63 + { 64 + size_t count = 0; 65 + for (size_t i = 0; i < m_dirty_pages.size(); ++i) { 66 + if (m_dirty_pages.get(i)) 67 + ++count; 68 + } 69 + return count * PAGE_SIZE; 70 + } 71 + 72 + void InodeVMObject::inode_size_changed(Badge<Inode>, size_t old_size, size_t new_size) 73 + { 74 + dbg() << "VMObject::inode_size_changed: {" << m_inode->fsid() << ":" << m_inode->index() << "} " << old_size << " -> " << new_size; 75 + 76 + InterruptDisabler disabler; 77 + 78 + auto new_page_count = PAGE_ROUND_UP(new_size) / PAGE_SIZE; 79 + m_physical_pages.resize(new_page_count); 80 + 81 + m_dirty_pages.grow(new_page_count, false); 82 + 83 + // FIXME: Consolidate with inode_contents_changed() so we only do a single walk. 84 + for_each_region([](auto& region) { 85 + region.remap(); 86 + }); 87 + } 88 + 89 + void InodeVMObject::inode_contents_changed(Badge<Inode>, off_t offset, ssize_t size, const u8* data) 90 + { 91 + (void)size; 92 + (void)data; 93 + InterruptDisabler disabler; 94 + ASSERT(offset >= 0); 95 + 96 + // FIXME: Only invalidate the parts that actually changed. 97 + for (auto& physical_page : m_physical_pages) 98 + physical_page = nullptr; 99 + 100 + #if 0 101 + size_t current_offset = offset; 102 + size_t remaining_bytes = size; 103 + const u8* data_ptr = data; 104 + 105 + auto to_page_index = [] (size_t offset) -> size_t { 106 + return offset / PAGE_SIZE; 107 + }; 108 + 109 + if (current_offset & PAGE_MASK) { 110 + size_t page_index = to_page_index(current_offset); 111 + size_t bytes_to_copy = min(size, PAGE_SIZE - (current_offset & PAGE_MASK)); 112 + if (m_physical_pages[page_index]) { 113 + auto* ptr = MM.quickmap_page(*m_physical_pages[page_index]); 114 + memcpy(ptr, data_ptr, bytes_to_copy); 115 + MM.unquickmap_page(); 116 + } 117 + current_offset += bytes_to_copy; 118 + data += bytes_to_copy; 119 + remaining_bytes -= bytes_to_copy; 120 + } 121 + 122 + for (size_t page_index = to_page_index(current_offset); page_index < m_physical_pages.size(); ++page_index) { 123 + size_t bytes_to_copy = PAGE_SIZE - (current_offset & PAGE_MASK); 124 + if (m_physical_pages[page_index]) { 125 + auto* ptr = MM.quickmap_page(*m_physical_pages[page_index]); 126 + memcpy(ptr, data_ptr, bytes_to_copy); 127 + MM.unquickmap_page(); 128 + } 129 + current_offset += bytes_to_copy; 130 + data += bytes_to_copy; 131 + } 132 + #endif 133 + 134 + // FIXME: Consolidate with inode_size_changed() so we only do a single walk. 135 + for_each_region([](auto& region) { 136 + region.remap(); 137 + }); 138 + } 139 + 140 + int InodeVMObject::release_all_clean_pages() 141 + { 142 + LOCKER(m_paging_lock); 143 + return release_all_clean_pages_impl(); 144 + } 145 + 146 + int InodeVMObject::release_all_clean_pages_impl() 147 + { 148 + int count = 0; 149 + InterruptDisabler disabler; 150 + for (size_t i = 0; i < page_count(); ++i) { 151 + if (!m_dirty_pages.get(i) && m_physical_pages[i]) { 152 + m_physical_pages[i] = nullptr; 153 + ++count; 154 + } 155 + } 156 + for_each_region([](auto& region) { 157 + region.remap(); 158 + }); 159 + return count; 160 + } 161 + 162 + u32 InodeVMObject::writable_mappings() const 163 + { 164 + u32 count = 0; 165 + const_cast<InodeVMObject&>(*this).for_each_region([&](auto& region) { 166 + if (region.is_writable()) 167 + ++count; 168 + }); 169 + return count; 170 + } 171 + 172 + u32 InodeVMObject::executable_mappings() const 173 + { 174 + u32 count = 0; 175 + const_cast<InodeVMObject&>(*this).for_each_region([&](auto& region) { 176 + if (region.is_executable()) 177 + ++count; 178 + }); 179 + return count; 180 + } 181 + 182 + }
+69
Kernel/VM/InodeVMObject.h
··· 1 + /* 2 + * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 + * All rights reserved. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions are met: 7 + * 8 + * 1. Redistributions of source code must retain the above copyright notice, this 9 + * list of conditions and the following disclaimer. 10 + * 11 + * 2. Redistributions in binary form must reproduce the above copyright notice, 12 + * this list of conditions and the following disclaimer in the documentation 13 + * and/or other materials provided with the distribution. 14 + * 15 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 + */ 26 + 27 + #pragma once 28 + 29 + #include <AK/Bitmap.h> 30 + #include <Kernel/UnixTypes.h> 31 + #include <Kernel/VM/VMObject.h> 32 + 33 + namespace Kernel { 34 + 35 + class InodeVMObject : public VMObject { 36 + public: 37 + virtual ~InodeVMObject() override; 38 + 39 + Inode& inode() { return *m_inode; } 40 + const Inode& inode() const { return *m_inode; } 41 + 42 + void inode_contents_changed(Badge<Inode>, off_t, ssize_t, const u8*); 43 + void inode_size_changed(Badge<Inode>, size_t old_size, size_t new_size); 44 + 45 + size_t amount_dirty() const; 46 + size_t amount_clean() const; 47 + 48 + int release_all_clean_pages(); 49 + 50 + u32 writable_mappings() const; 51 + u32 executable_mappings() const; 52 + 53 + protected: 54 + explicit InodeVMObject(Inode&, size_t); 55 + explicit InodeVMObject(const InodeVMObject&); 56 + 57 + InodeVMObject& operator=(const InodeVMObject&) = delete; 58 + InodeVMObject& operator=(InodeVMObject&&) = delete; 59 + InodeVMObject(InodeVMObject&&) = delete; 60 + 61 + virtual bool is_inode() const final { return true; } 62 + 63 + int release_all_clean_pages_impl(); 64 + 65 + NonnullRefPtr<Inode> m_inode; 66 + Bitmap m_dirty_pages; 67 + }; 68 + 69 + }
+56
Kernel/VM/PrivateInodeVMObject.cpp
··· 1 + /* 2 + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> 3 + * All rights reserved. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions are met: 7 + * 8 + * 1. Redistributions of source code must retain the above copyright notice, this 9 + * list of conditions and the following disclaimer. 10 + * 11 + * 2. Redistributions in binary form must reproduce the above copyright notice, 12 + * this list of conditions and the following disclaimer in the documentation 13 + * and/or other materials provided with the distribution. 14 + * 15 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 + */ 26 + 27 + #include <Kernel/FileSystem/Inode.h> 28 + #include <Kernel/VM/PrivateInodeVMObject.h> 29 + 30 + namespace Kernel { 31 + 32 + NonnullRefPtr<PrivateInodeVMObject> PrivateInodeVMObject::create_with_inode(Inode& inode) 33 + { 34 + return adopt(*new PrivateInodeVMObject(inode, inode.size())); 35 + } 36 + 37 + NonnullRefPtr<VMObject> PrivateInodeVMObject::clone() 38 + { 39 + return adopt(*new PrivateInodeVMObject(*this)); 40 + } 41 + 42 + PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, size_t size) 43 + : InodeVMObject(inode, size) 44 + { 45 + } 46 + 47 + PrivateInodeVMObject::PrivateInodeVMObject(const PrivateInodeVMObject& other) 48 + : InodeVMObject(other) 49 + { 50 + } 51 + 52 + PrivateInodeVMObject::~PrivateInodeVMObject() 53 + { 54 + } 55 + 56 + }
+51
Kernel/VM/PrivateInodeVMObject.h
··· 1 + /* 2 + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> 3 + * All rights reserved. 4 + * 5 + * Redistribution and use in source and binary forms, with or without 6 + * modification, are permitted provided that the following conditions are met: 7 + * 8 + * 1. Redistributions of source code must retain the above copyright notice, this 9 + * list of conditions and the following disclaimer. 10 + * 11 + * 2. Redistributions in binary form must reproduce the above copyright notice, 12 + * this list of conditions and the following disclaimer in the documentation 13 + * and/or other materials provided with the distribution. 14 + * 15 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 + */ 26 + 27 + #pragma once 28 + 29 + #include <AK/Bitmap.h> 30 + #include <Kernel/UnixTypes.h> 31 + #include <Kernel/VM/InodeVMObject.h> 32 + 33 + namespace Kernel { 34 + 35 + class PrivateInodeVMObject final : public InodeVMObject { 36 + AK_MAKE_NONMOVABLE(PrivateInodeVMObject); 37 + 38 + public: 39 + virtual ~PrivateInodeVMObject() override; 40 + 41 + static NonnullRefPtr<PrivateInodeVMObject> create_with_inode(Inode&); 42 + virtual NonnullRefPtr<VMObject> clone() override; 43 + 44 + private: 45 + explicit PrivateInodeVMObject(Inode&, size_t); 46 + explicit PrivateInodeVMObject(const PrivateInodeVMObject&); 47 + 48 + PrivateInodeVMObject& operator=(const PrivateInodeVMObject&) = delete; 49 + }; 50 + 51 + }
+1 -1
Kernel/VM/Region.cpp
··· 452 452 LOCKER(vmobject().m_paging_lock); 453 453 cli(); 454 454 455 - auto& inode_vmobject = static_cast<SharedInodeVMObject&>(vmobject()); 455 + auto& inode_vmobject = static_cast<InodeVMObject&>(vmobject()); 456 456 auto& vmobject_physical_page_entry = inode_vmobject.physical_pages()[first_page_index() + page_index_in_region]; 457 457 458 458 #ifdef PAGE_FAULT_DEBUG
+4 -138
Kernel/VM/SharedInodeVMObject.cpp
··· 1 1 /* 2 - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 2 + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> 3 3 * All rights reserved. 4 4 * 5 5 * Redistribution and use in source and binary forms, with or without ··· 25 25 */ 26 26 27 27 #include <Kernel/FileSystem/Inode.h> 28 - #include <Kernel/VM/SharedInodeVMObject.h> 29 28 #include <Kernel/VM/MemoryManager.h> 30 29 #include <Kernel/VM/Region.h> 30 + #include <Kernel/VM/SharedInodeVMObject.h> 31 31 32 32 namespace Kernel { 33 33 ··· 47 47 } 48 48 49 49 SharedInodeVMObject::SharedInodeVMObject(Inode& inode, size_t size) 50 - : VMObject(size) 51 - , m_inode(inode) 52 - , m_dirty_pages(page_count(), false) 50 + : InodeVMObject(inode, size) 53 51 { 54 52 } 55 53 56 54 SharedInodeVMObject::SharedInodeVMObject(const SharedInodeVMObject& other) 57 - : VMObject(other) 58 - , m_inode(other.m_inode) 55 + : InodeVMObject(other) 59 56 { 60 57 } 61 58 62 59 SharedInodeVMObject::~SharedInodeVMObject() 63 60 { 64 61 ASSERT(inode().shared_vmobject() == this); 65 - } 66 - 67 - size_t SharedInodeVMObject::amount_clean() const 68 - { 69 - size_t count = 0; 70 - ASSERT(page_count() == (size_t)m_dirty_pages.size()); 71 - for (size_t i = 0; i < page_count(); ++i) { 72 - if (!m_dirty_pages.get(i) && m_physical_pages[i]) 73 - ++count; 74 - } 75 - return count * PAGE_SIZE; 76 - } 77 - 78 - size_t SharedInodeVMObject::amount_dirty() const 79 - { 80 - size_t count = 0; 81 - for (size_t i = 0; i < m_dirty_pages.size(); ++i) { 82 - if (m_dirty_pages.get(i)) 83 - ++count; 84 - } 85 - return count * PAGE_SIZE; 86 - } 87 - 88 - void SharedInodeVMObject::inode_size_changed(Badge<Inode>, size_t old_size, size_t new_size) 89 - { 90 - dbg() << "VMObject::inode_size_changed: {" << m_inode->fsid() << ":" << m_inode->index() << "} " << old_size << " -> " << new_size; 91 - 92 - InterruptDisabler disabler; 93 - 94 - auto new_page_count = PAGE_ROUND_UP(new_size) / PAGE_SIZE; 95 - m_physical_pages.resize(new_page_count); 96 - 97 - m_dirty_pages.grow(new_page_count, false); 98 - 99 - // FIXME: Consolidate with inode_contents_changed() so we only do a single walk. 100 - for_each_region([](auto& region) { 101 - region.remap(); 102 - }); 103 - } 104 - 105 - void SharedInodeVMObject::inode_contents_changed(Badge<Inode>, off_t offset, ssize_t size, const u8* data) 106 - { 107 - (void)size; 108 - (void)data; 109 - InterruptDisabler disabler; 110 - ASSERT(offset >= 0); 111 - 112 - // FIXME: Only invalidate the parts that actually changed. 113 - for (auto& physical_page : m_physical_pages) 114 - physical_page = nullptr; 115 - 116 - #if 0 117 - size_t current_offset = offset; 118 - size_t remaining_bytes = size; 119 - const u8* data_ptr = data; 120 - 121 - auto to_page_index = [] (size_t offset) -> size_t { 122 - return offset / PAGE_SIZE; 123 - }; 124 - 125 - if (current_offset & PAGE_MASK) { 126 - size_t page_index = to_page_index(current_offset); 127 - size_t bytes_to_copy = min(size, PAGE_SIZE - (current_offset & PAGE_MASK)); 128 - if (m_physical_pages[page_index]) { 129 - auto* ptr = MM.quickmap_page(*m_physical_pages[page_index]); 130 - memcpy(ptr, data_ptr, bytes_to_copy); 131 - MM.unquickmap_page(); 132 - } 133 - current_offset += bytes_to_copy; 134 - data += bytes_to_copy; 135 - remaining_bytes -= bytes_to_copy; 136 - } 137 - 138 - for (size_t page_index = to_page_index(current_offset); page_index < m_physical_pages.size(); ++page_index) { 139 - size_t bytes_to_copy = PAGE_SIZE - (current_offset & PAGE_MASK); 140 - if (m_physical_pages[page_index]) { 141 - auto* ptr = MM.quickmap_page(*m_physical_pages[page_index]); 142 - memcpy(ptr, data_ptr, bytes_to_copy); 143 - MM.unquickmap_page(); 144 - } 145 - current_offset += bytes_to_copy; 146 - data += bytes_to_copy; 147 - } 148 - #endif 149 - 150 - // FIXME: Consolidate with inode_size_changed() so we only do a single walk. 151 - for_each_region([](auto& region) { 152 - region.remap(); 153 - }); 154 - } 155 - 156 - int SharedInodeVMObject::release_all_clean_pages() 157 - { 158 - LOCKER(m_paging_lock); 159 - return release_all_clean_pages_impl(); 160 - } 161 - 162 - int SharedInodeVMObject::release_all_clean_pages_impl() 163 - { 164 - int count = 0; 165 - InterruptDisabler disabler; 166 - for (size_t i = 0; i < page_count(); ++i) { 167 - if (!m_dirty_pages.get(i) && m_physical_pages[i]) { 168 - m_physical_pages[i] = nullptr; 169 - ++count; 170 - } 171 - } 172 - for_each_region([](auto& region) { 173 - region.remap(); 174 - }); 175 - return count; 176 - } 177 - 178 - u32 SharedInodeVMObject::writable_mappings() const 179 - { 180 - u32 count = 0; 181 - const_cast<SharedInodeVMObject&>(*this).for_each_region([&](auto& region) { 182 - if (region.is_writable()) 183 - ++count; 184 - }); 185 - return count; 186 - } 187 - 188 - u32 SharedInodeVMObject::executable_mappings() const 189 - { 190 - u32 count = 0; 191 - const_cast<SharedInodeVMObject&>(*this).for_each_region([&](auto& region) { 192 - if (region.is_executable()) 193 - ++count; 194 - }); 195 - return count; 196 62 } 197 63 198 64 }
+4 -25
Kernel/VM/SharedInodeVMObject.h
··· 28 28 29 29 #include <AK/Bitmap.h> 30 30 #include <Kernel/UnixTypes.h> 31 - #include <Kernel/VM/VMObject.h> 31 + #include <Kernel/VM/InodeVMObject.h> 32 32 33 33 namespace Kernel { 34 34 35 - class SharedInodeVMObject final : public VMObject { 35 + class SharedInodeVMObject final : public InodeVMObject { 36 + AK_MAKE_NONMOVABLE(SharedInodeVMObject); 37 + 36 38 public: 37 39 virtual ~SharedInodeVMObject() override; 38 40 39 41 static NonnullRefPtr<SharedInodeVMObject> create_with_inode(Inode&); 40 42 virtual NonnullRefPtr<VMObject> clone() override; 41 43 42 - Inode& inode() { return *m_inode; } 43 - const Inode& inode() const { return *m_inode; } 44 - 45 - void inode_contents_changed(Badge<Inode>, off_t, ssize_t, const u8*); 46 - void inode_size_changed(Badge<Inode>, size_t old_size, size_t new_size); 47 - 48 - size_t amount_dirty() const; 49 - size_t amount_clean() const; 50 - 51 - int release_all_clean_pages(); 52 - 53 - u32 writable_mappings() const; 54 - u32 executable_mappings() const; 55 - 56 44 private: 57 45 explicit SharedInodeVMObject(Inode&, size_t); 58 46 explicit SharedInodeVMObject(const SharedInodeVMObject&); 59 47 60 48 SharedInodeVMObject& operator=(const SharedInodeVMObject&) = delete; 61 - SharedInodeVMObject& operator=(SharedInodeVMObject&&) = delete; 62 - SharedInodeVMObject(SharedInodeVMObject&&) = delete; 63 - 64 - virtual bool is_inode() const override { return true; } 65 - 66 - int release_all_clean_pages_impl(); 67 - 68 - NonnullRefPtr<Inode> m_inode; 69 - Bitmap m_dirty_pages; 70 49 }; 71 50 72 51 }