From 15956fcf9a724974938a59aab928626d2a1eafcc Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 7 Apr 2021 12:48:20 -0700 Subject: [PATCH] kern: update for new slab resource counts/extents --- .../include/mesosphere/kern_k_memory_layout.hpp | 5 ++--- .../libmesosphere/source/init/kern_init_slab_setup.cpp | 10 ++++++---- .../libmesosphere/source/kern_k_memory_layout.cpp | 8 +------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/libraries/libmesosphere/include/mesosphere/kern_k_memory_layout.hpp b/libraries/libmesosphere/include/mesosphere/kern_k_memory_layout.hpp index 574c48749..dce0af090 100644 --- a/libraries/libmesosphere/include/mesosphere/kern_k_memory_layout.hpp +++ b/libraries/libmesosphere/include/mesosphere/kern_k_memory_layout.hpp @@ -44,9 +44,8 @@ namespace ams::kern { constexpr size_t KernelInitialPageHeapSize = 128_KB; constexpr size_t KernelSlabHeapDataSize = 5_MB; - constexpr size_t KernelSlabHeapGapsSize = 2_MB - 64_KB; - constexpr size_t KernelSlabHeapGapsSizeDeprecated = 2_MB; - constexpr size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSize; + constexpr size_t KernelSlabHeapGapsSizeMax = 2_MB - 64_KB; + constexpr size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSizeMax; /* NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x860. */ constexpr size_t KernelSlabHeapAdditionalSize = 0x68000; diff --git a/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp b/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp index 5fab99370..05fc227a3 100644 --- a/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp +++ b/libraries/libmesosphere/source/init/kern_init_slab_setup.cpp @@ -57,14 +57,14 @@ namespace ams::kern::init { /* Constexpr counts. */ constexpr size_t SlabCountKProcess = 80; constexpr size_t SlabCountKThread = 800; - constexpr size_t SlabCountKEvent = 700; + constexpr size_t SlabCountKEvent = 900; constexpr size_t SlabCountKInterruptEvent = 100; constexpr size_t SlabCountKPort = 256 + 0x20 /* Extra 0x20 ports over Nintendo for homebrew. */; constexpr size_t SlabCountKSharedMemory = 80; constexpr size_t SlabCountKTransferMemory = 200; constexpr size_t SlabCountKCodeMemory = 10; constexpr size_t SlabCountKDeviceAddressSpace = 300; - constexpr size_t SlabCountKSession = 933; + constexpr size_t SlabCountKSession = 1133; constexpr size_t SlabCountKLightSession = 100; constexpr size_t SlabCountKObjectName = 7; constexpr size_t SlabCountKResourceLimit = 5; @@ -82,7 +82,7 @@ namespace ams::kern::init { } /* Global to hold our resource counts. */ - KSlabResourceCounts g_slab_resource_counts = { + constinit KSlabResourceCounts g_slab_resource_counts = { .num_KProcess = SlabCountKProcess, .num_KThread = SlabCountKThread, .num_KEvent = SlabCountKEvent, @@ -131,7 +131,9 @@ namespace ams::kern::init { } size_t CalculateSlabHeapGapSize() { - return (kern::GetTargetFirmware() >= TargetFirmware_10_0_0) ? KernelSlabHeapGapsSize : KernelSlabHeapGapsSizeDeprecated; + constexpr size_t KernelSlabHeapGapSize = 2_MB - 296_KB; + static_assert(KernelSlabHeapGapSize <= KernelSlabHeapGapsSizeMax); + return KernelSlabHeapGapSize; } size_t CalculateTotalSlabHeapSize() { diff --git a/libraries/libmesosphere/source/kern_k_memory_layout.cpp b/libraries/libmesosphere/source/kern_k_memory_layout.cpp index cdc56fb63..8aecb49ca 100644 --- a/libraries/libmesosphere/source/kern_k_memory_layout.cpp +++ b/libraries/libmesosphere/source/kern_k_memory_layout.cpp @@ -170,14 +170,8 @@ namespace ams::kern { size_t KMemoryLayout::GetResourceRegionSizeForInit() { /* Calculate resource region size based on whether we allow extra threads. */ const bool use_extra_resources = KSystemControl::Init::ShouldIncreaseThreadResourceLimit(); - size_t resource_region_size = KernelResourceSize + (use_extra_resources ? KernelSlabHeapAdditionalSize : 0); - /* 10.0.0 reduced the slab heap gaps by 64K. */ - if (kern::GetTargetFirmware() < ams::TargetFirmware_10_0_0) { - resource_region_size += (KernelSlabHeapGapsSizeDeprecated - KernelSlabHeapGapsSize); - } - - return resource_region_size; + return KernelResourceSize + (use_extra_resources ? KernelSlabHeapAdditionalSize : 0); } }