Skip to content

drm/amdkfd: report realistic free/total memory on GTT-backed APUs

Priya Hosur amd-gfx 2 versions New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 0 repliesNew
  2. v12 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- 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).

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2drm/amdkfd: bound APU available memory by host available memorydrivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c+10 -00 replies
2/2drm/amdkfd: bound the APU GTT pool size by KFD's system memory limitdrivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c+28 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/2] drm/amdkfd: report realistic free/total memory on GTT-backed APUs

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/[email protected]/

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(-)
Signature · 1 line
2.43.0