* [PATCH 1/3] drm/amdgpu: Rework KFD memory max limits
@ 2023-09-29 18:18 Rajneesh Bhardwaj
2023-09-29 18:18 ` [PATCH 2/3] drm/amdgpu: Initialize acpi mem ranges after TTM Rajneesh Bhardwaj
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Rajneesh Bhardwaj @ 2023-09-29 18:18 UTC (permalink / raw)
To: amd-gfx
Cc: philip.yang, felix.kuehling, lijo.lazar, christian.koenig,
Rajneesh Bhardwaj
To allow bigger allocations specially on systems such as GFXIP 9.4.3
that use GTT memory for VRAM allocations, relax the limits to
maximize ROCm allocations.
Signed-off-by: Rajneesh Bhardwaj <rajneesh.bhardwaj@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index b5b940485059..b1c4e9c0e036 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -42,6 +42,7 @@
* changes to accumulate
*/
#define AMDGPU_USERPTR_RESTORE_DELAY_MS 1
+#define AMDGPU_RESERVE_MEM_LIMIT (1UL << 30)
/*
* Align VRAM availability to 2MB to avoid fragmentation caused by 4K allocations in the tail 2MB
@@ -115,11 +116,16 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void)
return;
si_meminfo(&si);
- mem = si.freeram - si.freehigh;
+ mem = si.totalram - si.totalhigh;
mem *= si.mem_unit;
spin_lock_init(&kfd_mem_limit.mem_limit_lock);
- kfd_mem_limit.max_system_mem_limit = mem - (mem >> 4);
+ kfd_mem_limit.max_system_mem_limit = mem - (mem >> 6);
+ if (kfd_mem_limit.max_system_mem_limit < 2 * AMDGPU_RESERVE_MEM_LIMIT)
+ kfd_mem_limit.max_system_mem_limit >>= 1;
+ else
+ kfd_mem_limit.max_system_mem_limit -= AMDGPU_RESERVE_MEM_LIMIT;
+
kfd_mem_limit.max_ttm_mem_limit = ttm_tt_pages_limit() << PAGE_SHIFT;
pr_debug("Kernel memory limit %lluM, TTM limit %lluM\n",
(kfd_mem_limit.max_system_mem_limit >> 20),
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] drm/amdgpu: Initialize acpi mem ranges after TTM
2023-09-29 18:18 [PATCH 1/3] drm/amdgpu: Rework KFD memory max limits Rajneesh Bhardwaj
@ 2023-09-29 18:18 ` Rajneesh Bhardwaj
2023-10-02 15:44 ` Bhardwaj, Rajneesh
2023-09-29 18:18 ` [PATCH 3/3] drm/amdgpu: Use ttm_pages_limit to override vram reporting Rajneesh Bhardwaj
2023-09-29 20:54 ` [PATCH 1/3] drm/amdgpu: Rework KFD memory max limits Felix Kuehling
2 siblings, 1 reply; 5+ messages in thread
From: Rajneesh Bhardwaj @ 2023-09-29 18:18 UTC (permalink / raw)
To: amd-gfx
Cc: philip.yang, Felix Kuehling, lijo.lazar, christian.koenig,
Rajneesh Bhardwaj
Move ttm init before acpi mem range init so we can use ttm_pages_limit
to override vram size for GFXIP 9.4.3. The vram size override change
will be introduced in a future commit.
Acked-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Rajneesh Bhardwaj <rajneesh.bhardwaj@amd.com>
---
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index 268ee533e7c1..005ea719d2fd 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -2190,17 +2190,17 @@ static int gmc_v9_0_sw_init(void *handle)
amdgpu_gmc_get_vbios_allocations(adev);
+ /* Memory manager */
+ r = amdgpu_bo_init(adev);
+ if (r)
+ return r;
+
if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3)) {
r = gmc_v9_0_init_mem_ranges(adev);
if (r)
return r;
}
- /* Memory manager */
- r = amdgpu_bo_init(adev);
- if (r)
- return r;
-
r = gmc_v9_0_gart_init(adev);
if (r)
return r;
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] drm/amdgpu: Use ttm_pages_limit to override vram reporting
2023-09-29 18:18 [PATCH 1/3] drm/amdgpu: Rework KFD memory max limits Rajneesh Bhardwaj
2023-09-29 18:18 ` [PATCH 2/3] drm/amdgpu: Initialize acpi mem ranges after TTM Rajneesh Bhardwaj
@ 2023-09-29 18:18 ` Rajneesh Bhardwaj
2023-09-29 20:54 ` [PATCH 1/3] drm/amdgpu: Rework KFD memory max limits Felix Kuehling
2 siblings, 0 replies; 5+ messages in thread
From: Rajneesh Bhardwaj @ 2023-09-29 18:18 UTC (permalink / raw)
To: amd-gfx
Cc: philip.yang, felix.kuehling, lijo.lazar, christian.koenig,
Rajneesh Bhardwaj
On GFXIP9.4.3 APU, allow the memory reporting as per the ttm pages
limit in NPS1 mode.
Signed-off-by: Rajneesh Bhardwaj <rajneesh.bhardwaj@amd.com>
---
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index 005ea719d2fd..fadc4d2ed071 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -25,6 +25,7 @@
#include <linux/pci.h>
#include <drm/drm_cache.h>
+#include <drm/ttm/ttm_tt.h>
#include "amdgpu.h"
#include "gmc_v9_0.h"
@@ -1896,7 +1897,8 @@ static void
gmc_v9_0_init_acpi_mem_ranges(struct amdgpu_device *adev,
struct amdgpu_mem_partition_info *mem_ranges)
{
- int num_ranges = 0, ret, mem_groups;
+ int num_ranges = 0, ret, num_nodes;
+ uint64_t node_size_ttm_override = 0;
struct amdgpu_numa_info numa_info;
int node_ids[MAX_MEM_RANGES];
int num_xcc, xcc_id;
@@ -1904,7 +1906,8 @@ gmc_v9_0_init_acpi_mem_ranges(struct amdgpu_device *adev,
num_xcc = NUM_XCC(adev->gfx.xcc_mask);
xcc_mask = (1U << num_xcc) - 1;
- mem_groups = hweight32(adev->aid_mask);
+ num_nodes = num_online_nodes();
+ node_size_ttm_override = (ttm_tt_pages_limit() << PAGE_SHIFT) / num_nodes;
for_each_inst(xcc_id, xcc_mask) {
ret = amdgpu_acpi_get_mem_info(adev, xcc_id, &numa_info);
@@ -1912,7 +1915,6 @@ gmc_v9_0_init_acpi_mem_ranges(struct amdgpu_device *adev,
continue;
if (numa_info.nid == NUMA_NO_NODE) {
- mem_ranges[0].size = numa_info.size;
mem_ranges[0].numa.node = numa_info.nid;
num_ranges = 1;
break;
@@ -1930,11 +1932,16 @@ gmc_v9_0_init_acpi_mem_ranges(struct amdgpu_device *adev,
adev->gmc.num_mem_partitions = num_ranges;
- /* If there is only partition, don't use entire size */
- if (adev->gmc.num_mem_partitions == 1) {
- mem_ranges[0].size = mem_ranges[0].size * (mem_groups - 1);
- do_div(mem_ranges[0].size, mem_groups);
- }
+ /* In NPS1 mode, we should restrict the vram reporting
+ * tied to the ttm_pages_limit which is 1/2 of the
+ * system memory. For other partition modes, the HBM is
+ * uniformly divided already per numa node reported. If
+ * user wants to go beyond the default ttm limit and
+ * maximize the ROCm allocations, they can go up to max
+ * ttm and sysmem limits.
+ */
+ if (adev->gmc.num_mem_partitions == 1)
+ mem_ranges[0].size = node_size_ttm_override;
}
static void
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/3] drm/amdgpu: Rework KFD memory max limits
2023-09-29 18:18 [PATCH 1/3] drm/amdgpu: Rework KFD memory max limits Rajneesh Bhardwaj
2023-09-29 18:18 ` [PATCH 2/3] drm/amdgpu: Initialize acpi mem ranges after TTM Rajneesh Bhardwaj
2023-09-29 18:18 ` [PATCH 3/3] drm/amdgpu: Use ttm_pages_limit to override vram reporting Rajneesh Bhardwaj
@ 2023-09-29 20:54 ` Felix Kuehling
2 siblings, 0 replies; 5+ messages in thread
From: Felix Kuehling @ 2023-09-29 20:54 UTC (permalink / raw)
To: Rajneesh Bhardwaj, amd-gfx; +Cc: philip.yang, lijo.lazar, christian.koenig
On 2023-09-29 14:18, Rajneesh Bhardwaj wrote:
> To allow bigger allocations specially on systems such as GFXIP 9.4.3
> that use GTT memory for VRAM allocations, relax the limits to
> maximize ROCm allocations.
>
> Signed-off-by: Rajneesh Bhardwaj <rajneesh.bhardwaj@amd.com>
If the new heuristic in patch 1 causes regressions, we can change
AMDGPU_RESERVE_MEM_LIMIT to something larger, e.g. 1.5 GB (3UL << 29).
Maybe we should start with that more conservative value to minimize the
risk on 16GB system memory systems that have proven problematic in the past.
Other than that, patches 1 and 3 are
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index b5b940485059..b1c4e9c0e036 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -42,6 +42,7 @@
> * changes to accumulate
> */
> #define AMDGPU_USERPTR_RESTORE_DELAY_MS 1
> +#define AMDGPU_RESERVE_MEM_LIMIT (1UL << 30)
>
> /*
> * Align VRAM availability to 2MB to avoid fragmentation caused by 4K allocations in the tail 2MB
> @@ -115,11 +116,16 @@ void amdgpu_amdkfd_gpuvm_init_mem_limits(void)
> return;
>
> si_meminfo(&si);
> - mem = si.freeram - si.freehigh;
> + mem = si.totalram - si.totalhigh;
> mem *= si.mem_unit;
>
> spin_lock_init(&kfd_mem_limit.mem_limit_lock);
> - kfd_mem_limit.max_system_mem_limit = mem - (mem >> 4);
> + kfd_mem_limit.max_system_mem_limit = mem - (mem >> 6);
> + if (kfd_mem_limit.max_system_mem_limit < 2 * AMDGPU_RESERVE_MEM_LIMIT)
> + kfd_mem_limit.max_system_mem_limit >>= 1;
> + else
> + kfd_mem_limit.max_system_mem_limit -= AMDGPU_RESERVE_MEM_LIMIT;
> +
> kfd_mem_limit.max_ttm_mem_limit = ttm_tt_pages_limit() << PAGE_SHIFT;
> pr_debug("Kernel memory limit %lluM, TTM limit %lluM\n",
> (kfd_mem_limit.max_system_mem_limit >> 20),
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/3] drm/amdgpu: Initialize acpi mem ranges after TTM
2023-09-29 18:18 ` [PATCH 2/3] drm/amdgpu: Initialize acpi mem ranges after TTM Rajneesh Bhardwaj
@ 2023-10-02 15:44 ` Bhardwaj, Rajneesh
0 siblings, 0 replies; 5+ messages in thread
From: Bhardwaj, Rajneesh @ 2023-10-02 15:44 UTC (permalink / raw)
To: amd-gfx; +Cc: philip.yang, felix.kuehling, lijo.lazar, christian.koenig
I found an issue with this patch, that leads to performance drop. This
leads to incorrectly initialize numa pools on a multi node system. I am
working on the fix and will send another change set.
On 9/29/2023 2:18 PM, Rajneesh Bhardwaj wrote:
> Move ttm init before acpi mem range init so we can use ttm_pages_limit
> to override vram size for GFXIP 9.4.3. The vram size override change
> will be introduced in a future commit.
>
> Acked-by: Felix Kuehling <Felix.Kuehling@amd.com>
> Signed-off-by: Rajneesh Bhardwaj <rajneesh.bhardwaj@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> index 268ee533e7c1..005ea719d2fd 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
> @@ -2190,17 +2190,17 @@ static int gmc_v9_0_sw_init(void *handle)
>
> amdgpu_gmc_get_vbios_allocations(adev);
>
> + /* Memory manager */
> + r = amdgpu_bo_init(adev);
> + if (r)
> + return r;
> +
> if (amdgpu_ip_version(adev, GC_HWIP, 0) == IP_VERSION(9, 4, 3)) {
> r = gmc_v9_0_init_mem_ranges(adev);
> if (r)
> return r;
> }
>
> - /* Memory manager */
> - r = amdgpu_bo_init(adev);
> - if (r)
> - return r;
> -
> r = gmc_v9_0_gart_init(adev);
> if (r)
> return r;
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-02 15:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-29 18:18 [PATCH 1/3] drm/amdgpu: Rework KFD memory max limits Rajneesh Bhardwaj
2023-09-29 18:18 ` [PATCH 2/3] drm/amdgpu: Initialize acpi mem ranges after TTM Rajneesh Bhardwaj
2023-10-02 15:44 ` Bhardwaj, Rajneesh
2023-09-29 18:18 ` [PATCH 3/3] drm/amdgpu: Use ttm_pages_limit to override vram reporting Rajneesh Bhardwaj
2023-09-29 20:54 ` [PATCH 1/3] drm/amdgpu: Rework KFD memory max limits Felix Kuehling
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox