提交 2b7b3ad2 编写于 作者: M Maarten Lankhorst 提交者: Dave Airlie

drm/ttm: cope with reserved buffers on swap list in ttm_bo_swapout, v2

Replace the while loop with a simple for each loop, and only run the
delayed destroy cleanup if we can reserve the buffer first.

No race occurs, since lru lock is never dropped any more. An empty list
and a list full of unreservable buffers both cause -EBUSY to be returned,
which is identical to the previous situation.
Signed-off-by: NMaarten Lankhorst <maarten.lankhorst@canonical.com>
Reviewed-by: NThomas Hellstrom <thellstrom@vmware.com>
Signed-off-by: NDave Airlie <airlied@redhat.com>
上级 85b144f8
...@@ -1813,41 +1813,25 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink) ...@@ -1813,41 +1813,25 @@ static int ttm_bo_swapout(struct ttm_mem_shrink *shrink)
uint32_t swap_placement = (TTM_PL_FLAG_CACHED | TTM_PL_FLAG_SYSTEM); uint32_t swap_placement = (TTM_PL_FLAG_CACHED | TTM_PL_FLAG_SYSTEM);
spin_lock(&glob->lru_lock); spin_lock(&glob->lru_lock);
while (ret == -EBUSY) { list_for_each_entry(bo, &glob->swap_lru, swap) {
if (unlikely(list_empty(&glob->swap_lru))) { ret = ttm_bo_reserve_locked(bo, false, true, false, 0);
spin_unlock(&glob->lru_lock); if (!ret)
return -EBUSY; break;
} }
bo = list_first_entry(&glob->swap_lru,
struct ttm_buffer_object, swap);
kref_get(&bo->list_kref);
if (!list_empty(&bo->ddestroy)) {
ttm_bo_reserve_locked(bo, false, false, false, 0);
ttm_bo_cleanup_refs_and_unlock(bo, false, false);
kref_put(&bo->list_kref, ttm_bo_release_list); if (ret) {
spin_lock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
continue; return ret;
} }
/** kref_get(&bo->list_kref);
* Reserve buffer. Since we unlock while sleeping, we need
* to re-check that nobody removed us from the swap-list while
* we slept.
*/
ret = ttm_bo_reserve_locked(bo, false, true, false, 0); if (!list_empty(&bo->ddestroy)) {
if (unlikely(ret == -EBUSY)) { ret = ttm_bo_cleanup_refs_and_unlock(bo, false, false);
spin_unlock(&glob->lru_lock); kref_put(&bo->list_kref, ttm_bo_release_list);
ttm_bo_wait_unreserved(bo, false); return ret;
kref_put(&bo->list_kref, ttm_bo_release_list);
spin_lock(&glob->lru_lock);
}
} }
BUG_ON(ret != 0);
put_count = ttm_bo_del_from_lru(bo); put_count = ttm_bo_del_from_lru(bo);
spin_unlock(&glob->lru_lock); spin_unlock(&glob->lru_lock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册