All of lore.kernel.org
 help / color / mirror / Atom feed
From: Priya Hosur <Priya.Hosur@amd.com>
To: amd-gfx@lists.freedesktop.org,
	"Strahinja Stamenkovic" <strahinja.stamenkovic@amd.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Felix Kuehling" <Felix.Kuehling@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Lijo Lazar" <lijo.lazar@amd.com>
Cc: Priya Hosur <Priya.Hosur@amd.com>,
	Pratik Vishwakarma <Pratik.Vishwakarma@amd.com>,
	Veerabadhran Gopalakrishnan <Veerabadhran.Gopalakrishnan@amd.com>
Subject: [PATCH v2 1/2] drm/amdkfd: bound APU available memory by host available memory
Date: Fri, 27 Nov 2026 15:49:07 +0530	[thread overview]
Message-ID: <20261127101908.8313-2-Priya.Hosur@amd.com> (raw)
In-Reply-To: <20261127082854.112025-1-Priya.Hosur@amd.com>

On APUs where the VRAM carve-out is smaller than GTT (apu_prefer_gtt),
KFD serves VRAM allocations from GTT, which is ordinary system memory.
amdgpu_amdkfd_get_available_memory() then reports the minimum of the
static KFD system limit, the TTM limit and the XCP size, each reduced
only by KFD's own allocations. Memory used by the rest of the system is
never subtracted, so AMDKFD_IOC_AVAILABLE_MEMORY, and hipMemGetInfo() on
top of it, overstates what can be allocated.

On a Ryzen AI MAX+ 395 (gfx1151, 62 GiB RAM, ttm.pages_limit 80 GiB)
with 40 GiB held by another process, hipMemGetInfo() reports 59.67 GiB
free while MemAvailable is 20.39 GiB. Applications that size buffers
from it (e.g. a KV cache) overcommit and, without swap, trigger the OOM
killer instead of failing cleanly.

Bound the reported value by si_mem_available() when apu_prefer_gtt is
set, unless no_system_mem_limit is set, which explicitly allows KFD to
overcommit system memory. si_mem_available() includes reclaimable page
cache, so this does not under-report on an idle system.

Apply the bound in amdgpu_amdkfd_get_available_memory() rather than in
__get_available_memory(), which is also used by the allocation path for
is_app_apu. Allocation limits are unchanged; only the reported value is
affected.

Co-developed-by: Strahinja Stamenkovic <strahinja.stamenkovic@amd.com>
Signed-off-by: Strahinja Stamenkovic <strahinja.stamenkovic@amd.com>
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Priya Hosur <Priya.Hosur@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index a6616447abc8..0a04516e137e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1732,6 +1732,16 @@ size_t amdgpu_amdkfd_get_available_memory(struct amdgpu_device *adev,
 					   adev->kfd.vram_used_aligned[xcp_id]);
 	spin_unlock(&kfd_mem_limit.mem_limit_lock);
 
+	/*
+	 * In GTT mode, KFD allocations are backed by ordinary system pages, so
+	 * memory used elsewhere on the host is not available to the GPU either.
+	 * KFD only tracks its own usage, so also bound the reported value by the
+	 * host's available memory. This affects reporting only, not the limits.
+	 */
+	if (adev->apu_prefer_gtt && !no_system_mem_limit)
+		available = min_t(size_t, available,
+				  (size_t)si_mem_available() << PAGE_SHIFT);
+
 	return available;
 }
 
-- 
2.43.0


  parent reply	other threads:[~2026-11-27 10:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  8:28 [PATCH 0/2] drm/amdkfd: report realistic free/total memory on GTT-backed APUs Priya Hosur
2026-11-27  8:28 ` [PATCH 1/2] drm/amdkfd: bound APU available memory by host available memory Priya Hosur
2026-11-27  8:37   ` sashiko-bot
2026-11-27  8:52   ` Stamenkovic, Strahinja
2026-11-27  8:28 ` [PATCH 2/2] drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit Priya Hosur
2026-11-27  8:43   ` sashiko-bot
2026-11-27  8:52   ` Stamenkovic, Strahinja
2026-11-27 10:19 ` [PATCH v2 0/2] drm/amdkfd: report realistic free/total memory on GTT-backed APUs Priya Hosur
2026-11-27 10:19 ` Priya Hosur [this message]
2026-11-27 10:19 ` [PATCH v2 2/2] drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit Priya Hosur

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261127101908.8313-2-Priya.Hosur@amd.com \
    --to=priya.hosur@amd.com \
    --cc=Felix.Kuehling@amd.com \
    --cc=Pratik.Vishwakarma@amd.com \
    --cc=Veerabadhran.Gopalakrishnan@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=lijo.lazar@amd.com \
    --cc=strahinja.stamenkovic@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.