@@ -1121,6 +1124,20 @@ vm_bind_prealloc_count(struct msm_vm_bind_job *job)
/* Flush the remaining range: */
prealloc_count(job, first, last);
+
+ /*
+ * Now that we know the needed amount to pre-alloc, throttle on pending
+ * VM_BIND jobs if we already have too much pre-alloc memory in flight
+ */
+ ret = wait_event_interruptible(
+ to_msm_vm(job->vm)->sched.job_scheduled,
+ atomic_read(&job->queue->in_flight_prealloc) <= 1024);
+ if (ret)
+ return ret;
+
+ atomic_add(job->prealloc.count, &job->queue->in_flight_prealloc);
+
+ return 0;
}