SerenityOS / serenity

The Serenity Operating System 🐞
https://serenityos.org
BSD 2-Clause "Simplified" License
29.46k stars 3.14k forks source link

Kernel/Memory: Make mmap objects track dirty and clean pages #24561

Open brody-qq opened 3 weeks ago

brody-qq commented 3 weeks ago

This PR fixes this issue https://github.com/SerenityOS/serenity/issues/15951

This PR also adds a few more test cases for private and shared file mmaps

brody-qq commented 3 weeks ago

A lot of my testing was done by running the following 2 programs in userspace and checking the debug logs for anything unusual:

If anyone has advice on better ways to test this I would appreciate it!

brody-qq commented 1 week ago

I updated this to remove a FIXME comment that is fixed by this PR

--- a/Kernel/Memory/Region.cpp
+++ b/Kernel/Memory/Region.cpp
@@ -56,10 +56,8 @@ Region::Region(VirtualRange const& range, NonnullLockRefPtr<VMObject> vmobject,

 Region::~Region()
 {
-    if (is_writable() && vmobject().is_shared_inode()) {
-        // FIXME: This is very aggressive. Find a way to do less work!
+    if (is_writable() && vmobject().is_shared_inode())
         (void)static_cast<SharedInodeVMObject&>(vmobject()).sync_before_destroying();
-    }

     m_vmobject->remove_region(*this);