summaryrefslogtreecommitdiff
path: root/linux-core/drm_memory.c
diff options
context:
space:
mode:
authorThomas Hellstrom <thomas-at-tungstengraphics-dot-com>2008-04-28 12:10:44 +0200
committerThomas Hellstrom <thomas-at-tungstengraphics-dot-com>2008-04-28 12:10:44 +0200
commit7f269bec7ed49385de394fdbd970f463ef2060f0 (patch)
tree8c45f8c2e11cf101350272f81892cf4cf7678c3a /linux-core/drm_memory.c
parent55a9941977953d16b36bbf3e1dcad392ac70e1ef (diff)
parent7f8e4060859651993921281445ec00940c577222 (diff)
Merge branch 'master' into modesetting-101
Conflicts: linux-core/Makefile.kernel linux-core/drm_compat.c linux-core/drm_fops.c linux-core/drm_lock.c shared-core/drm.h shared-core/i915_dma.c shared-core/i915_drv.h shared-core/i915_irq.c
Diffstat (limited to 'linux-core/drm_memory.c')
-rw-r--r--linux-core/drm_memory.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/linux-core/drm_memory.c b/linux-core/drm_memory.c
index 12e01414..75f5b521 100644
--- a/linux-core/drm_memory.c
+++ b/linux-core/drm_memory.c
@@ -61,35 +61,39 @@ static inline size_t drm_size_align(size_t size)
int drm_alloc_memctl(size_t size)
{
- int ret = 0;
+ int ret = 0;
unsigned long a_size = drm_size_align(size);
- unsigned long new_used = drm_memctl.cur_used + a_size;
+ unsigned long new_used;
spin_lock(&drm_memctl.lock);
- if (unlikely(new_used > drm_memctl.high_threshold)) {
- if (!DRM_SUSER(DRM_CURPROC) ||
- (new_used + drm_memctl.emer_used > drm_memctl.emer_threshold) ||
- (a_size > 2*PAGE_SIZE)) {
- ret = -ENOMEM;
- goto out;
- }
-
- /*
- * Allow small root-only allocations, even if the
- * high threshold is exceeded.
- */
-
- new_used -= drm_memctl.high_threshold;
- drm_memctl.emer_used += new_used;
- a_size -= new_used;
+ new_used = drm_memctl.cur_used + a_size;
+ if (likely(new_used < drm_memctl.high_threshold)) {
+ drm_memctl.cur_used = new_used;
+ goto out;
}
- drm_memctl.cur_used += a_size;
+
+ /*
+ * Allow small allocations from root-only processes to
+ * succeed until the emergency threshold is reached.
+ */
+
+ new_used += drm_memctl.emer_used;
+ if (unlikely(!DRM_SUSER(DRM_CURPROC) ||
+ (a_size > 16*PAGE_SIZE) ||
+ (new_used > drm_memctl.emer_threshold))) {
+ ret = -ENOMEM;
+ goto out;
+ }
+
+ drm_memctl.cur_used = drm_memctl.high_threshold;
+ drm_memctl.emer_used = new_used - drm_memctl.high_threshold;
out:
spin_unlock(&drm_memctl.lock);
return ret;
}
EXPORT_SYMBOL(drm_alloc_memctl);
+
void drm_free_memctl(size_t size)
{
unsigned long a_size = drm_size_align(size);