jemalloc: Allow opting in for MADVISE_FREE

"MADV_FREE" is more powerful than "MADV_DONTNEED" which
is noticable in cases where there is high memory pressure.
Allowing Jemalloc to use "MADV_FREE" also enables
it to perform lazy page purging.

So, add an option to opt in to the usage
of "MADV_FREE" in jemalloc.
Targets which have "MADVISE_FREE" support
should always opt in by setting
"TARGET_SUPPORTS_MADVISE_FREE" to true
in order to benefit from lazy page
purging in jemalloc.

Change-Id: Ie7455fe9d24f710146ed64f6e5ad1debde60aae3
Signed-off-by: Alex Naidis <alex.naidis@linux.com>
diff --git a/Android.mk b/Android.mk
index 608a5f3..d6d11b4 100644
--- a/Android.mk
+++ b/Android.mk
@@ -71,6 +71,14 @@
 jemalloc_common_cflags += -DJEMALLOC_THP
 endif
 
+# Enable Jemalloc MADVISE_FREE usage if
+# the target specifies that its kernel supports
+# MADVISE_FREE. This enables the lazy page
+# purge feature.
+ifeq ($(TARGET_SUPPORTS_MADVISE_FREE),true)
+  jemalloc_common_cflags += -DJEMALLOC_PURGE_MADVISE_FREE
+endif
+
 # Use a 512K chunk size on 32 bit systems.
 # This keeps the total amount of virtual address space consumed
 # by jemalloc lower.