From 39665db167ff705c851bac241db7e118c2a20116 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 12 Jul 2019 22:41:21 -0400 Subject: [PATCH] kernel/vm: Inline the VMArea::name string. B_OS_NAME_LENGTH is 32, char* is 8 (on x64), and this structure has quite a lot of pointers in it so it is not like we really needed to save those 24 bytes. Hitting malloc() in here is not so great, especially because we usually have B_DONT_LOCK_KERNEL_SPACE turned on, so just inline and avoid it. Change-Id: I5c94955324cfda08972895826b61748c3b69096a --- headers/private/kernel/vm/VMArea.h | 2 +- src/system/kernel/vm/VMArea.cpp | 14 ++------------ 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/headers/private/kernel/vm/VMArea.h b/headers/private/kernel/vm/VMArea.h index 0c4337a9e4..7ec9281b04 100644 --- a/headers/private/kernel/vm/VMArea.h +++ b/headers/private/kernel/vm/VMArea.h @@ -97,8 +97,8 @@ public: }; public: - char* name; area_id id; + char name[B_OS_NAME_LENGTH]; uint32 protection; uint16 wiring; diff --git a/src/system/kernel/vm/VMArea.cpp b/src/system/kernel/vm/VMArea.cpp index ffe111e13f..cd29076bca 100644 --- a/src/system/kernel/vm/VMArea.cpp +++ b/src/system/kernel/vm/VMArea.cpp @@ -28,7 +28,6 @@ static area_id sNextAreaID = 1; VMArea::VMArea(VMAddressSpace* addressSpace, uint32 wiring, uint32 protection) : - name(NULL), protection(protection), wiring(wiring), memory_type(0), @@ -53,23 +52,14 @@ VMArea::~VMArea() // TODO: This might be stricter than necessary. free_etc(page_protections, flags); - free_etc(name, flags); } status_t VMArea::Init(const char* name, uint32 allocationFlags) { - // restrict the area name to B_OS_NAME_LENGTH - size_t length = strlen(name) + 1; - if (length > B_OS_NAME_LENGTH) - length = B_OS_NAME_LENGTH; - - // clone the name - this->name = (char*)malloc_etc(length, allocationFlags); - if (this->name == NULL) - return B_NO_MEMORY; - strlcpy(this->name, name, length); + // copy the name + strlcpy(this->name, name, B_OS_NAME_LENGTH); id = atomic_add(&sNextAreaID, 1); return B_OK;