[Galaxy Tab 2 7" Android Development] Android-Andi:
thanks for the Information :) what about the other patches from this update [MENTION=4021423]ketut.kumajaya[/MENTION] (https://github.com/andi34/android_k...mmit/a32f427eacde7361b99da0e13c72bc6c6a31bc54)?

Do we need all the changes added for zram?

I reverted the patch now in my github....

BTW: I think i did everything wrong to the "mm/vmscan.c" :p

here is the diff

diff --git a/./samsungkernel/mm/vmscan.c b/./samsungkernel3/mm/vmscan.c
index 66ee0d1..99443aa 100644
--- a/./samsungkernel/mm/vmscan.c
+++ b/./samsungkernel3/mm/vmscan.c
@@ -117,6 +117,11 @@ struct scan_control {

#define lru_to_page(_head) (list_entry((_head)->prev, struct page, lru))

+#ifdef CONFIG_ZRAM_FOR_ANDROID
+atomic_t kswapd_thread_on = ATOMIC_INIT(1);
+extern int get_soft_reclaim_status(void);
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
+
#ifdef ARCH_HAS_PREFETCH
#define prefetch_prev_lru_page(_page, _base, _field)	\
do {	\
@@ -1269,6 +1274,13 @@ static int too_many_isolated(struct zone *zone, int file,
{
unsigned long inactive, isolated;

+#ifdef CONFIG_ZRAM_FOR_ANDROID
+	if(get_soft_reclaim_status() == 1)
+	{
+	return 0;
+	}
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
+
if (current_is_kswapd())
return 0;

@@ -1983,6 +1995,10 @@ restart:
*/
if (nr_reclaimed >= nr_to_reclaim && priority < DEF_PRIORITY)
break;
+#ifdef CONFIG_ZRAM_FOR_ANDROID
+	if ((sc->nr_reclaimed + nr_reclaimed) >= nr_to_reclaim && sc->may_swap)
+	break;
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
}
blk_finish_plug(&plug);
sc->nr_reclaimed += nr_reclaimed;
@@ -2023,7 +2039,11 @@ static void shrink_zones(int priority, struct zonelist *zonelist,
{
struct zoneref *z;
struct zone *zone;
+#ifdef CONFIG_ZRAM_FOR_ANDROID
+	unsigned long nr_soft_reclaimed = 0;
+#else
unsigned long nr_soft_reclaimed;
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
unsigned long nr_soft_scanned;

for_each_zone_zonelist_nodemask(zone, z, zonelist,
@@ -2046,9 +2066,11 @@ static void shrink_zones(int priority, struct zonelist *zonelist,
* and balancing, not for a memcg's limit.
*/
nr_soft_scanned = 0;
+#ifndef CONFIG_ZRAM_FOR_ANDROID
nr_soft_reclaimed = mem_cgroup_soft_limit_reclaim(zone,
sc->order, sc->gfp_mask,
&nr_soft_scanned);
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
sc->nr_reclaimed += nr_soft_reclaimed;
sc->nr_scanned += nr_soft_scanned;
/* need some check for avoid more shrink_zone() */
@@ -2201,8 +2223,11 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
.may_writepage = !laptop_mode,
.nr_to_reclaim = SWAP_CLUSTER_MAX,
.may_unmap = 1,
+#ifdef CONFIG_ZRAM_FOR_ANDROID
+	.may_swap = 0,
+#else
.may_swap = 1,
-	.swappiness = vm_swappiness,
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
.order = order,
.mem_cgroup = NULL,
.nodemask = nodemask,
@@ -2416,12 +2441,20 @@ static unsigned long balance_pgdat(pg_data_t *pgdat, int order,
int end_zone = 0;	/* Inclusive. 0 = ZONE_DMA */
unsigned long total_scanned;
struct reclaim_state *reclaim_state = current->reclaim_state;
+#ifdef CONFIG_ZRAM_FOR_ANDROID
+	unsigned long nr_soft_reclaimed = 0;
+#else
unsigned long nr_soft_reclaimed;
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
unsigned long nr_soft_scanned;
struct scan_control sc = {
.gfp_mask = GFP_KERNEL,
.may_unmap = 1,
+#ifdef CONFIG_ZRAM_FOR_ANDROID
+	.may_swap = 0,
+#else
.may_swap = 1,
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
/*
* kswapd doesn't want to be bailed out while reclaim. because
* we want to put equal scanning pressure on each zone.
@@ -2513,9 +2546,11 @@ loop_again:
/*
* Call soft limit reclaim before calling shrink_zone.
*/
+#ifndef CONFIG_ZRAM_FOR_ANDROID
nr_soft_reclaimed = mem_cgroup_soft_limit_reclaim(zone,
order, sc.gfp_mask,
&nr_soft_scanned);
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
sc.nr_reclaimed += nr_soft_reclaimed;
total_scanned += nr_soft_scanned;

@@ -2711,6 +2746,11 @@ static void kswapd_try_to_sleep(pg_data_t *pgdat, int order, int classzone_idx)
* per-cpu vmstat threshold while kswapd is awake and restore
* them before going back to sleep.
*/
+
+#ifdef CONFIG_ZRAM_FOR_ANDROID
+	atomic_set(&kswapd_thread_on,0);
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
+
set_pgdat_percpu_threshold(pgdat, calculate_normal_threshold);
schedule();
set_pgdat_percpu_threshold(pgdat, calculate_pressure_threshold);
@@ -2805,6 +2845,10 @@ static int kswapd(void *p)
if (kthread_should_stop())
break;

+#ifdef CONFIG_ZRAM_FOR_ANDROID
+	atomic_set(&kswapd_thread_on, 1);
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
+
/*
* We can speed up thawing tasks if we don't call balance_pgdat
* after returning from the refrigerator
@@ -2878,6 +2922,129 @@ unsigned long zone_reclaimable_pages(struct zone *zone)
return nr;
}

+#ifdef CONFIG_ZRAM_FOR_ANDROID
+/*
+ * This is the main entry point to direct page reclaim for RTCC.
+ *
+ * If a full scan of the inactive list fails to free enough memory then we
+ * are "out of memory" and something needs to be killed.
+ *
+ * If the caller is !__GFP_FS then the probability of a failure is reasonably
+ * high - the zone may be full of dirty or under-writeback pages, which this
+ * caller can't do much about. We kick the writeback threads and take explicit
+ * naps in the hope that some of these pages can be written. But if the
+ * allocating task holds filesystem locks which prevent writeout this might not
+ * work, and the allocation attempt will fail.
+ *
+ * returns:	0, if no pages reclaimed
+ *	else, the number of pages reclaimed
+ */
+static unsigned long rtcc_do_try_to_free_pages(struct zonelist *zonelist, struct scan_control *sc, struct shrink_control *shrink)
+{
+	int priority;
+	unsigned long total_scanned = 0;
+	struct zoneref *z;
+	struct zone *zone;
+	unsigned long writeback_threshold;
+
+	get_mems_allowed();
+	delayacct_freepages_start();
+
+	if (scanning_global_lru(sc))
+	count_vm_event(ALLOCSTALL);
+
+	for (priority = DEF_PRIORITY; priority >= 0; priority--) {
+	sc->nr_scanned = 0;
+	if (!priority)
+	disable_swap_token(sc->mem_cgroup);
+	shrink_zones(priority, zonelist, sc);
+	total_scanned += sc->nr_scanned;
+	if (sc->nr_reclaimed >= sc->nr_to_reclaim)
+	goto out;
+
+	/*
+	* Try to write back as many pages as we just scanned. This
+	* tends to cause slow streaming writers to write data to the
+	* disk smoothly, at the dirtying rate, which is nice. But
+	* that's undesirable in laptop mode, where we *want* lumpy
+	* writeout. So in laptop mode, write out the whole world.
+	*/
+	writeback_threshold = sc->nr_to_reclaim + sc->nr_to_reclaim / 2;
+	if (total_scanned > writeback_threshold) {
+	wakeup_flusher_threads(laptop_mode ? 0 : total_scanned);
+	sc->may_writepage = 1;
+	}
+
+	/* Take a nap, wait for some writeback to complete */
+	if (!sc->hibernation_mode && sc->nr_scanned &&
+	priority < DEF_PRIORITY - 2) {
+	struct zone *preferred_zone;
+
+	first_zones_zonelist(zonelist, gfp_zone(sc->gfp_mask),
+	&cpuset_current_mems_allowed,
+	&preferred_zone);
+	wait_iff_congested(preferred_zone, BLK_RW_ASYNC, HZ/10);
+	}
+	}
+
+out:
+	delayacct_freepages_end();
+	put_mems_allowed();
+
+	if (sc->nr_reclaimed)
+	return sc->nr_reclaimed;
+
+	/*
+	* As hibernation is going on, kswapd is freezed so that it can't mark
+	* the zone into all_unreclaimable. Thus bypassing all_unreclaimable
+	* check.
+	*/
+	if (oom_killer_disabled)
+	return 0;
+
+	/* top priority shrink_zones still had more to do? don't OOM, then */
+	if (scanning_global_lru(sc) && !all_unreclaimable(zonelist, sc))
+	return 1;
+
+	return 0;
+}
+
+long rtcc_reclaim_pages(long nr_to_reclaim)
+{
+	struct reclaim_state reclaim_state;
+	struct scan_control sc = {
+	.gfp_mask = GFP_KERNEL,
+	.may_swap = 1,
+	.may_unmap = 1,
+	.may_writepage = 1,
+	.nr_to_reclaim = nr_to_reclaim,
+	.swappiness = 100,
+	.order = 0,
+	};
+	struct shrink_control shrink = {
+	.gfp_mask = sc.gfp_mask,
+	};
+	struct zonelist *zonelist = node_zonelist(numa_node_id(), sc.gfp_mask);
+	struct task_struct *p = current;
+	unsigned long nr_reclaimed;
+
+	p->flags |= PF_MEMALLOC;
+	lockdep_set_current_reclaim_state(sc.gfp_mask);
+	reclaim_state.reclaimed_slab = 0;
+	p->reclaim_state = &reclaim_state;
+
+	nr_reclaimed = rtcc_do_try_to_free_pages(zonelist, &sc, &shrink);
+
+	p->reclaim_state = NULL;
+	lockdep_clear_current_reclaim_state();
+	p->flags &= ~PF_MEMALLOC;
+
+	printk("RTCC, reclaim %ld pages\n", nr_reclaimed);
+
+	return nr_reclaimed;
+}
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
+
#ifdef CONFIG_HIBERNATION
/*
* Try to free `nr_to_reclaim' of memory, system-wide, and return the number of
@@ -3080,7 +3247,11 @@ static int __zone_reclaim(struct zone *zone, gfp_t gfp_mask, unsigned int order)
struct scan_control sc = {
.may_writepage = !!(zone_reclaim_mode & RECLAIM_WRITE),
.may_unmap = !!(zone_reclaim_mode & RECLAIM_SWAP),
+#ifdef CONFIG_ZRAM_FOR_ANDROID
+	.may_swap = 0,
+#else
.may_swap = 1,
+#endif /* CONFIG_ZRAM_FOR_ANDROID */
.nr_to_reclaim = max_t(unsigned long, nr_pages,
SWAP_CLUSTER_MAX),
.gfp_mask = gfp_mask,