Skip to contentSkip to conversation

drm/amdgpu: Adjust the VM size based on system memory size

PATCH In review Felix Kuehling 4 participants 6 messages Aug 21, 2018 – Aug 22, 2018 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Adjust the VM size based on system memory size

Set the VM size based on system memory size between the ASIC-specific limits given by min_vm_size and max_bits. GFXv9 GPUs will keep their default VM size of 256TB (48 bit). Only older GPUs will adjust VM size depending on system memory size.

This makes more VM space available for ROCm applications on GFXv8 GPUs that want to map all available VRAM and system memory in their SVM address space.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 26 ++++++++++++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 +-
 2 files changed, 23 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +22 -4
index 662e8a3..48971cc 100644
@@ -2482,28 +2482,46 @@ static uint32_t amdgpu_vm_get_block_size(uint64_t vm_size)
  * amdgpu_vm_adjust_size - adjust vm size, block size and fragment size
  *
  * @adev: amdgpu_device pointer
- * @vm_size: the default vm size if it's set auto
+ * @min_vm_size: the minimum vm size in GB if it's set auto
  * @fragment_size_default: Default PTE fragment size
  * @max_level: max VMPT level
  * @max_bits: max address space size in bits
  *
  */
-void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
+void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
 			   uint32_t fragment_size_default, unsigned max_level,
 			   unsigned max_bits)
 {
+	unsigned int max_size = 1 << (max_bits - 30);
+	unsigned int vm_size;
 	uint64_t tmp;
 
 	/* adjust vm size first */
 	if (amdgpu_vm_size != -1) {
-		unsigned max_size = 1 << (max_bits - 30);
-
 		vm_size = amdgpu_vm_size;
 		if (vm_size > max_size) {
 			dev_warn(adev->dev, "VM size (%d) too large, max is %u GB\n",
 				 amdgpu_vm_size, max_size);
 			vm_size = max_size;
 		}
+	} else {
+		struct sysinfo si;
+		unsigned int phys_ram_gb;
+
+		/* Optimal VM size depends on the amount of physical
+		 * RAM available. Underlying requirements and
+		 * assumptions:
+		 *
+		 *  - Need to map system memory and VRAM from all GPUs
+		 *     - VRAM from other GPUs not known here
+		 *     - Assume VRAM <= system memory
+		 *  - On GFX8 and older, VM space can be segmented for
+		 *    different MTYPEs
+		 *  - Need to allow room for fragmentation, guard pages etc.
+		 */
+		si_meminfo(&si);
+		phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit) >> 30;
+		vm_size = min(max(phys_ram_gb * 3, min_vm_size), max_size);
 	}
 
 	adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
index 1162c2b..ab1d23e 100644
@@ -345,7 +345,7 @@ struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
 void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket);
 void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
 		      struct amdgpu_bo_va *bo_va);
-void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
+void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
 			   uint32_t fragment_size_default, unsigned max_level,
 			   unsigned max_bits);
 int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1534886748-22658-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org

#2 lore raw

This patch is meant for amd-staging-drm-next. It's part of my effort to reduce differences between kfd-staging and upstream and eventually replace all our memory manager hacks with upstream solutions.

This commit should only affect GFXv8 and older. It should not have any negative impact, except bigger GPUVM page tables on systems with lots of memory. Conversely, this could actually allow making the GPUVM page tables smaller on systems with little memory, if we wanted to take advantage of that opportunity.

The current minimum is 64GB, which I believe means 32KB page tables and page directories. The smallest VM size that makes sense with 2-levels of 4KB page tables would be 1GB. If we really want to go that small, I should also factor the local VRAM size into the equation.

Regards,
  Felix

Quoted 75 lines · Felix Kuehling

Set the VM size based on system memory size between the ASIC-specific limits given by min_vm_size and max_bits. GFXv9 GPUs will keep their default VM size of 256TB (48 bit). Only older GPUs will adjust VM size depending on system memory size.

This makes more VM space available for ROCm applications on GFXv8 GPUs that want to map all available VRAM and system memory in their SVM address space.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 26 ++++++++++++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 +-
 2 files changed, 23 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +22 -4
index 662e8a3..48971cc 100644
@@ -2482,28 +2482,46 @@ static uint32_t amdgpu_vm_get_block_size(uint64_t vm_size)
  * amdgpu_vm_adjust_size - adjust vm size, block size and fragment size
  *
  * @adev: amdgpu_device pointer
- * @vm_size: the default vm size if it's set auto
+ * @min_vm_size: the minimum vm size in GB if it's set auto
  * @fragment_size_default: Default PTE fragment size
  * @max_level: max VMPT level
  * @max_bits: max address space size in bits
  *
  */
-void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
+void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
 			   uint32_t fragment_size_default, unsigned max_level,
 			   unsigned max_bits)
 {
+	unsigned int max_size = 1 << (max_bits - 30);
+	unsigned int vm_size;
 	uint64_t tmp;
 
 	/* adjust vm size first */
 	if (amdgpu_vm_size != -1) {
-		unsigned max_size = 1 << (max_bits - 30);
-
 		vm_size = amdgpu_vm_size;
 		if (vm_size > max_size) {
 			dev_warn(adev->dev, "VM size (%d) too large, max is %u GB\n",
 				 amdgpu_vm_size, max_size);
 			vm_size = max_size;
 		}
+	} else {
+		struct sysinfo si;
+		unsigned int phys_ram_gb;
+
+		/* Optimal VM size depends on the amount of physical
+		 * RAM available. Underlying requirements and
+		 * assumptions:
+		 *
+		 *  - Need to map system memory and VRAM from all GPUs
+		 *     - VRAM from other GPUs not known here
+		 *     - Assume VRAM <= system memory
+		 *  - On GFX8 and older, VM space can be segmented for
+		 *    different MTYPEs
+		 *  - Need to allow room for fragmentation, guard pages etc.
+		 */
+		si_meminfo(&si);
+		phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit) >> 30;
+		vm_size = min(max(phys_ram_gb * 3, min_vm_size), max_size);
 	}
 
 	adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index 1162c2b..ab1d23e 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm, · line 351

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
@@ -345,7 +345,7 @@ struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
 void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket);
 void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
 		      struct amdgpu_bo_va *bo_va);
-void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
+void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
 			   uint32_t fragment_size_default, unsigned max_level,
 			   unsigned max_bits);
 int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 40b96ac4-322d-7d11-1e8d-970a575b4282-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Am 21.08.2018 um 23:45 schrieb Felix Kuehling:

Quoted 78 lines

This patch is meant for amd-staging-drm-next. It's part of my effort to reduce differences between kfd-staging and upstream and eventually replace all our memory manager hacks with upstream solutions.

This commit should only affect GFXv8 and older. It should not have any negative impact, except bigger GPUVM page tables on systems with lots of memory. Conversely, this could actually allow making the GPUVM page tables smaller on systems with little memory, if we wanted to take advantage of that opportunity.

The current minimum is 64GB, which I believe means 32KB page tables and page directories. The smallest VM size that makes sense with 2-levels of 4KB page tables would be 1GB. If we really want to go that small, I should also factor the local VRAM size into the equation.

Regards,
  Felix

Quoted 58 lines · Felix Kuehling

Set the VM size based on system memory size between the ASIC-specific limits given by min_vm_size and max_bits. GFXv9 GPUs will keep their default VM size of 256TB (48 bit). Only older GPUs will adjust VM size depending on system memory size.

This makes more VM space available for ROCm applications on GFXv8 GPUs that want to map all available VRAM and system memory in their SVM address space.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 26 ++++++++++++++++++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 +-
  2 files changed, 23 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +13 -4
index 662e8a3..48971cc 100644
@@ -2482,28 +2482,46 @@ static uint32_t amdgpu_vm_get_block_size(uint64_t vm_size)
   * amdgpu_vm_adjust_size - adjust vm size, block size and fragment size
   *
   * @adev: amdgpu_device pointer
- * @vm_size: the default vm size if it's set auto
+ * @min_vm_size: the minimum vm size in GB if it's set auto
   * @fragment_size_default: Default PTE fragment size
   * @max_level: max VMPT level
   * @max_bits: max address space size in bits
   *
   */
-void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
+void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
  			   uint32_t fragment_size_default, unsigned max_level,
  			   unsigned max_bits)
  {
+	unsigned int max_size = 1 << (max_bits - 30);
+	unsigned int vm_size;
  	uint64_t tmp;
 
  	/* adjust vm size first */
  	if (amdgpu_vm_size != -1) {
-		unsigned max_size = 1 << (max_bits - 30);
-
  		vm_size = amdgpu_vm_size;
  		if (vm_size > max_size) {
  			dev_warn(adev->dev, "VM size (%d) too large, max is %u GB\n",
  				 amdgpu_vm_size, max_size);
  			vm_size = max_size;
  		}
+	} else {
+		struct sysinfo si;
+		unsigned int phys_ram_gb;
+
+		/* Optimal VM size depends on the amount of physical
+		 * RAM available. Underlying requirements and
+		 * assumptions:
+		 *
+		 *  - Need to map system memory and VRAM from all GPUs
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static uint32_t amdgpu_vm_get_block_size(uint64_t vm_size) · line 2523

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +8 -0
+		 *     - VRAM from other GPUs not known here
+		 *     - Assume VRAM <= system memory
+		 *  - On GFX8 and older, VM space can be segmented for
+		 *    different MTYPEs
+		 *  - Need to allow room for fragmentation, guard pages etc.
+		 */
+		si_meminfo(&si);
+		phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit) >> 30;

Looks good to me, but I would make sure that round that up before shifting it.

Quoted 1 line

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static uint32_t amdgpu_vm_get_block_size(uint64_t vm_size) · line 2524

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -0
+		vm_size = min(max(phys_ram_gb * 3, min_vm_size), max_size);

Mhm, "phys_ram_gb * 3"? Maybe add a comment with the rational for that.

Christian.

Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
  	}
 
  	adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -1
index 1162c2b..ab1d23e 100644
@@ -345,7 +345,7 @@ struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
  void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket);
  void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
  		      struct amdgpu_bo_va *bo_va);
-void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm, · line 351

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -0
+void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
  			   uint32_t fragment_size_default, unsigned max_level,
  			   unsigned max_bits);
  int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 52d5e14f-88be-696c-e656-ecb5cf1ee582-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#6 lore raw
Quoted 1 line · Christian König

Am 21.08.2018 um 23:45 schrieb Felix Kuehling:

[snip]

Quoted 18 lines
Quoted 17 lines

+    } else {

Quoted 16 lines

+        struct sysinfo si;
+        unsigned int phys_ram_gb;
+
+        /* Optimal VM size depends on the amount of physical +         * RAM available. Underlying requirements and
+         * assumptions:
+         *
+         *  - Need to map system memory and VRAM from all GPUs +         *     - VRAM from other GPUs not known here
+         *     - Assume VRAM <= system memory
+         *  - On GFX8 and older, VM space can be segmented for +         *    different MTYPEs
+         *  - Need to allow room for fragmentation, guard pages etc. +         */
+        si_meminfo(&si);
+        phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit) >> 30;

Quoted 2 lines

Looks good to me, but I would make sure that round that up before shifting it.

Hmm, we used to round up. I just removed it because we were told it's not necessary.

But I guess rounding up to the next power of two increases the available VM size without increasing page table size. So we should take it if we can get it for free. I'll reintroduce rounding up.

Quoted 4 lines
Quoted 2 lines
Quoted 2 lines

+        vm_size = min(max(phys_ram_gb * 3, min_vm_size), max_size);

Mhm, "phys_ram_gb * 3"? Maybe add a comment with the rational for that.

Well, the long comment above was meant to justify the factor 3. Maybe I didn't make that clear enough. 1x is system memory itself, 2x is a wild guess of VRAM on all GPUs. 3x is room for a second aperture for MTYPE control, fragmentation and guard pages.

Regards,
  Felix

Quoted 29 lines

Christian.

Quoted 25 lines
Quoted 13 lines

      }
        adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index 1162c2b..ab1d23e 100644
@@ -345,7 +345,7 @@ struct amdgpu_bo_va_mapping
 *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,

  void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket);
  void amdgpu_vm_bo_rmv(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va);

Quoted 8 lines

-void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
+void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
                 uint32_t fragment_size_default, unsigned max_level, unsigned max_bits);
  int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 962840bc-9ee2-97df-24dc-ce22a4558de5-5C7GfCeVMHo@public.gmane.org

#8 lore raw

Am 22.08.2018 um 19:40 schrieb Felix Kuehling:

Quoted 20 lines · Christian König
Quoted 1 line

Am 21.08.2018 um 23:45 schrieb Felix Kuehling:

[snip]

Quoted 17 lines
Quoted 17 lines

+    } else {

Quoted 16 lines

+        struct sysinfo si;
+        unsigned int phys_ram_gb;
+
+        /* Optimal VM size depends on the amount of physical +         * RAM available. Underlying requirements and
+         * assumptions:
+         *
+         *  - Need to map system memory and VRAM from all GPUs +         *     - VRAM from other GPUs not known here
+         *     - Assume VRAM <= system memory
+         *  - On GFX8 and older, VM space can be segmented for +         *    different MTYPEs
+         *  - Need to allow room for fragmentation, guard pages etc. +         */
+        si_meminfo(&si);
+        phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit) >> 30;

Quoted 8 lines
Quoted 2 lines

Looks good to me, but I would make sure that round that up before shifting it.

Hmm, we used to round up. I just removed it because we were told it's not necessary.

But I guess rounding up to the next power of two increases the available VM size without increasing page table size. So we should take it if we can get it for free. I'll reintroduce rounding up.

No, that wasn't what I meant. Rounding up to the next power of two is indeed not necessary.

What I meant is when the installed system memory is 3.9GB we only take into account 3GB here because we always truncate.

Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line

+        vm_size = min(max(phys_ram_gb * 3, min_vm_size), max_size);

Mhm, "phys_ram_gb * 3"? Maybe add a comment with the rational for that.

Well, the long comment above was meant to justify the factor 3. Maybe I didn't make that clear enough. 1x is system memory itself, 2x is a wild guess of VRAM on all GPUs. 3x is room for a second aperture for MTYPE control, fragmentation and guard pages.

Ah! Yeah that wasn't obvious.

Christian.

Quoted 31 lines

Regards,
  Felix

Quoted 27 lines

Christian.

Quoted 25 lines
Quoted 16 lines

      }
        adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
index 1162c2b..ab1d23e 100644
@@ -345,7 +345,7 @@ struct amdgpu_bo_va_mapping
 *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
   void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct
 ww_acquire_ctx *ticket);
   void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
                 struct amdgpu_bo_va *bo_va);
-void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t
 vm_size,
+void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t
Quoted 5 lines

min_vm_size,
                 uint32_t fragment_size_default, unsigned max_level, unsigned max_bits);
  int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct
drm_file *filp);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#9 lore raw
In reply to a message not in the archive
Quoted 57 lines · Felix Kuehling

Set the VM size based on system memory size between the ASIC-specific limits given by min_vm_size and max_bits. GFXv9 GPUs will keep their default VM size of 256TB (48 bit). Only older GPUs will adjust VM size depending on system memory size.

This makes more VM space available for ROCm applications on GFXv8 GPUs that want to map all available VRAM and system memory in their SVM address space.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 26 ++++++++++++++++++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h |  2 +-
  2 files changed, 23 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +12 -4
index 662e8a3..48971cc 100644
@@ -2482,28 +2482,46 @@ static uint32_t amdgpu_vm_get_block_size(uint64_t vm_size)
   * amdgpu_vm_adjust_size - adjust vm size, block size and fragment size
   *
   * @adev: amdgpu_device pointer
- * @vm_size: the default vm size if it's set auto
+ * @min_vm_size: the minimum vm size in GB if it's set auto
   * @fragment_size_default: Default PTE fragment size
   * @max_level: max VMPT level
   * @max_bits: max address space size in bits
   *
   */
-void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
+void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
  			   uint32_t fragment_size_default, unsigned max_level,
  			   unsigned max_bits)
  {
+	unsigned int max_size = 1 << (max_bits - 30);
+	unsigned int vm_size;
  	uint64_t tmp;
 
  	/* adjust vm size first */
  	if (amdgpu_vm_size != -1) {
-		unsigned max_size = 1 << (max_bits - 30);
-
  		vm_size = amdgpu_vm_size;
  		if (vm_size > max_size) {
  			dev_warn(adev->dev, "VM size (%d) too large, max is %u GB\n",
  				 amdgpu_vm_size, max_size);
  			vm_size = max_size;
  		}
+	} else {
+		struct sysinfo si;
+		unsigned int phys_ram_gb;
+
+		/* Optimal VM size depends on the amount of physical
+		 * RAM available. Underlying requirements and
+		 * assumptions:
+		 *

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static uint32_t amdgpu_vm_get_block_size(uint64_t vm_size) · line 2524

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +10 -0
+		 *  - Need to map system memory and VRAM from all GPUs
+		 *     - VRAM from other GPUs not known here
+		 *     - Assume VRAM <= system memory
+		 *  - On GFX8 and older, VM space can be segmented for
+		 *    different MTYPEs
+		 *  - Need to allow room for fragmentation, guard pages etc.
+		 */
+		si_meminfo(&si);
+		phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit) >> 30;
+		vm_size = min(max(phys_ram_gb * 3, min_vm_size), max_size);

The patch looks good for me.
Curious about the constant "3", is that a experiment value? or any verification for that?

Regards,
Jerry

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
  	}
 
  	adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +0 -0
index 1162c2b..ab1d23e 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm, · line 351

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
@@ -345,7 +345,7 @@ struct amdgpu_bo_va_mapping *amdgpu_vm_bo_lookup_mapping(struct amdgpu_vm *vm,
  void amdgpu_vm_bo_trace_cs(struct amdgpu_vm *vm, struct ww_acquire_ctx *ticket);
  void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
  		      struct amdgpu_bo_va *bo_va);
-void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size,
+void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
  			   uint32_t fragment_size_default, unsigned max_level,
  			   unsigned max_bits);
  int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx