From 872c9528c7a55d16a6a6f2dffba752555a4b22f5 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Wed, 24 Jul 2024 16:31:28 -0400 Subject: [PATCH] kernel/vm: Remove areas from the areas map all at once if possible. This way we avoid lock contention if multiple threads are trying to delete areas at once. Same benchmark and "before" as previous commit: real 0m14.522s user 0m14.194s sys 0m4.337s after: real 0m13.810s user 0m14.145s sys 0m4.155s --- src/system/kernel/vm/vm.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/system/kernel/vm/vm.cpp b/src/system/kernel/vm/vm.cpp index 4009319ae2..47b48a3c6f 100644 --- a/src/system/kernel/vm/vm.cpp +++ b/src/system/kernel/vm/vm.cpp @@ -2570,7 +2570,8 @@ delete_area(VMAddressSpace* addressSpace, VMArea* area, { ASSERT(!area->IsWired()); - VMAreas::Remove(area); + if (area->id >= 0) + VMAreas::Remove(area); // At this point the area is removed from the global hash table, but // still exists in the area list. @@ -3992,6 +3993,17 @@ vm_delete_areas(struct VMAddressSpace* addressSpace, bool deletingAddressSpace) // remove all reserved areas in this address space addressSpace->UnreserveAllAddressRanges(0); + // remove all areas from the areas map at once (to avoid lock contention) + VMAreas::WriteLock(); + { + VMAddressSpace::AreaIterator it = addressSpace->GetAreaIterator(); + while (VMArea* area = it.Next()) { + VMAreas::Remove(area); + area->id = INT32_MIN; + } + } + VMAreas::WriteUnlock(); + // delete all the areas in this address space while (VMArea* area = addressSpace->FirstArea()) { ASSERT(!area->IsWired());