Skip to content

Commit b74fae5

Browse files
author
Rob Clark
committed
drm/msm: Add VM_BIND throttling
A large number of (unsorted or separate) small (<2MB) mappings can cause a lot of, probably unnecessary, prealloc pages. Ie. a single 4k page size mapping will pre-allocate 3 pages (for levels 2-4) for the pagetable. Which can chew up a large amount of unneeded memory. So add a mechanism to put an upper bound on the # of pre-alloc pages. Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com> Tested-by: Antonino Maniscalco <antomani103@gmail.com> Reviewed-by: Antonino Maniscalco <antomani103@gmail.com> Patchwork: https://patchwork.freedesktop.org/patch/661529/
1 parent 3bebfd5 commit b74fae5

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

drivers/gpu/drm/msm/msm_gem.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ struct msm_gem_vm {
7575
*/
7676
struct drm_gpu_scheduler sched;
7777

78+
/**
79+
* @prealloc_throttle: Used to throttle VM_BIND ops if too much pre-
80+
* allocated memory is in flight.
81+
*
82+
* Because we have to pre-allocate pgtable pages for the worst case
83+
* (ie. new mappings do not share any PTEs with existing mappings)
84+
* we could end up consuming a lot of resources transiently. The
85+
* prealloc_throttle puts an upper bound on that.
86+
*/
87+
struct {
88+
/** @wait: Notified when preallocated resources are released */
89+
wait_queue_head_t wait;
90+
91+
/**
92+
* @in_flight: The # of preallocated pgtable pages in-flight
93+
* for queued VM_BIND jobs.
94+
*/
95+
atomic_t in_flight;
96+
} prealloc_throttle;
97+
7898
/**
7999
* @mm: Memory management for kernel managed VA allocations
80100
*

drivers/gpu/drm/msm/msm_gem_vma.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,8 @@ msm_vma_job_free(struct drm_sched_job *_job)
705705

706706
vm->mmu->funcs->prealloc_cleanup(vm->mmu, &job->prealloc);
707707

708+
atomic_sub(job->prealloc.count, &vm->prealloc_throttle.in_flight);
709+
708710
drm_sched_job_cleanup(_job);
709711

710712
job_foreach_bo (obj, job)
@@ -721,6 +723,8 @@ msm_vma_job_free(struct drm_sched_job *_job)
721723
kfree(op);
722724
}
723725

726+
wake_up(&vm->prealloc_throttle.wait);
727+
724728
kfree(job);
725729
}
726730

@@ -783,6 +787,8 @@ msm_gem_vm_create(struct drm_device *drm, struct msm_mmu *mmu, const char *name,
783787
ret = drm_sched_init(&vm->sched, &args);
784788
if (ret)
785789
goto err_free_dummy;
790+
791+
init_waitqueue_head(&vm->prealloc_throttle.wait);
786792
}
787793

788794
drm_gpuvm_init(&vm->base, name, flags, drm, dummy_gem,
@@ -1090,10 +1096,12 @@ ops_are_same_pte(struct msm_vm_bind_op *first, struct msm_vm_bind_op *next)
10901096
* them as a single mapping. Otherwise the prealloc_count() will not realize
10911097
* they can share pagetable pages and vastly overcount.
10921098
*/
1093-
static void
1099+
static int
10941100
vm_bind_prealloc_count(struct msm_vm_bind_job *job)
10951101
{
10961102
struct msm_vm_bind_op *first = NULL, *last = NULL;
1103+
struct msm_gem_vm *vm = to_msm_vm(job->vm);
1104+
int ret;
10971105

10981106
for (int i = 0; i < job->nr_ops; i++) {
10991107
struct msm_vm_bind_op *op = &job->ops[i];
@@ -1122,6 +1130,20 @@ vm_bind_prealloc_count(struct msm_vm_bind_job *job)
11221130

11231131
/* Flush the remaining range: */
11241132
prealloc_count(job, first, last);
1133+
1134+
/*
1135+
* Now that we know the needed amount to pre-alloc, throttle on pending
1136+
* VM_BIND jobs if we already have too much pre-alloc memory in flight
1137+
*/
1138+
ret = wait_event_interruptible(
1139+
vm->prealloc_throttle.wait,
1140+
atomic_read(&vm->prealloc_throttle.in_flight) <= 1024);
1141+
if (ret)
1142+
return ret;
1143+
1144+
atomic_add(job->prealloc.count, &vm->prealloc_throttle.in_flight);
1145+
1146+
return 0;
11251147
}
11261148

11271149
/*
@@ -1412,7 +1434,9 @@ msm_ioctl_vm_bind(struct drm_device *dev, void *data, struct drm_file *file)
14121434
if (ret)
14131435
goto out_unlock;
14141436

1415-
vm_bind_prealloc_count(job);
1437+
ret = vm_bind_prealloc_count(job);
1438+
if (ret)
1439+
goto out_unlock;
14161440

14171441
struct drm_exec exec;
14181442
unsigned flags = DRM_EXEC_IGNORE_DUPLICATES | DRM_EXEC_INTERRUPTIBLE_WAIT;

0 commit comments

Comments
 (0)