From ec4b2ce6644de01817200a3915689222497f4c5e Mon Sep 17 00:00:00 2001 From: Paulo Zanoni Date: Tue, 25 Mar 2025 16:45:08 -0700 Subject: [PATCH] anv: restore the old behavior of up to 75% of RAM for the system heap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "We paid for sixteen gigs of RAM, so we gonna use the whole damn sixteen gigs of RAM!" - My Mom First, some history: The Anv 50%-or-75% rule was originally added in 2017 by 060a6434eca9 ("anv: Advertise larger heap sizes"). When i915.ko started reporting memory sizes in its ioctls, it didn't impose any restrictions: 100% of SRAM was reported as available, so the restriction was in Mesa. When xe.ko was introduced, it only reported 50% of the SRAM as available through its ioctls, so commit b571ae6e7a76 ("intel: Make memory heaps consistent between KMDs") adapted the code to not take an extra 25% of the 50% that was already cut, and restricted i915.ko to 50% instead of the 50%-or-75%. In Kernel commit d2d5f6d57884 ("drm/xe: Increase the XE_PL_TT watermark"), xe.ko changed to reporting 100% of SRAM through its ioctls, so we adapted Mesa to do the right thing depending on which Kernel version was running. While this was all happening, we were discussing about which behavior was actually the best: restrict everything to 50% in order to avoid issues when many things are running in parallel, or keep the restriction only at 75% in order to allow high demanding workloads to make full use of the hardware. The way I see, if parallel applications are causing the system to run out of resources, the user always has the option to kill applications and use one thing at a time. On the other hand, if a single application needs more than 50% of the SRAM and we don't allow it in our heaps, the application will never work (unless, of course, the user patches Mesa). So in this commit we go back to allowing high-demanding applications to work by restoring the 50%-or-75% rule. This commit is especially useful in systems with integrated graphics, like LNL, where the option to upgrade RAM is not present. Reviewed-by: José Roberto de Souza Signed-off-by: Paulo Zanoni Part-of: --- src/intel/vulkan/anv_physical_device.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/intel/vulkan/anv_physical_device.c b/src/intel/vulkan/anv_physical_device.c index 067de17b562..2918212cb1b 100644 --- a/src/intel/vulkan/anv_physical_device.c +++ b/src/intel/vulkan/anv_physical_device.c @@ -1993,7 +1993,10 @@ anv_restrict_sys_heap_size(struct anv_physical_device *device, return kmd_reported_sram; } - return kmd_reported_sram / 2; + if (kmd_reported_sram <= 4ull * 1024ull * 1024ull * 1024ull) + return kmd_reported_sram / 2; + else + return kmd_reported_sram * 3 / 4; } static VkResult MUST_CHECK