From fc9ce229819c232e8960fe14e14157ab2befd43c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 28 May 2021 09:33:14 +0200 Subject: Kernel: Use KString for Region names Replace the AK::String used for Region::m_name with a KString. This seems beneficial across the board, but as a specific data point, it reduces time spent in sys$set_mmap_name() by ~50% on test-js. :^) --- Kernel/Syscalls/mmap.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'Kernel/Syscalls') diff --git a/Kernel/Syscalls/mmap.cpp b/Kernel/Syscalls/mmap.cpp index 9f556b2502..1dddb431e5 100644 --- a/Kernel/Syscalls/mmap.cpp +++ b/Kernel/Syscalls/mmap.cpp @@ -156,13 +156,14 @@ KResultOr Process::sys$mmap(Userspace u if (!is_user_range(VirtualAddress(addr), page_round_up(size))) return EFAULT; - String name; + OwnPtr name; if (params.name.characters) { if (params.name.length > PATH_MAX) return ENAMETOOLONG; - name = copy_string_from_user(params.name); - if (name.is_null()) - return EFAULT; + auto name_or_error = try_copy_kstring_from_user(params.name); + if (name_or_error.is_error()) + return name_or_error.error(); + name = name_or_error.release_value(); } if (size == 0) @@ -213,7 +214,7 @@ KResultOr Process::sys$mmap(Userspace u if (map_anonymous) { auto strategy = map_noreserve ? AllocationStrategy::None : AllocationStrategy::Reserve; - auto region_or_error = space().allocate_region(range.value(), !name.is_null() ? name : "mmap", prot, strategy); + auto region_or_error = space().allocate_region(range.value(), {}, prot, strategy); if (region_or_error.is_error()) return region_or_error.error().error(); region = region_or_error.value(); @@ -253,8 +254,7 @@ KResultOr Process::sys$mmap(Userspace u region->set_shared(true); if (map_stack) region->set_stack(true); - if (!name.is_null()) - region->set_name(name); + region->set_name(move(name)); PerformanceManager::add_mmap_perf_event(*this, *region); @@ -480,9 +480,10 @@ KResultOr Process::sys$set_mmap_name(Userspace PATH_MAX) return ENAMETOOLONG; - auto name = copy_string_from_user(params.name); - if (name.is_null()) - return EFAULT; + auto name_or_error = try_copy_kstring_from_user(params.name); + if (name_or_error.is_error()) + return name_or_error.error(); + auto name = name_or_error.release_value(); auto range_or_error = expand_range_to_page_boundaries((FlatPtr)params.addr, params.size); if (range_or_error.is_error()) -- cgit v1.2.3