msm: kgsl: Limit GPU memory buffer allocation sizes
Limit the size of individual GPU memory allocations to the amount of
free memory on the system minus 32MB. This early check gives us the
chance to verify that the user didn't ask for an obscene amount of
memory, and also to limit the chance that an allocation attempt will
invoke the OOM killer.
The 32MB buffer in particular should keep us out of the clutches of
the OOM killer. That number is the same amount of buffer used in
the page allocation alogrithms and it should keep the GPU from further
throwing fuel on the fire of a low memory situation.
Change-Id: Ic0dedbadcc5ee9cc0d77056b1a22eed5c385d636
Signed-off-by: Jordan Crouse <jcrouse@codeaurora.org>
Signed-off-by: Rajeev Kulkarni <krajeev@codeaurora.org>
diff --git a/drivers/gpu/msm/kgsl_sharedmem.c b/drivers/gpu/msm/kgsl_sharedmem.c
index 3f8071b..c579b26 100644
--- a/drivers/gpu/msm/kgsl_sharedmem.c
+++ b/drivers/gpu/msm/kgsl_sharedmem.c
@@ -510,6 +510,25 @@
struct page **pages = NULL;
pgprot_t page_prot = pgprot_writecombine(PAGE_KERNEL);
void *ptr;
+ struct sysinfo si;
+
+ /*
+ * Get the current memory information to be used in deciding if we
+ * should go ahead with this allocation
+ */
+
+ si_meminfo(&si);
+
+ /*
+ * Limit the size of the allocation to the amount of free memory minus
+ * 32MB. Why 32MB? Because thats the buffer that page_alloc uses and
+ * it just seems like a reasonable limit that won't make the OOM killer
+ * go all serial on us. Of course, if we are down this low all bets
+ * are off but above all do no harm.
+ */
+
+ if (size >= ((si.freeram << PAGE_SHIFT) - SZ_32M))
+ return -ENOMEM;
/*
* Add guard page to the end of the allocation when the