mm: pin locked file after fault. [1/2]
PD#SWPL-95400
Problem:
If we pin a file in android, the whole data of this file
will be loaded to DDR, but most of these data may not be
used, this caused memory waste.
Solution:
delay mark mlocked flags for unevictable pages until
it has been faulted.
You can use following command to disable this function:
echo 0 > /proc/sys/vm/shrink_unevictable
Verify:
sc2_ah212
Change-Id: I05bb7654cc228604fe692429efbe40af713ca5c3
Signed-off-by: Jianxiong Pan <jianxiong.pan@amlogic.com>
diff --git a/mm/mlock.c b/mm/mlock.c
index eec2418..96309ee 100644
--- a/mm/mlock.c
+++ b/mm/mlock.c
@@ -25,6 +25,9 @@
#include <linux/memcontrol.h>
#include <linux/mm_inline.h>
#include <linux/secretmem.h>
+#ifdef CONFIG_AMLOGIC_PIN_LOCKED_FILE
+#include <linux/amlogic/pin_file.h>
+#endif
#include "internal.h"
@@ -193,6 +196,7 @@ unsigned int munlock_vma_page(struct page *page)
/*
* convert get_user_pages() return value to posix mlock() error
*/
+#ifndef CONFIG_AMLOGIC_PIN_LOCKED_FILE_V2
static int __mlock_posix_error_return(long retval)
{
if (retval == -EFAULT)
@@ -201,6 +205,7 @@ static int __mlock_posix_error_return(long retval)
retval = -EAGAIN;
return retval;
}
+#endif
/*
* Prepare page for fast batched LRU putback via putback_lru_evictable_pagevec()
@@ -588,6 +593,9 @@ static int apply_vma_lock_flags(unsigned long start, size_t len,
tmp = vma->vm_end;
if (tmp > end)
tmp = end;
+ #ifdef CONFIG_AMLOGIC_PIN_LOCKED_FILE
+ reset_page_vma_flags(vma, flags);
+ #endif
error = mlock_fixup(vma, &prev, nstart, tmp, newflags);
if (error)
break;
@@ -686,9 +694,11 @@ static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t fla
if (error)
return error;
+#ifndef CONFIG_AMLOGIC_PIN_LOCKED_FILE_V2
error = __mm_populate(start, len, 0);
if (error)
return __mlock_posix_error_return(error);
+#endif
return 0;
}