drm/amdkfd: check system memory when set apu_prefer_gtt
Subsystems (3)
PATCH v2 1/1 drm/amdkfd: check system memory when set apu_prefer_gtt
Current apu_prefer_gtt setting only check gtt_size, which could be set by user to a larger than system memory value (via ttm modules parameter pages_limit). E.g. carveout vram 32GB, gtt_size 50GB (via ttm modules parameter pages_limit), system memory 31GB. In that case, apu_prefer_gtt will be set incorrectly. Take system memory into account when set apu_prefer_gtt.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 -- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++++- 4 files changed, 12 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -2
@@ -170,8 +170,6 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)int i;int last_valid_bit; -amdgpu_amdkfd_gpuvm_init_mem_limits (); - if (adev->kfd.dev) { struct kgd2kfd_shared_resources gpu_resources = { .compute_vmid_bitmap =
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -2
@@ -369,7 +369,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id);#if IS_ENABLED (CONFIG_HSA_AMD ) -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ); +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void );void amdgpu_amdkfd_gpuvm_destroy_cb (struct amdgpu_device *adev,struct amdgpu_vm *vm);
@@ -382,7 +382,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo);void amdgpu_amdkfd_reserve_system_mem (uint64_t size);#else static inline -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { }
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4 -2
@@ -109,13 +109,13 @@ static bool reuse_dmamap(struct amdgpu_device *adev, struct amdgpu_device *bo_ad* System (TTM + userptr) memory - 15/16th System RAM * TTM memory - 3/8th System RAM */ -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) {struct sysinfo si;uint64_t mem;if (kfd_mem_limit.max_system_mem_limit) -return ; +return kfd_mem_limit.max_system_mem_limit;si_meminfo (&si); mem = si.totalram - si.totalhigh;
@@ -132,6 +132,8 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void)pr_debug ("Kernel memory limit %lluM, TTM limit %lluM\n" , (kfd_mem_limit.max_system_mem_limit >>20 ), (kfd_mem_limit.max_ttm_mem_limit >>20 )); + +return kfd_mem_limit.max_system_mem_limit; }void amdgpu_amdkfd_reserve_system_mem (uint64_t size)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +6 -1
@@ -2071,6 +2071,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr,int amdgpu_ttm_init (struct amdgpu_device *adev) {uint64_t gtt_size; +uint64_t max_system_mem_limit;int r;dma_set_max_seg_size (adev->dev,UINT_MAX );
@@ -2210,8 +2211,12 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)dev_info (adev->dev," %uM of GTT memory ready.\n" , (unsigned int )(gtt_size / (1024 *1024 ))); + + max_system_mem_limit =amdgpu_amdkfd_gpuvm_init_mem_limits (); +if (adev->flags &AMD_IS_APU ) { -if (adev->gmc.real_vram_size < gtt_size) +if (adev->gmc.real_vram_size < gtt_size && + adev->gmc.real_vram_size < max_system_mem_limit) adev->apu_prefer_gtt = true; }
Signature · 1 line
2.43.0
Quoted 7 lines · Yifan Zhang
Current
apu_prefer_gttsetting only checkgtt_size, which could be set by user to a larger than system memory value (via ttm modules parameterpages_limit). E.g. carveout vram 32GB,gtt_size50GB (via ttm modules parameterpages_limit), system memory 31GB. In that case,apu_prefer_gttwill be set incorrectly. Take system memory into account when setapu_prefer_gtt.
Wouldn't it be cleaner to do this in TTM? IE test that a bad option was set by user pages_limit value and then show something like:
if (user > possible) {
pr_warn("Requested invalid %d pages, limiting to %d pages", user,
possible);
user = possible;
}Then we can always trust what we get from TTM.
Quoted 98 lines
Signed-off-by Yifan Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 -- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++++- 4 files changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-2@@ -170,8 +170,6 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)int i;int last_valid_bit; -amdgpu_amdkfd_gpuvm_init_mem_limits (); - if (adev->kfd.dev) { struct kgd2kfd_shared_resources gpu_resources = { .compute_vmid_bitmap =drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2
-2@@ -369,7 +369,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id);#if IS_ENABLED (CONFIG_HSA_AMD ) -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ); +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void );void amdgpu_amdkfd_gpuvm_destroy_cb (struct amdgpu_device *adev,struct amdgpu_vm *vm);@@ -382,7 +382,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo);void amdgpu_amdkfd_reserve_system_mem (uint64_t size);#else static inline -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { }drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4
-2@@ -109,13 +109,13 @@ static bool reuse_dmamap(struct amdgpu_device *adev, struct amdgpu_device *bo_ad* System (TTM + userptr) memory - 15/16th System RAM * TTM memory - 3/8th System RAM */ -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) {struct sysinfo si;uint64_t mem;if (kfd_mem_limit.max_system_mem_limit) -return ; +return kfd_mem_limit.max_system_mem_limit;si_meminfo (&si); mem = si.totalram - si.totalhigh;@@ -132,6 +132,8 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void)pr_debug ("Kernel memory limit %lluM, TTM limit %lluM\n" , (kfd_mem_limit.max_system_mem_limit >>20 ), (kfd_mem_limit.max_ttm_mem_limit >>20 )); + +return kfd_mem_limit.max_system_mem_limit; }void amdgpu_amdkfd_reserve_system_mem (uint64_t size)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +6
-1@@ -2071,6 +2071,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr,int amdgpu_ttm_init (struct amdgpu_device *adev) {uint64_t gtt_size; +uint64_t max_system_mem_limit;int r;dma_set_max_seg_size (adev->dev,UINT_MAX );@@ -2210,8 +2211,12 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)dev_info (adev->dev," %uM of GTT memory ready.\n" , (unsigned int )(gtt_size / (1024 *1024 ))); + + max_system_mem_limit =amdgpu_amdkfd_gpuvm_init_mem_limits (); +if (adev->flags &AMD_IS_APU ) { -if (adev->gmc.real_vram_size < gtt_size) +if (adev->gmc.real_vram_size < gtt_size && + adev->gmc.real_vram_size < max_system_mem_limit) adev->apu_prefer_gtt = true; }
[AMD Official Use Only - AMD Internal Distribution Only]
Yes, I agree. I’ve just been notified that this memory configuration is a mistake rather than a valid user case. So the fix is low priority for now.
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Friday, March 20, 2026 11:14 AM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdkfd: check system memory when set apu_prefer_gtt
Quoted 7 lines · Yifan Zhang
Current
apu_prefer_gttsetting only checkgtt_size, which could be set by user to a larger than system memory value (via ttm modules parameterpages_limit). E.g. carveout vram 32GB,gtt_size50GB (via ttm modules parameterpages_limit), system memory 31GB. In that case,apu_prefer_gttwill be set incorrectly. Take system memory into account when setapu_prefer_gtt.
Wouldn't it be cleaner to do this in TTM? IE test that a bad option was set by user pages_limit value and then show something like:
if (user > possible) {
pr_warn("Requested invalid %d pages, limiting to %d pages", user, possible);
user = possible;
}Then we can always trust what we get from TTM.
Quoted 103 lines
Signed-off-by Yifan Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 -- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++++- 4 files changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-2@@ -170,8 +170,6 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)int i;int last_valid_bit; -amdgpu_amdkfd_gpuvm_init_mem_limits (); - if (adev->kfd.dev) { struct kgd2kfd_shared_resources gpu_resources = { .compute_vmid_bitmap =drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2
-2@@ -369,7 +369,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id);#if IS_ENABLED (CONFIG_HSA_AMD ) -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ); +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void );void amdgpu_amdkfd_gpuvm_destroy_cb (struct amdgpu_device *adev,struct amdgpu_vm *vm);@@ -382,7 +382,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo);void amdgpu_amdkfd_reserve_system_mem (uint64_t size);#else static inline -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { }drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4
-2@@ -109,13 +109,13 @@ static bool reuse_dmamap(struct amdgpu_device *adev, struct amdgpu_device *bo_ad* System (TTM + userptr) memory - 15/16th System RAM * TTM memory - 3/8th System RAM */ -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) {struct sysinfo si;uint64_t mem;if (kfd_mem_limit.max_system_mem_limit) -return ; +return kfd_mem_limit.max_system_mem_limit;si_meminfo (&si); mem = si.totalram - si.totalhigh;@@ -132,6 +132,8 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void)pr_debug ("Kernel memory limit %lluM, TTM limit %lluM\n" , (kfd_mem_limit.max_system_mem_limit >>20 ), (kfd_mem_limit.max_ttm_mem_limit >>20 )); + +return kfd_mem_limit.max_system_mem_limit; } void amdgpu_amdkfd_reserve_system_mem(uint64_t size) diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index714fd8d12ca5..df98ece071e1100644drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -2071,6 +2071,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr,int amdgpu_ttm_init (struct amdgpu_device *adev) {uint64_t gtt_size; +uint64_t max_system_mem_limit;int r; dma_set_max_seg_size(adev->dev, UINT_MAX); @@ -2210,8 +2211,12 @@int
amdgpu_ttm_init(struct amdgpu_device *adev)dev_info(adev->dev, " %uM of GTT memory ready.\n", (unsigned int)(gtt_size / (1024 * 1024)));drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5
-1+ + max_system_mem_limit =amdgpu_amdkfd_gpuvm_init_mem_limits (); +if (adev->flags &AMD_IS_APU ) { -if (adev->gmc.real_vram_size < gtt_size) +if (adev->gmc.real_vram_size < gtt_size && + adev->gmc.real_vram_size < max_system_mem_limit) adev->apu_prefer_gtt = true; }
I think there is actually a very easy way to trigger it and it's not obvious that a user messed it up.
Assume you're on a 128GB system with VRAM set to 512MB.
1) Set TTM page limit corresponding to 96GB
2) Use uma_carveout sysfs or BIOS to set VRAM to 96GB
3) Reboot system
4) Now VRAM is 96GB, but the page limit was a module parameter and will be wrong.
I actually /think/ that the RFC [1] I proposed a few weeks ago could be a good way to prevent this. By using EFI variable instead, TTM could sanity check anything it reads at startup and save sane values to EFI for the next reboot (if they're insane).
https://lore.kernel.org/dri-devel/[email protected]/ [1]
Quoted 135 lines · Yifan
[AMD Official Use Only - AMD Internal Distribution Only]
Yes, I agree. I’ve just been notified that this memory configuration is a mistake rather than a valid user case. So the fix is low priority for now.
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Friday, March 20, 2026 11:14 AM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdkfd: check system memory when setapu_prefer_gttQuoted 7 lines · Yifan Zhang
Current
apu_prefer_gttsetting only checkgtt_size, which could be set by user to a larger than system memory value (via ttm modules parameterpages_limit). E.g. carveout vram 32GB,gtt_size50GB (via ttm modules parameterpages_limit), system memory 31GB. In that case,apu_prefer_gttwill be set incorrectly. Take system memory into account when setapu_prefer_gtt.Wouldn't it be cleaner to do this in TTM? IE test that a bad option was set by user
pages_limitvalue and then show something like:if (user > possible) { pr_warn("Requested invalid %d pages, limiting to %d pages", user, possible); user = possible; }Then we can always trust what we get from TTM.
Quoted 103 lines
Signed-off-by Yifan Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 -- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++++- 4 files changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-2@@ -170,8 +170,6 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)int i;int last_valid_bit; -amdgpu_amdkfd_gpuvm_init_mem_limits (); - if (adev->kfd.dev) { struct kgd2kfd_shared_resources gpu_resources = { .compute_vmid_bitmap =drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2
-2@@ -369,7 +369,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id);#if IS_ENABLED (CONFIG_HSA_AMD ) -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ); +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void );void amdgpu_amdkfd_gpuvm_destroy_cb (struct amdgpu_device *adev,struct amdgpu_vm *vm);@@ -382,7 +382,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo);void amdgpu_amdkfd_reserve_system_mem (uint64_t size);#else static inline -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { }drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4
-2@@ -109,13 +109,13 @@ static bool reuse_dmamap(struct amdgpu_device *adev, struct amdgpu_device *bo_ad* System (TTM + userptr) memory - 15/16th System RAM * TTM memory - 3/8th System RAM */ -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) {struct sysinfo si;uint64_t mem;if (kfd_mem_limit.max_system_mem_limit) -return ; +return kfd_mem_limit.max_system_mem_limit;si_meminfo (&si); mem = si.totalram - si.totalhigh;@@ -132,6 +132,8 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void)pr_debug ("Kernel memory limit %lluM, TTM limit %lluM\n" , (kfd_mem_limit.max_system_mem_limit >>20 ), (kfd_mem_limit.max_ttm_mem_limit >>20 )); + +return kfd_mem_limit.max_system_mem_limit; } void amdgpu_amdkfd_reserve_system_mem(uint64_t size) diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index714fd8d12ca5..df98ece071e1100644drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -2071,6 +2071,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr,int amdgpu_ttm_init (struct amdgpu_device *adev) {uint64_t gtt_size; +uint64_t max_system_mem_limit;int r; dma_set_max_seg_size(adev->dev, UINT_MAX); @@ -2210,8 +2211,12 @@int
amdgpu_ttm_init(struct amdgpu_device *adev)dev_info(adev->dev, " %uM of GTT memory ready.\n", (unsigned int)(gtt_size / (1024 * 1024)));drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5
-1+ + max_system_mem_limit =amdgpu_amdkfd_gpuvm_init_mem_limits (); +if (adev->flags &AMD_IS_APU ) { -if (adev->gmc.real_vram_size < gtt_size) +if (adev->gmc.real_vram_size < gtt_size && + adev->gmc.real_vram_size < max_system_mem_limit) adev->apu_prefer_gtt = true; }
Christian König
maintainerHi Mario,
first of all please loop me in on TTM changes as maintainer explicitely. I don't see everything which flys by on dri-devel.
Then changing the 50% limit is an absolutely NO-GO. It's completely irrelevant that AI wants to use more, HPC use cases complained about that for decades, but we simply can't do that reliable.
Regards,
Christian.
Quoted 149 lines · Mario Limonciello
I think there is actually a very easy way to trigger it and it's not obvious that a user messed it up.
Assume you're on a 128GB system with VRAM set to 512MB.
1) Set TTM page limit corresponding to 96GB
2) Useuma_carveoutsysfs or BIOS to set VRAM to 96GB
3) Reboot system
4) Now VRAM is 96GB, but the page limit was a module parameter and will be wrong.I actually /think/ that the RFC [1] I proposed a few weeks ago could be a good way to prevent this. By using EFI variable instead, TTM could sanity check anything it reads at startup and save sane values to EFI for the next reboot (if they're insane).
https://lore.kernel.org/dri-devel/[email protected]/ [1]
Quoted 135 lines · Yifan
[AMD Official Use Only - AMD Internal Distribution Only]
Yes, I agree. I’ve just been notified that this memory configuration is a mistake rather than a valid user case. So the fix is low priority for now.
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Friday, March 20, 2026 11:14 AM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdkfd: check system memory when setapu_prefer_gttQuoted 7 lines · Yifan Zhang
Current
apu_prefer_gttsetting only checkgtt_size, which could be set by user to a larger than system memory value (via ttm modules parameterpages_limit). E.g. carveout vram 32GB,gtt_size50GB (via ttm modules parameterpages_limit), system memory 31GB. In that case,apu_prefer_gttwill be set incorrectly. Take system memory into account when setapu_prefer_gtt.Wouldn't it be cleaner to do this in TTM? IE test that a bad option was set by user
pages_limitvalue and then show something like:if (user > possible) {
pr_warn("Requested invalid %d pages, limiting to %d pages", user, possible); user = possible;
}Then we can always trust what we get from TTM.
Quoted 103 lines
Signed-off-by Yifan Zhang <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 -- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 4 ++--drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c| 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++++-4 files changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-2@@ -170,8 +170,6 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev) int i; int last_valid_bit; - amdgpu_amdkfd_gpuvm_init_mem_limits(); - if (adev->kfd.dev) { struct kgd2kfd_shared_resources gpu_resources = {.compute_vmid_bitmap =
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-1@@ -369,7 +369,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id); #if IS_ENABLED(CONFIG_HSA_AMD) -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ); +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ); void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev, struct amdgpu_vm *vm);@@ -382,7 +382,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo); void amdgpu_amdkfd_reserve_system_mem(uint64_t size); #elsestatic inline
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-1-void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ){
}drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4
-2@@ -109,13 +109,13 @@ static bool reuse_dmamap(struct amdgpu_device *adev, struct amdgpu_device *bo_ad* System (TTM + userptr) memory - 15/16th System RAM * TTM memory - 3/8th System RAM */ -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { struct sysinfo si; uint64_t mem; if (kfd_mem_limit.max_system_mem_limit) - return; + return kfd_mem_limit.max_system_mem_limit; si_meminfo(&si); mem = si.totalram - si.totalhigh;@@ -132,6 +132,8 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void) pr_debug("Kernel memory limit %lluM, TTM limit %lluM\n", (kfd_mem_limit.max_system_mem_limit >> 20), (kfd_mem_limit.max_ttm_mem_limit >> 20)); + + return kfd_mem_limit.max_system_mem_limit; }void
amdgpu_amdkfd_reserve_system_mem(uint64_t size)diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index714fd8d12ca5..df98ece071e1100644drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -2071,6 +2071,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr, int amdgpu_ttm_init(struct amdgpu_device *adev) { uint64_t gtt_size; + uint64_t max_system_mem_limit; int r;
dma_set_max_seg_size(adev->dev, UINT_MAX); @@ -2210,8 +2211,12 @@ intamdgpu_ttm_init(struct amdgpu_device *adev)dev_info(adev->dev, " %uM of GTT memory ready.\n", (unsigned int)(gtt_size / (1024 * 1024)));drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3
-0+ + max_system_mem_limit = amdgpu_amdkfd_gpuvm_init_mem_limits(); +if (
adev->flags&AMD_IS_APU) {
- if (adev->gmc.real_vram_size<gtt_size)
+ if (adev->gmc.real_vram_size<gtt_size&&
+adev->gmc.real_vram_size<max_system_mem_limit)adev->apu_prefer_gtt= true;
}
Quoted 3 lines · Christian König
Hi Mario,
first of all please loop me in on TTM changes as maintainer explicitely. I don't see everything which flys by on dri-devel.
Sure. I was initially just looking for anyone comments on it, didn't think it was worth bubbling to top of your mailbox for an RFC.
Quoted 2 lines
Then changing the 50% limit is an absolutely NO-GO. It's completely irrelevant that AI wants to use more, HPC use cases complained about that for decades, but we simply can't do that reliable.
What does HPC do now when they need more? Tell people to put page limit on the kernel command line? This shouldn't be any different than status quo before - except that user intent can persist.
Quoted 155 lines
Regards,
Christian.Quoted 149 lines · Mario Limonciello
I think there is actually a very easy way to trigger it and it's not obvious that a user messed it up.
Assume you're on a 128GB system with VRAM set to 512MB.
1) Set TTM page limit corresponding to 96GB
2) Useuma_carveoutsysfs or BIOS to set VRAM to 96GB
3) Reboot system
4) Now VRAM is 96GB, but the page limit was a module parameter and will be wrong.I actually /think/ that the RFC [1] I proposed a few weeks ago could be a good way to prevent this. By using EFI variable instead, TTM could sanity check anything it reads at startup and save sane values to EFI for the next reboot (if they're insane).
https://lore.kernel.org/dri-devel/[email protected]/ [1]
Quoted 135 lines · Yifan
[AMD Official Use Only - AMD Internal Distribution Only]
Yes, I agree. I’ve just been notified that this memory configuration is a mistake rather than a valid user case. So the fix is low priority for now.
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Friday, March 20, 2026 11:14 AM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdkfd: check system memory when setapu_prefer_gttQuoted 7 lines · Yifan Zhang
Current
apu_prefer_gttsetting only checkgtt_size, which could be set by user to a larger than system memory value (via ttm modules parameterpages_limit). E.g. carveout vram 32GB,gtt_size50GB (via ttm modules parameterpages_limit), system memory 31GB. In that case,apu_prefer_gttwill be set incorrectly. Take system memory into account when setapu_prefer_gtt.Wouldn't it be cleaner to do this in TTM? IE test that a bad option was set by user
pages_limitvalue and then show something like:if (user > possible) {
pr_warn("Requested invalid %d pages, limiting to %d pages", user, possible); user = possible;
}Then we can always trust what we get from TTM.
Quoted 103 lines
Signed-off-by Yifan Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 -- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++++- 4 files changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-2@@ -170,8 +170,6 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev) int i; int last_valid_bit; - amdgpu_amdkfd_gpuvm_init_mem_limits(); - if (adev->kfd.dev) { struct kgd2kfd_shared_resources gpu_resources = { .compute_vmid_bitmap =drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2
-2@@ -369,7 +369,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id); #if IS_ENABLED(CONFIG_HSA_AMD) -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ); +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ); void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev, struct amdgpu_vm *vm);@@ -382,7 +382,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo); void amdgpu_amdkfd_reserve_system_mem(uint64_t size); #else static inline -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { }drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4
-2@@ -109,13 +109,13 @@ static bool reuse_dmamap(struct amdgpu_device *adev, struct amdgpu_device *bo_ad* System (TTM + userptr) memory - 15/16th System RAM * TTM memory - 3/8th System RAM */ -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { struct sysinfo si; uint64_t mem; if (kfd_mem_limit.max_system_mem_limit) - return; + return kfd_mem_limit.max_system_mem_limit; si_meminfo(&si); mem = si.totalram - si.totalhigh;@@ -132,6 +132,8 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void) pr_debug("Kernel memory limit %lluM, TTM limit %lluM\n", (kfd_mem_limit.max_system_mem_limit >> 20), (kfd_mem_limit.max_ttm_mem_limit >> 20)); + + return kfd_mem_limit.max_system_mem_limit; } void amdgpu_amdkfd_reserve_system_mem(uint64_t size) diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index714fd8d12ca5..df98ece071e1100644drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -2071,6 +2071,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr, int amdgpu_ttm_init(struct amdgpu_device *adev) { uint64_t gtt_size; + uint64_t max_system_mem_limit; int r; dma_set_max_seg_size(adev->dev, UINT_MAX); @@ -2210,8 +2211,12 @@int
amdgpu_ttm_init(struct amdgpu_device *adev)
dev_info(adev->dev, " %uM of GTT memory ready.\n", (unsigned int)(gtt_size / (1024 * 1024)));drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5
-1+ + max_system_mem_limit = amdgpu_amdkfd_gpuvm_init_mem_limits(); + if (adev->flags & AMD_IS_APU) { - if (adev->gmc.real_vram_size < gtt_size) + if (adev->gmc.real_vram_size < gtt_size && + adev->gmc.real_vram_size < max_system_mem_limit) adev->apu_prefer_gtt = true; }
Christian König
maintainerHi Mario,
Quoted 8 lines · Mario Limonciello
Quoted 3 lines · Christian König
Hi Mario,
first of all please loop me in on TTM changes as maintainer explicitely. I don't see everything which flys by on dri-devel.
Sure. I was initially just looking for anyone comments on it, didn't think it was worth bubbling to top of your mailbox for an RFC.
I usually completely miss such stuff otherwise. I'm not very proud of it, but I have a backlog of multiple thousands of mailing list mails I couldn't look into.
Quoted 4 lines
Quoted 2 lines
Then changing the 50% limit is an absolutely NO-GO. It's completely irrelevant that AI wants to use more, HPC use cases complained about that for decades, but we simply can't do that reliable.
What does HPC do now when they need more? Tell people to put page limit on the kernel command line?
Yes, either that or other similar workarounds.
Quoted 1 line
This shouldn't be any different than status quo before - except that user intent can persist.
The key point is the system starts to become unstable when you go over 50%. We have tons of complains about that as well from HPC customers.
The problem is that TTMs eviction code needs memory to swap GPU buffers out to disk, that's why we use the 50% limit here.
Intel has been working on and provides an alternative shrinker callback (see drivers/gpu/drm/xe/xe_shrinker.c) to work around that and so lift the 50% limit. But so far that is only implemented for XE.
If you want to fix this for amdgpu just take the xe_shrinker as an example and implement that same stuff for us as well.
Regards,
Christian.
Quoted 157 lines
Quoted 156 lines
Regards,
Christian.Quoted 149 lines · Mario Limonciello
I think there is actually a very easy way to trigger it and it's not obvious that a user messed it up.
Assume you're on a 128GB system with VRAM set to 512MB.
1) Set TTM page limit corresponding to 96GB
2) Useuma_carveoutsysfs or BIOS to set VRAM to 96GB
3) Reboot system
4) Now VRAM is 96GB, but the page limit was a module parameter and will be wrong.I actually /think/ that the RFC [1] I proposed a few weeks ago could be a good way to prevent this. By using EFI variable instead, TTM could sanity check anything it reads at startup and save sane values to EFI for the next reboot (if they're insane).
https://lore.kernel.org/dri-devel/[email protected]/ [1]
Quoted 135 lines · Yifan
[AMD Official Use Only - AMD Internal Distribution Only]
Yes, I agree. I’ve just been notified that this memory configuration is a mistake rather than a valid user case. So the fix is low priority for now.
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Friday, March 20, 2026 11:14 AM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdkfd: check system memory when setapu_prefer_gttQuoted 7 lines · Yifan Zhang
Current
apu_prefer_gttsetting only checkgtt_size, which could be set by user to a larger than system memory value (via ttm modules parameterpages_limit). E.g. carveout vram 32GB,gtt_size50GB (via ttm modules parameterpages_limit), system memory 31GB. In that case,apu_prefer_gttwill be set incorrectly. Take system memory into account when setapu_prefer_gtt.Wouldn't it be cleaner to do this in TTM? IE test that a bad option was set by user
pages_limitvalue and then show something like:if (user > possible) {
pr_warn("Requested invalid %d pages, limiting to %d pages", user, possible); user = possible;
}Then we can always trust what we get from TTM.
Quoted 103 lines
Signed-off-by Yifan Zhang <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 -- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 4 ++--drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c| 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++++-4 files changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-2@@ -170,8 +170,6 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev) int i; int last_valid_bit; - amdgpu_amdkfd_gpuvm_init_mem_limits(); - if (adev->kfd.dev) { struct kgd2kfd_shared_resources gpu_resources = {.compute_vmid_bitmap =
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-1@@ -369,7 +369,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id); #if IS_ENABLED(CONFIG_HSA_AMD) -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ); +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ); void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev, struct amdgpu_vm *vm);@@ -382,7 +382,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo); void amdgpu_amdkfd_reserve_system_mem(uint64_t size); #elsestatic inline
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-1-void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ){
}drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4
-2@@ -109,13 +109,13 @@ static bool reuse_dmamap(struct amdgpu_device *adev, struct amdgpu_device *bo_ad* System (TTM + userptr) memory - 15/16th System RAM * TTM memory - 3/8th System RAM */ -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { struct sysinfo si; uint64_t mem; if (kfd_mem_limit.max_system_mem_limit) - return; + return kfd_mem_limit.max_system_mem_limit; si_meminfo(&si); mem = si.totalram - si.totalhigh;@@ -132,6 +132,8 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void) pr_debug("Kernel memory limit %lluM, TTM limit %lluM\n", (kfd_mem_limit.max_system_mem_limit >> 20), (kfd_mem_limit.max_ttm_mem_limit >> 20)); + + return kfd_mem_limit.max_system_mem_limit; }void
amdgpu_amdkfd_reserve_system_mem(uint64_t size)diff --gita/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index714fd8d12ca5..df98ece071e1100644drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -2071,6 +2071,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr, int amdgpu_ttm_init(struct amdgpu_device *adev) { uint64_t gtt_size; + uint64_t max_system_mem_limit; int r;
dma_set_max_seg_size(adev->dev, UINT_MAX); @@ -2210,8 +2211,12 @@ intamdgpu_ttm_init(struct amdgpu_device *adev)dev_info(adev->dev, " %uM of GTT memory ready.\n", (unsigned int)(gtt_size / (1024 * 1024)));drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3
-0+ + max_system_mem_limit = amdgpu_amdkfd_gpuvm_init_mem_limits(); +if (
adev->flags&AMD_IS_APU) {
- if (adev->gmc.real_vram_size<gtt_size)
+ if (adev->gmc.real_vram_size<gtt_size&&
+adev->gmc.real_vram_size<max_system_mem_limit)adev->apu_prefer_gtt= true;
}
Quoted 5 lines · Christian König
Hi Mario,
Quoted 2 lines · Mario Limonciello
Quoted 8 lines
Quoted 6 lines · Christian König
Quoted 3 lines
Hi Mario,
first of all please loop me in on TTM changes as maintainer explicitely. I don't see everything which flys by on dri-devel.
Sure. I was initially just looking for anyone comments on it, didn't think it was worth bubbling to top of your mailbox for an RFC.
I usually completely miss such stuff otherwise. I'm not very proud of it, but I have a backlog of multiple thousands of mailing list mails I couldn't look into.
Ack.
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
Then changing the 50% limit is an absolutely NO-GO. It's completely irrelevant that AI wants to use more, HPC use cases complained about that for decades, but we simply can't do that reliable.
What does HPC do now when they need more? Tell people to put page limit on the kernel command line?
Quoted 7 lines
Yes, either that or other similar workarounds.
Quoted 1 line
This shouldn't be any different than status quo before - except that user intent can persist.
The key point is the system starts to become unstable when you go over 50%. We have tons of complains about that as well from HPC customers.
The problem is that TTMs eviction code needs memory to swap GPU buffers out to disk, that's why we use the 50% limit here.
Do you mean for eviction in cases that the hardware is going to D3 like a system power state transition?
What kind of instability is actually hit? I'd like to reproduce this first hand to understand it better.
Because as it stands today there is plenty of ROCm documentation that is user facing saying go increase your page limit if you want to load the big models.
Quoted 4 lines
Intel has been working on and provides an alternative shrinker callback (see
drivers/gpu/drm/xe/xe_shrinker.c) to work around that and so lift the 50% limit. But so far that is only implemented for XE.If you want to fix this for amdgpu just take the
xe_shrinkeras an example and implement that same stuff for us as well.
Do you know of limitations with it? I wonder would it make sense to just move it to ttm for all drivers to use?
Quoted 162 lines
Regards,
Christian.Quoted 157 lines
Quoted 156 lines
Regards,
Christian.Quoted 149 lines · Mario Limonciello
I think there is actually a very easy way to trigger it and it's not obvious that a user messed it up.
Assume you're on a 128GB system with VRAM set to 512MB.
1) Set TTM page limit corresponding to 96GB
2) Useuma_carveoutsysfs or BIOS to set VRAM to 96GB
3) Reboot system
4) Now VRAM is 96GB, but the page limit was a module parameter and will be wrong.I actually /think/ that the RFC [1] I proposed a few weeks ago could be a good way to prevent this. By using EFI variable instead, TTM could sanity check anything it reads at startup and save sane values to EFI for the next reboot (if they're insane).
https://lore.kernel.org/dri-devel/[email protected]/ [1]
Quoted 135 lines · Yifan
[AMD Official Use Only - AMD Internal Distribution Only]
Yes, I agree. I’ve just been notified that this memory configuration is a mistake rather than a valid user case. So the fix is low priority for now.
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Friday, March 20, 2026 11:14 AM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdkfd: check system memory when setapu_prefer_gttQuoted 7 lines · Yifan Zhang
Current
apu_prefer_gttsetting only checkgtt_size, which could be set by user to a larger than system memory value (via ttm modules parameterpages_limit). E.g. carveout vram 32GB,gtt_size50GB (via ttm modules parameterpages_limit), system memory 31GB. In that case,apu_prefer_gttwill be set incorrectly. Take system memory into account when setapu_prefer_gtt.Wouldn't it be cleaner to do this in TTM? IE test that a bad option was set by user
pages_limitvalue and then show something like:if (user > possible) {
pr_warn("Requested invalid %d pages, limiting to %d pages", user, possible); user = possible;
}Then we can always trust what we get from TTM.
Quoted 103 lines
Signed-off-by Yifan Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 -- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++++- 4 files changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-2@@ -170,8 +170,6 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev) int i; int last_valid_bit; - amdgpu_amdkfd_gpuvm_init_mem_limits(); - if (adev->kfd.dev) { struct kgd2kfd_shared_resources gpu_resources = { .compute_vmid_bitmap =drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2
-2@@ -369,7 +369,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id); #if IS_ENABLED(CONFIG_HSA_AMD) -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ); +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ); void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device *adev, struct amdgpu_vm *vm);@@ -382,7 +382,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo); void amdgpu_amdkfd_reserve_system_mem(uint64_t size); #else static inline -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { }drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4
-2@@ -109,13 +109,13 @@ static bool reuse_dmamap(struct amdgpu_device *adev, struct amdgpu_device *bo_ad* System (TTM + userptr) memory - 15/16th System RAM * TTM memory - 3/8th System RAM */ -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { struct sysinfo si; uint64_t mem; if (kfd_mem_limit.max_system_mem_limit) - return; + return kfd_mem_limit.max_system_mem_limit; si_meminfo(&si); mem = si.totalram - si.totalhigh;@@ -132,6 +132,8 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void) pr_debug("Kernel memory limit %lluM, TTM limit %lluM\n", (kfd_mem_limit.max_system_mem_limit >> 20), (kfd_mem_limit.max_ttm_mem_limit >> 20)); + + return kfd_mem_limit.max_system_mem_limit; } void amdgpu_amdkfd_reserve_system_mem(uint64_t size) diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index714fd8d12ca5..df98ece071e1100644drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -2071,6 +2071,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr, int amdgpu_ttm_init(struct amdgpu_device *adev) { uint64_t gtt_size; + uint64_t max_system_mem_limit; int r; dma_set_max_seg_size(adev->dev, UINT_MAX); @@ -2210,8 +2211,12 @@int
amdgpu_ttm_init(struct amdgpu_device *adev)
dev_info(adev->dev, " %uM of GTT memory ready.\n", (unsigned int)(gtt_size / (1024 * 1024)));drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5
-1+ + max_system_mem_limit = amdgpu_amdkfd_gpuvm_init_mem_limits(); + if (adev->flags & AMD_IS_APU) { - if (adev->gmc.real_vram_size < gtt_size) + if (adev->gmc.real_vram_size < gtt_size && + adev->gmc.real_vram_size < max_system_mem_limit) adev->apu_prefer_gtt = true; }
[Public]
Quoted 47 lines
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Christian König
Sent: Monday, March 23, 2026 9:49 PM
To: Limonciello, Mario <[email protected]>; Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Yuan, Perry <[email protected]>; Lin, Leo <[email protected]>; Perry, David <[email protected]>
Subject: Re: [PATCH v2] drm/amdkfd: check system memory when setapu_prefer_gttHi Mario,
Quoted 6 lines · Mario Limonciello
Quoted 3 lines · Christian König
Hi Mario,
first of all please loop me in on TTM changes as maintainer explicitely. I don't see
everything which flys by on dri-devel.
Quoted 2 lines
Sure. I was initially just looking for anyone comments on it, didn't think it was worth
bubbling to top of your mailbox for an RFC.
I usually completely miss such stuff otherwise. I'm not very proud of it, but I have a backlog of multiple thousands of mailing list mails I couldn't look into.
Quoted 2 lines
Quoted 2 lines
Then changing the 50% limit is an absolutely NO-GO. It's completely irrelevant that
AI wants to use more, HPC use cases complained about that for decades, but we simply can't do that reliable.
Quoted 2 lines
What does HPC do now when they need more? Tell people to put page limit on the
kernel command line?
Yes, either that or other similar workarounds.
Quoted 1 line
This shouldn't be any different than status quo before - except that user intent can
persist.
The key point is the system starts to become unstable when you go over 50%. We have tons of complains about that as well from HPC customers.
The problem is that TTMs eviction code needs memory to swap GPU buffers out to disk, that's why we use the 50% limit here.
Quoted 6 lines
Intel has been working on and provides an alternative shrinker callback (see
drivers/gpu/drm/xe/xe_shrinker.c) to work around that and so lift the 50% limit. But so far that is only implemented for XE.If you want to fix this for amdgpu just take the
xe_shrinkeras an example and implement that same stuff for us as well.
If we prefer user ptr instead of GTT for APU VRAM handling, we can get rid of ttm limit issue.
By the way, why not use user ptr for MI300 APU VRAM handling in the first place?
I remember user ptr has some limitations.
Regards,
Lang
Quoted 179 lines
Regards,
Christian.Quoted 7 lines
Quoted 7 lines
Regards,
Christian.Quoted 1 line · Mario Limonciello
I think there is actually a very easy way to trigger it and it's not obvious that a user
messed it up.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Assume you're on a 128GB system with VRAM set to 512MB.
1) Set TTM page limit corresponding to 96GB
2) Useuma_carveoutsysfs or BIOS to set VRAM to 96GB
3) Reboot system
4) Now VRAM is 96GB, but the page limit was a module parameter and will bewrong.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
I actually /think/ that the RFC [1] I proposed a few weeks ago could be a good
way to prevent this. By using EFI variable instead, TTM could sanity check anything it reads at startup and save sane values to EFI for the next reboot (if they're insane).
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
https://lore.kernel.org/dri-devel/20260306055439.1822879-1-mario.lim
[email protected]/ [1]Quoted 3 lines · Yifan
[AMD Official Use Only - AMD Internal Distribution Only]
Yes, I agree. I’ve just been notified that this memory configuration is a mistake
rather than a valid user case. So the fix is low priority for now.
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
-----Original Message-----
From: Limonciello, Mario <[email protected]>
Sent: Friday, March 20, 2026 11:14 AM
To: Zhang, Yifan <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Limonciello, Mario <[email protected]>; Yuan, Perry <[email protected]>
Subject: Re: [PATCH v2] drm/amdkfd: check system memory when setapu_prefer_gttQuoted 7 lines · Yifan Zhang
Current
apu_prefer_gttsetting only checkgtt_size, which could be set by user to a larger than system memory value (via ttm modules parameterpages_limit). E.g. carveout vram 32GB,gtt_size50GB (via ttm modules parameterpages_limit), system memory 31GB. In that case,apu_prefer_gttwill be set incorrectly. Take system memory into account when setapu_prefer_gtt.Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Wouldn't it be cleaner to do this in TTM? IE test that a bad option was set by
user
pages_limitvalue and then show something like:Quoted 123 lines
Quoted 122 lines
Quoted 121 lines
Quoted 120 lines
if (user > possible) {
pr_warn("Requested invalid %d pages, limiting to %d pages",user, possible); user = possible; }Then we can always trust what we get from TTM.
Quoted 110 lines
Signed-off-by Yifan Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 2 -- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 7 ++++++- 4 files changed, 12 insertions(+), 7 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0
-2@@ -170,8 +170,6 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)int i;int last_valid_bit; -amdgpu_amdkfd_gpuvm_init_mem_limits (); -if (adev->kfd.dev) {struct kgd2kfd_shared_resources gpu_resources = {.compute_vmid_bitmap = diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.hb/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
indexcdbab7f8cee8..13cada7da4a9100644drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-0@@ -369,7 +369,7 @@ u64 amdgpu_amdkfd_xcp_memory_size(struct amdgpu_device *adev, int xcp_id);#if IS_ENABLED (CONFIG_HSA_AMD ) -voidamdgpu_amdkfd_gpuvm_init_mem_limits (void); +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ); void amdgpu_amdkfd_gpuvm_destroy_cb(struct amdgpu_device*adev,
struct amdgpu_vm *vm);drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1
-1@@ -382,7 +382,7 @@ void amdgpu_amdkfd_release_notify(struct amdgpu_bo *bo);void amdgpu_amdkfd_reserve_system_mem (uint64_t size);#else static inline -void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) { }drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0@@ -109,13 +109,13 @@ static bool reuse_dmamap(struct
amdgpu_device*adev, structamdgpu_device*bo_ad
* System (TTM + userptr) memory - 15/16th System RAM
* TTM memory - 3/8th System RAM
*/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-2-void amdgpu_amdkfd_gpuvm_init_mem_limits (void ) +uint64_t amdgpu_amdkfd_gpuvm_init_mem_limits (void ) {struct sysinfo si;uint64_t mem;if (kfd_mem_limit.max_system_mem_limit) -return ; +return kfd_mem_limit.max_system_mem_limit;si_meminfo (&si); mem = si.totalram - si.totalhigh; @@ -132,6 +132,8 @@ void
amdgpu_amdkfd_gpuvm_init_mem_limits(void)pr_debug("Kernel memory limit %lluM, TTM limit %lluM\n", (kfd_mem_limit.max_system_mem_limit >> 20), (kfd_mem_limit.max_ttm_mem_limit >> 20));drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +2
-1+ +return kfd_mem_limit.max_system_mem_limit; } void amdgpu_amdkfd_reserve_system_mem(uint64_t size) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index714fd8d12ca5..df98ece071e1100644drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1
-0@@ -2071,6 +2071,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr, int amdgpu_ttm_init(struct amdgpu_device *adev) { uint64_t gtt_size; +uint64_t max_system_mem_limit;int r;dma_set_max_seg_size(adev->dev, UINT_MAX); @@ -2210,8 +2211,12 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) dev_info(adev->dev, " %uM of GTT memory ready.\n", (unsigned int)(gtt_size / (1024 * 1024)));drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +7
-1+ + max_system_mem_limit = +amdgpu_amdkfd_gpuvm_init_mem_limits (); +if (adev->flags &AMD_IS_APU ) { -if (adev->gmc.real_vram_size < gtt_size) +if (adev->gmc.real_vram_size < gtt_size && + adev->gmc.real_vram_size < +max_system_mem_limit) adev->apu_prefer_gtt = true; }