mirror of
https://github.com/torvalds/linux.git
synced 2026-05-16 02:25:58 +02:00
Userspace can severely fragment rb_hole_addr rbtree by manipulating
alignment while allocating buffers. Fragmented rb_hole_addr rbtree
would result in large delays while allocating buffer object for a
userspace application. It takes long time to find suitable hole
because if we fail to find a suitable hole in the first attempt
then we look for neighbouring nodes using rb_prev()/rb_next().
Traversing rbtree using rb_prev()/rb_next() can take really long
time if the tree is fragmented.
This patch improves searches in fragmented rb_hole_addr rbtree by
modifying it to an augmented rbtree which will store an extra field
in drm_mm_node, subtree_max_hole. Each drm_mm_node now stores maximum
hole size for its subtree in drm_mm_node->subtree_max_hole. Using
drm_mm_node->subtree_max_hole, it is possible to eliminate a complete
subtree if that subtree is unable to serve a request hence reducing
number of rb_prev()/rb_next() used.
With this patch applied, 1 million bo allocs on amdgpu took ~8 sec,
compared to 50k bo allocs which took 28 sec without it.
partial test code:
int test_fragmentation(void)
{
int i = 0;
uint32_t minor_version;
uint32_t major_version;
struct amdgpu_bo_alloc_request request = {};
amdgpu_bo_handle vram_handle[MAX_ALLOC] = {};
amdgpu_device_handle device_handle;
request.alloc_size = 4096;
request.phys_alignment = 8192;
request.preferred_heap = AMDGPU_GEM_DOMAIN_VRAM;
int fd = open("/dev/dri/card0", O_RDWR | O_CLOEXEC);
amdgpu_device_initialize(fd, &major_version, &minor_version,
&device_handle);
for (i = 0; i < MAX_ALLOC; i++) {
amdgpu_bo_alloc(device_handle, &request, &vram_handle[i]);
}
for (i = 0; i < MAX_ALLOC; i++)
amdgpu_bo_free(vram_handle[i]);
return 0;
}
v2:
Use RB_DECLARE_CALLBACKS_MAX to maintain subtree_max_hole
v3:
insert_hole_addr() should be static a function
fix return value of next_hole_high_addr()/next_hole_low_addr()
Reported-by: kbuild test robot <lkp@intel.com>
v4:
Fix commit message.
Signed-off-by: Nirmoy Das <nirmoy.das@amd.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Acked-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/364341/
Signed-off-by: Christian König <christian.koenig@amd.com>
|
||
|---|---|---|
| .. | ||
| bridge | ||
| i2c | ||
| ttm | ||
| amd_asic_type.h | ||
| drm_agpsupport.h | ||
| drm_atomic_helper.h | ||
| drm_atomic_state_helper.h | ||
| drm_atomic_uapi.h | ||
| drm_atomic.h | ||
| drm_audio_component.h | ||
| drm_auth.h | ||
| drm_blend.h | ||
| drm_bridge_connector.h | ||
| drm_bridge.h | ||
| drm_cache.h | ||
| drm_client.h | ||
| drm_color_mgmt.h | ||
| drm_connector.h | ||
| drm_crtc_helper.h | ||
| drm_crtc.h | ||
| drm_damage_helper.h | ||
| drm_debugfs_crc.h | ||
| drm_debugfs.h | ||
| drm_device.h | ||
| drm_displayid.h | ||
| drm_dp_dual_mode_helper.h | ||
| drm_dp_helper.h | ||
| drm_dp_mst_helper.h | ||
| drm_drv.h | ||
| drm_dsc.h | ||
| drm_edid.h | ||
| drm_encoder_slave.h | ||
| drm_encoder.h | ||
| drm_fb_cma_helper.h | ||
| drm_fb_helper.h | ||
| drm_file.h | ||
| drm_fixed.h | ||
| drm_flip_work.h | ||
| drm_format_helper.h | ||
| drm_fourcc.h | ||
| drm_framebuffer.h | ||
| drm_gem_cma_helper.h | ||
| drm_gem_framebuffer_helper.h | ||
| drm_gem_shmem_helper.h | ||
| drm_gem_ttm_helper.h | ||
| drm_gem_vram_helper.h | ||
| drm_gem.h | ||
| drm_hashtab.h | ||
| drm_hdcp.h | ||
| drm_ioctl.h | ||
| drm_irq.h | ||
| drm_lease.h | ||
| drm_legacy.h | ||
| drm_managed.h | ||
| drm_mipi_dbi.h | ||
| drm_mipi_dsi.h | ||
| drm_mm.h | ||
| drm_mode_config.h | ||
| drm_mode_object.h | ||
| drm_modes.h | ||
| drm_modeset_helper_vtables.h | ||
| drm_modeset_helper.h | ||
| drm_modeset_lock.h | ||
| drm_of.h | ||
| drm_panel.h | ||
| drm_pciids.h | ||
| drm_plane_helper.h | ||
| drm_plane.h | ||
| drm_prime.h | ||
| drm_print.h | ||
| drm_probe_helper.h | ||
| drm_property.h | ||
| drm_rect.h | ||
| drm_scdc_helper.h | ||
| drm_self_refresh_helper.h | ||
| drm_simple_kms_helper.h | ||
| drm_syncobj.h | ||
| drm_sysfs.h | ||
| drm_util.h | ||
| drm_utils.h | ||
| drm_vblank.h | ||
| drm_vma_manager.h | ||
| drm_writeback.h | ||
| gma_drm.h | ||
| gpu_scheduler.h | ||
| i915_component.h | ||
| i915_drm.h | ||
| i915_mei_hdcp_interface.h | ||
| i915_pciids.h | ||
| intel_lpe_audio.h | ||
| intel-gtt.h | ||
| spsc_queue.h | ||
| task_barrier.h | ||