mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
Kernel: Skip TLB flushes while cloning regions in sys$fork()
Since we know for sure that the virtual memory regions in the new process being created are not being used on any CPU, there's no need to do TLB flushes for every mapped page.
This commit is contained in:
parent
8fd69e9e56
commit
a819eb5016
Notes:
sideshowbarker
2024-07-18 21:44:38 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/a819eb50166
3 changed files with 10 additions and 4 deletions
|
@ -89,7 +89,7 @@ KResultOr<pid_t> Process::sys$fork(RegisterState& regs)
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& child_region = child->space().add_region(region_clone.release_nonnull());
|
auto& child_region = child->space().add_region(region_clone.release_nonnull());
|
||||||
child_region.map(child->space().page_directory());
|
child_region.map(child->space().page_directory(), ShouldFlushTLB::No);
|
||||||
|
|
||||||
if (®ion == m_master_tls_region.unsafe_ptr())
|
if (®ion == m_master_tls_region.unsafe_ptr())
|
||||||
child->m_master_tls_region = child_region;
|
child->m_master_tls_region = child_region;
|
||||||
|
|
|
@ -385,7 +385,7 @@ void Region::set_page_directory(PageDirectory& page_directory)
|
||||||
m_page_directory = page_directory;
|
m_page_directory = page_directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Region::map(PageDirectory& page_directory)
|
bool Region::map(PageDirectory& page_directory, ShouldFlushTLB should_flush_tlb)
|
||||||
{
|
{
|
||||||
ScopedSpinLock lock(s_mm_lock);
|
ScopedSpinLock lock(s_mm_lock);
|
||||||
ScopedSpinLock page_lock(page_directory.get_lock());
|
ScopedSpinLock page_lock(page_directory.get_lock());
|
||||||
|
@ -403,6 +403,7 @@ bool Region::map(PageDirectory& page_directory)
|
||||||
++page_index;
|
++page_index;
|
||||||
}
|
}
|
||||||
if (page_index > 0) {
|
if (page_index > 0) {
|
||||||
|
if (should_flush_tlb == ShouldFlushTLB::Yes)
|
||||||
MM.flush_tlb(m_page_directory, vaddr(), page_index);
|
MM.flush_tlb(m_page_directory, vaddr(), page_index);
|
||||||
return page_index == page_count();
|
return page_index == page_count();
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,11 @@ namespace Kernel {
|
||||||
class Inode;
|
class Inode;
|
||||||
class VMObject;
|
class VMObject;
|
||||||
|
|
||||||
|
enum class ShouldFlushTLB {
|
||||||
|
No,
|
||||||
|
Yes,
|
||||||
|
};
|
||||||
|
|
||||||
class Region final
|
class Region final
|
||||||
: public InlineLinkedListNode<Region>
|
: public InlineLinkedListNode<Region>
|
||||||
, public Weakable<Region>
|
, public Weakable<Region>
|
||||||
|
@ -215,7 +220,7 @@ public:
|
||||||
void set_executable(bool b) { set_access_bit(Access::Execute, b); }
|
void set_executable(bool b) { set_access_bit(Access::Execute, b); }
|
||||||
|
|
||||||
void set_page_directory(PageDirectory&);
|
void set_page_directory(PageDirectory&);
|
||||||
bool map(PageDirectory&);
|
bool map(PageDirectory&, ShouldFlushTLB = ShouldFlushTLB::Yes);
|
||||||
enum class ShouldDeallocateVirtualMemoryRange {
|
enum class ShouldDeallocateVirtualMemoryRange {
|
||||||
No,
|
No,
|
||||||
Yes,
|
Yes,
|
||||||
|
|
Loading…
Reference in a new issue