* [PATCH 1/2] drm/amdkfd: bound APU available memory by host available memory
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 ` 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
` (3 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Priya Hosur @ 2026-11-27 8:28 UTC (permalink / raw)
To: amd-gfx, Strahinja Stamenkovic, Alex Deucher, Felix Kuehling,
Christian König, Lijo Lazar
Cc: Priya Hosur, Pratik Vishwakarma, Veerabadhran Gopalakrishnan
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>
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
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 1/2] drm/amdkfd: bound APU available memory by host available memory
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
1 sibling, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-11-27 8:37 UTC (permalink / raw)
To: Priya Hosur, amd-gfx
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdkfd: missing Signed-off-by trailer for Co-developed-by
author
--
commit 420a8aac5bafb2838f8e3671bb8ebf0a0f48b7bc
Author: Priya Hosur <Priya.Hosur@amd.com>
> drm/amdkfd: bound APU available memory by host available memory
>
> 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>
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Priya Hosur <Priya.Hosur@amd.com>
[Severity: High]
Per Documentation/process/submitting-patches.rst, every Co-developed-by
trailer must be immediately followed by a matching Signed-off-by trailer
from that co-author. Should a Signed-off-by trailer for Strahinja
Stamenkovic be added right after the Co-developed-by line?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127082854.112025-1-Priya.Hosur@amd.com?part=1
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [PATCH 1/2] drm/amdkfd: bound APU available memory by host available memory
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
1 sibling, 0 replies; 10+ messages in thread
From: Stamenkovic, Strahinja @ 2026-11-27 8:52 UTC (permalink / raw)
To: Hosur, Priya, amd-gfx@lists.freedesktop.org, Deucher, Alexander,
Kuehling, Felix, Koenig, Christian, Lazar, Lijo
Cc: Vishwakarma, Pratik, Gopalakrishnan, Veerabadhran (Veera)
Signed-off-by: Strahinja Stamenkovic <strahinja.stamenkovic@amd.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/2] drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit
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:28 ` 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
` (2 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Priya Hosur @ 2026-11-27 8:28 UTC (permalink / raw)
To: amd-gfx, Strahinja Stamenkovic, Alex Deucher, Felix Kuehling,
Christian König, Lijo Lazar
Cc: Priya Hosur, Pratik Vishwakarma, Veerabadhran Gopalakrishnan
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. 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>
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..17c12edca437 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 min((u64)ttm_tt_pages_limit() << PAGE_SHIFT,
+ amdgpu_amdkfd_system_mem_limit());
+}
+
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
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 2/2] drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit
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
1 sibling, 0 replies; 10+ messages in thread
From: sashiko-bot @ 2026-11-27 8:43 UTC (permalink / raw)
To: Priya Hosur, amd-gfx
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] drm/amdkfd: unaligned GTT pool size in
amdgpu_amdkfd_gtt_pool_size()
--
commit 17502322da1ca7a12d9a6715a32b9c3d4e96b211
Author: Priya Hosur <Priya.Hosur@amd.com>
drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit
This commit caps the reported APU GTT pool size in
amdgpu_amdkfd_get_local_mem_info() and amdgpu_amdkfd_xcp_memory_size() by
the smaller of TTM's page limit and KFD's system memory limit.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
> index 0dab267eb3828..17c12edca4371 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 min((u64)ttm_tt_pages_limit() << PAGE_SHIFT,
> + amdgpu_amdkfd_system_mem_limit());
> +}
[Severity: Low]
Can amdgpu_amdkfd_gtt_pool_size() return a byte count that is not aligned
to PAGE_SIZE?
In amdgpu_amdkfd_gpuvm_init_mem_limits(), max_system_mem_limit is derived
from mem - (mem >> 6), which is only 64-byte aligned whenever
si.totalram - si.totalhigh is not a multiple of 64 pages. Since
amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu() rounds every allocation up with
PAGE_ALIGN(size) before checking max_system_mem_limit, any sub-page
remainder advertised in local_mem_size_public and
amdgpu_amdkfd_xcp_memory_size() cannot be allocated. Rounding the result
down with ALIGN_DOWN(..., PAGE_SIZE) would match the partition branch in
amdgpu_amdkfd_xcp_memory_size().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127082854.112025-1-Priya.Hosur@amd.com?part=2
^ permalink raw reply [flat|nested] 10+ messages in thread* RE: [PATCH 2/2] drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit
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
1 sibling, 0 replies; 10+ messages in thread
From: Stamenkovic, Strahinja @ 2026-11-27 8:52 UTC (permalink / raw)
To: Hosur, Priya, amd-gfx@lists.freedesktop.org, Deucher, Alexander,
Kuehling, Felix, Koenig, Christian, Lazar, Lijo
Cc: Vishwakarma, Pratik, Gopalakrishnan, Veerabadhran (Veera)
Signed-off-by: Strahinja Stamenkovic <strahinja.stamenkovic@amd.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v2 0/2] drm/amdkfd: report realistic free/total memory on GTT-backed APUs
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:28 ` [PATCH 2/2] drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit Priya Hosur
@ 2026-11-27 10:19 ` 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 ` [PATCH v2 2/2] drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit Priya Hosur
4 siblings, 0 replies; 10+ messages in thread
From: Priya Hosur @ 2026-11-27 10:19 UTC (permalink / raw)
To: amd-gfx, Strahinja Stamenkovic, Alex Deucher, Felix Kuehling,
Christian König, Lijo Lazar
Cc: Priya Hosur, Pratik Vishwakarma, Veerabadhran Gopalakrishnan
On APUs where KFD serves VRAM allocations from GTT (apu_prefer_gtt),
the memory reported to user space does not match what can be allocated:
- Free (AMDKFD_IOC_AVAILABLE_MEMORY -> hipMemGetInfo()) only subtracts
KFD's own allocations, so host memory used by other processes is
ignored.
- Total (topology local memory size) is the TTM pages limit, which may
be above physical RAM, while KFD refuses allocations beyond its
system memory limit.
Frameworks such as vLLM, llama.cpp and PyTorch size buffers from these
values and over-commit, ending in the OOM killer.
Patch 1 bounds the reported free memory by si_mem_available(). Patch 2
bounds the reported pool size by KFD's system memory limit. Only the
reported values change; allocation limits and GTT/TTM sizing are not
touched. Both are skipped with no_system_mem_limit=1. Carve-out backed
APUs and dGPUs are not affected.
Tested on gfx1151 (Ryzen AI MAX+ 395, 62 GiB RAM), HIP free/total vs
MemAvailable (GiB):
ttm.pages_limit = 80 GiB stock 7.0.0-44 v2
total 80.00 59.69
40 GiB held by another process
free / MemAvailable 59.67 / 20.39 19.52 / 19.52
default ttm.pages_limit (31.08 GiB) v1
total 31.08 (unchanged)
40 GiB held: free / MemAvailable 19.16 / 19.16
With v2 the reported total is 64089890816 bytes, i.e. KFD's system
memory limit rounded down to PAGE_SIZE.
With no_system_mem_limit=1 the reported values are the same as without
this series. kfdtest (KFDMemoryTest, KFDLocalMemoryTest,
KFDTopologyTest, KFDOpenCloseKFDTest) results are identical with and
without the series at ttm.pages_limit = 80 GiB. Not tested: MI300A, dGPU.
Changes in v2:
- Add Strahinja's Signed-off-by after Co-developed-by (Sashiko review).
- Patch 2: round the reported pool size down to PAGE_SIZE, since
max_system_mem_limit is not necessarily page aligned while KFD
allocations are (Sashiko review).
Changes in v1:
- Initial version, based on amd-staging-drm-next. In patch 1 the bound
is applied in the amdgpu_amdkfd_get_available_memory() wrapper, since
__get_available_memory() is also used by the is_app_apu allocation
path after commit 32abf4fe544b ("drm/amdkfd: correct vram_available
calculation").
v1: https://lore.kernel.org/amd-gfx/20261127082854.112025-1-Priya.Hosur@amd.com/
Priya Hosur (2):
drm/amdkfd: bound APU available memory by host available memory
drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 15 +++++++++++++--
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 6 ++++++
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 19 +++++++++++++++++++
3 files changed, 38 insertions(+), 2 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 10+ messages in thread* [PATCH v2 1/2] drm/amdkfd: bound APU available memory by host available memory
2026-11-27 8:28 [PATCH 0/2] drm/amdkfd: report realistic free/total memory on GTT-backed APUs Priya Hosur
` (2 preceding siblings ...)
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
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
4 siblings, 0 replies; 10+ messages in thread
From: Priya Hosur @ 2026-11-27 10:19 UTC (permalink / raw)
To: amd-gfx, Strahinja Stamenkovic, Alex Deucher, Felix Kuehling,
Christian König, Lijo Lazar
Cc: Priya Hosur, Pratik Vishwakarma, Veerabadhran Gopalakrishnan
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
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v2 2/2] drm/amdkfd: bound the APU GTT pool size by KFD's system memory limit
2026-11-27 8:28 [PATCH 0/2] drm/amdkfd: report realistic free/total memory on GTT-backed APUs Priya Hosur
` (3 preceding siblings ...)
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
4 siblings, 0 replies; 10+ messages in thread
From: Priya Hosur @ 2026-11-27 10:19 UTC (permalink / raw)
To: amd-gfx, Strahinja Stamenkovic, Alex Deucher, Felix Kuehling,
Christian König, Lijo Lazar
Cc: Priya Hosur, Pratik Vishwakarma, Veerabadhran Gopalakrishnan
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
^ permalink raw reply related [flat|nested] 10+ messages in thread