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 2/2] drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit
Date: Fri, 27 Nov 2026 15:49:08 +0530 [thread overview]
Message-ID: <20261127101908.8313-3-Priya.Hosur@amd.com> (raw)
In-Reply-To: <20261127082854.112025-1-Priya.Hosur@amd.com>
With apu_prefer_gtt, KFD reports ttm_tt_pages_limit() as the local
memory size, which HIP exposes as the device's total memory. TTM may
legitimately be configured above physical memory, since it can swap
buffers out, but KFD allocations are additionally bounded by
kfd_mem_limit.max_system_mem_limit, which is derived from physical
memory. KFD therefore advertises a pool it will never allocate from: on
a Ryzen AI MAX+ 395 with 62 GiB RAM and ttm.pages_limit set to 80 GiB,
HIP reports 80 GiB total while KFD caps allocations at 59.69 GiB, so
applications sizing against a fraction of total fail.
Report the smaller of the TTM limit and KFD's system memory limit, via a
new amdgpu_amdkfd_system_mem_limit() accessor, rounded down to PAGE_SIZE
since max_system_mem_limit is not necessarily page aligned while KFD
allocations are. When no_system_mem_limit is set to allow overcommit,
the TTM limit is reported unchanged. GTT and TTM sizing are not
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.c | 15 +++++++++++++--
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 6 ++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 9 +++++++++
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index 0dab267eb382..7f6c172e7e53 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -521,6 +521,17 @@ uint32_t amdgpu_amdkfd_get_fw_version(struct amdgpu_device *adev,
return 0;
}
+/*
+ * Size of the GTT-backed pool reported on APUs. TTM may be configured above
+ * physical RAM, but KFD will not allocate beyond its system memory limit, so
+ * don't report more than that.
+ */
+static u64 amdgpu_amdkfd_gtt_pool_size(void)
+{
+ return ALIGN_DOWN(min((u64)ttm_tt_pages_limit() << PAGE_SHIFT,
+ amdgpu_amdkfd_system_mem_limit()), PAGE_SIZE);
+}
+
void amdgpu_amdkfd_get_local_mem_info(struct amdgpu_device *adev,
struct kfd_local_mem_info *mem_info,
struct amdgpu_xcp *xcp)
@@ -535,7 +546,7 @@ void amdgpu_amdkfd_get_local_mem_info(struct amdgpu_device *adev,
mem_info->local_mem_size_private =
KFD_XCP_MEMORY_SIZE(adev, xcp->id);
} else if (adev->apu_prefer_gtt) {
- mem_info->local_mem_size_public = (ttm_tt_pages_limit() << PAGE_SHIFT);
+ mem_info->local_mem_size_public = amdgpu_amdkfd_gtt_pool_size();
mem_info->local_mem_size_private = 0;
} else {
mem_info->local_mem_size_public = adev->gmc.visible_vram_size;
@@ -863,7 +874,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id)
return ALIGN_DOWN(tmp, PAGE_SIZE);
} else if (adev->apu_prefer_gtt) {
- return (ttm_tt_pages_limit() << PAGE_SHIFT);
+ return amdgpu_amdkfd_gtt_pool_size();
} else {
return adev->gmc.real_vram_size;
}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index 74dc307e5140..f504f133f2a4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
@@ -400,6 +400,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo);
void amdgpu_amdkfd_account_vram_pin(struct amdgpu_bo *bo, int xcp_id);
void amdgpu_amdkfd_account_vram_unpin(struct amdgpu_bo *bo, int xcp_id);
void amdgpu_amdkfd_reserve_system_mem(uint64_t size);
+u64 amdgpu_amdkfd_system_mem_limit(void);
#else
static inline
void amdgpu_amdkfd_gpuvm_init_mem_limits(void)
@@ -426,6 +427,11 @@ static inline
void amdgpu_amdkfd_account_vram_unpin(struct amdgpu_bo *bo, int xcp_id)
{
}
+
+static inline u64 amdgpu_amdkfd_system_mem_limit(void)
+{
+ return U64_MAX;
+}
#endif
#if IS_ENABLED(CONFIG_HSA_AMD_SVM)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 0a04516e137e..5b530ddf06b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -130,6 +130,15 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void)
(kfd_mem_limit.max_ttm_mem_limit >> 20));
}
+/* Returns U64_MAX if the system memory limit is disabled or not yet set up. */
+u64 amdgpu_amdkfd_system_mem_limit(void)
+{
+ if (no_system_mem_limit || !kfd_mem_limit.max_system_mem_limit)
+ return U64_MAX;
+
+ return kfd_mem_limit.max_system_mem_limit;
+}
+
void amdgpu_amdkfd_reserve_system_mem(uint64_t size)
{
kfd_mem_limit.system_mem_used += size;
--
2.43.0
prev 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 ` [PATCH v2 1/2] drm/amdkfd: bound APU available memory by host available memory Priya Hosur
2026-11-27 10:19 ` Priya Hosur [this message]
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-3-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.