@@ -30,6 +30,7 @@ static int shmem_get_pages(struct drm_i915_gem_object *obj)
struct drm_i915_private *i915 = to_i915(obj->base.dev);
struct intel_memory_region *mem = obj->mm.region;
const unsigned long page_count = obj->base.size / PAGE_SIZE;
+ resource_size_t size = obj->base.size;
unsigned long i;
struct address_space *mapping;
struct sg_table *st;
@@ -184,6 +185,8 @@ static int shmem_get_pages(struct drm_i915_gem_object *obj)
__i915_gem_object_set_pages(obj, st, sg_page_sizes);
+ mem->avail -= size;
+
return 0;
err_sg:
@@ -298,6 +301,8 @@ __i915_gem_object_release_shmem(struct drm_i915_gem_object *obj,
void i915_gem_object_put_pages_shmem(struct drm_i915_gem_object *obj, struct sg_table *pages)
{
+ struct intel_memory_region *mem = obj->mm.region;
+ resource_size_t size = obj->base.size;
struct sgt_iter sgt_iter;
struct pagevec pvec;
struct page *page;
@@ -326,6 +331,8 @@ void i915_gem_object_put_pages_shmem(struct drm_i915_gem_object *obj, struct sg_
check_release_pagevec(&pvec);
obj->mm.dirty = false;
+ mem->avail += size;
+
sg_free_table(pages);
kfree(pages);
}