]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/amdgpu: optimize VRAM allocation when using drm buddy
authorShane Xiao <shane.xiao@amd.com>
Sat, 18 Feb 2023 03:58:45 +0000 (11:58 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 23 Feb 2023 22:35:58 +0000 (17:35 -0500)
Since the VRAM manager changed from drm mm to drm buddy. It's
not necessary to allocate 2MB aligned VRAM for more than 2MB
unaligned size, and then do trim. This method improves the
allocation efficiency and reduces memory fragmentation.

v2: Correct the remainder operation

Signed-off-by: Shane Xiao <shane.xiao@amd.com>
Reviewed-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c

index 9fa1d814508a6cd42e31f3f0fa8b0150835af548..43d6a9d6a5384f886b4460a539bb97450cf1a0e2 100644 (file)
@@ -453,7 +453,8 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
                /* Limit maximum size to 2GiB due to SG table limitations */
                size = min(remaining_size, 2ULL << 30);
 
-               if (size >= (u64)pages_per_block << PAGE_SHIFT)
+               if ((size >= (u64)pages_per_block << PAGE_SHIFT) &&
+                               !(size & (((u64)pages_per_block << PAGE_SHIFT) - 1)))
                        min_block_size = (u64)pages_per_block << PAGE_SHIFT;
 
                cur_size = size;