aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
diff options
context:
space:
mode:
authorFelix Kuehling <Felix.Kuehling@amd.com>2018-08-21 17:14:32 -0400
committerAlex Deucher <alexander.deucher@amd.com>2018-08-27 16:10:42 -0400
commit43370c4ce5c6a1fae84b58f67f7834902ee74b7c (patch)
tree347ec3fba551c2ce89b068ae7bf305c460f6d17d /drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
parent80dbea4720bb43b473219fad0cf3b426f2cd04cc (diff)
drm/amdgpu: Adjust the VM size based on system memory size v2
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. v2: * Clarify comment * Round up memory size before >> 30 * Round up automatic vm_size to power of two Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com> Acked-by: Junwei Zhang <Jerry.Zhang@amd.com> Reviewed-by: Huang Rui <ray.huang@amd.com> Reviewed-by: Christian König <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c')
-rw-r--r--drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
index 7e644bc6793e..b905d7901248 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
@@ -2504,28 +2504,52 @@ static uint32_t amdgpu_vm_get_block_size(uint64_t vm_size)
2504 * amdgpu_vm_adjust_size - adjust vm size, block size and fragment size 2504 * amdgpu_vm_adjust_size - adjust vm size, block size and fragment size
2505 * 2505 *
2506 * @adev: amdgpu_device pointer 2506 * @adev: amdgpu_device pointer
2507 * @vm_size: the default vm size if it's set auto 2507 * @min_vm_size: the minimum vm size in GB if it's set auto
2508 * @fragment_size_default: Default PTE fragment size 2508 * @fragment_size_default: Default PTE fragment size
2509 * @max_level: max VMPT level 2509 * @max_level: max VMPT level
2510 * @max_bits: max address space size in bits 2510 * @max_bits: max address space size in bits
2511 * 2511 *
2512 */ 2512 */
2513void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t vm_size, 2513void amdgpu_vm_adjust_size(struct amdgpu_device *adev, uint32_t min_vm_size,
2514 uint32_t fragment_size_default, unsigned max_level, 2514 uint32_t fragment_size_default, unsigned max_level,
2515 unsigned max_bits) 2515 unsigned max_bits)
2516{ 2516{
2517 unsigned int max_size = 1 << (max_bits - 30);
2518 unsigned int vm_size;
2517 uint64_t tmp; 2519 uint64_t tmp;
2518 2520
2519 /* adjust vm size first */ 2521 /* adjust vm size first */
2520 if (amdgpu_vm_size != -1) { 2522 if (amdgpu_vm_size != -1) {
2521 unsigned max_size = 1 << (max_bits - 30);
2522
2523 vm_size = amdgpu_vm_size; 2523 vm_size = amdgpu_vm_size;
2524 if (vm_size > max_size) { 2524 if (vm_size > max_size) {
2525 dev_warn(adev->dev, "VM size (%d) too large, max is %u GB\n", 2525 dev_warn(adev->dev, "VM size (%d) too large, max is %u GB\n",
2526 amdgpu_vm_size, max_size); 2526 amdgpu_vm_size, max_size);
2527 vm_size = max_size; 2527 vm_size = max_size;
2528 } 2528 }
2529 } else {
2530 struct sysinfo si;
2531 unsigned int phys_ram_gb;
2532
2533 /* Optimal VM size depends on the amount of physical
2534 * RAM available. Underlying requirements and
2535 * assumptions:
2536 *
2537 * - Need to map system memory and VRAM from all GPUs
2538 * - VRAM from other GPUs not known here
2539 * - Assume VRAM <= system memory
2540 * - On GFX8 and older, VM space can be segmented for
2541 * different MTYPEs
2542 * - Need to allow room for fragmentation, guard pages etc.
2543 *
2544 * This adds up to a rough guess of system memory x3.
2545 * Round up to power of two to maximize the available
2546 * VM size with the given page table size.
2547 */
2548 si_meminfo(&si);
2549 phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit +
2550 (1 << 30) - 1) >> 30;
2551 vm_size = roundup_pow_of_two(
2552 min(max(phys_ram_gb * 3, min_vm_size), max_size));
2529 } 2553 }
2530 2554
2531 adev->vm_manager.max_pfn = (uint64_t)vm_size << 18; 2555 adev->vm_manager.max_pfn = (uint64_t)vm_size << 18;