Merge tag 'v3.10.72' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / mm / compaction.c
index eeaaa929d1debf611c1cd87adb3e949c701580bb..dcf59d582ae9cd35c83f306dd5c76b51a251fcd3 100644 (file)
 #include <linux/page-isolation.h>
 #include "internal.h"
 
+#ifdef CONFIG_HAS_EARLYSUSPEND
+#include <linux/earlysuspend.h>
+#endif
+
 #ifdef CONFIG_COMPACTION
 static inline void count_compact_event(enum vm_event_item item)
 {
@@ -226,6 +230,9 @@ static bool suitable_migration_target(struct page *page)
        if (is_migrate_isolate(migratetype))
                return false;
 
+       if (is_migrate_mtkpasr(migratetype))
+               return false;
+
        /* If the page is a large free page, then allow migration */
        if (PageBuddy(page) && page_order(page) >= pageblock_order)
                return true;
@@ -1230,3 +1237,58 @@ void compaction_unregister_node(struct node *node)
 #endif /* CONFIG_SYSFS && CONFIG_NUMA */
 
 #endif /* CONFIG_COMPACTION */
+
+#ifdef CONFIG_HAS_EARLYSUSPEND
+extern void drop_pagecache(void);
+//extern void kick_lmk_from_compaction(gfp_t);
+static void kick_compaction_early_suspend(struct early_suspend *h)
+{
+       struct zone *z = &NODE_DATA(0)->node_zones[ZONE_NORMAL];
+       int status;
+       int retry = 3;
+       int safe_order = THREAD_SIZE_ORDER + 1; 
+       bool contended;
+       gfp_t gfp_mask = GFP_KERNEL;
+
+       /* Check whether gfp is restricted. */
+       if (gfp_mask != (gfp_mask & gfp_allowed_mask)) {
+               printk("XXXXXX GFP is restricted! XXXXXX\n");
+               return;
+       }
+
+       /* We try retry times at most. */
+       while (retry > 0) {
+               /* If it is safe under low watermark, then break. */
+               if (zone_watermark_ok(z, safe_order, low_wmark_pages(z), 0, 0))
+                       break;
+               status = compact_zone_order(z, safe_order, gfp_mask, true, &contended);
+               --retry;
+       }
+}
+
+static void kick_compaction_late_resume(struct early_suspend *h)
+{
+       /* Do nothing */
+}
+
+static struct early_suspend kick_compaction_early_suspend_desc = {
+       .level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1,
+       .suspend = kick_compaction_early_suspend,
+       .resume = kick_compaction_late_resume,
+};
+
+static int __init compaction_init(void)
+{
+       printk("@@@@@@ [%s] Register early suspend callback @@@@@@\n",__FUNCTION__);
+       register_early_suspend(&kick_compaction_early_suspend_desc);
+       return 0;
+}
+static void __exit compaction_exit(void)
+{
+       printk("@@@@@@ [%s] Unregister early suspend callback @@@@@@\n",__FUNCTION__);
+       unregister_early_suspend(&kick_compaction_early_suspend_desc);
+}
+
+module_init(compaction_init);
+module_exit(compaction_exit);
+#endif