static int do_compcache(void * nothing)
{
	int ret;
	set_freezable();

	for ( ; ; ) {
		ret = try_to_freeze();
		if (kthread_should_stop())
			break;

		if (atomic_read(&s_reclaim.kcompcached_running) == 1) {
			if (rtcc_reclaim_pages(number_of_reclaim_pages) < minimum_reclaim_pages)
				cancel_soft_reclaim();

			atomic_set(&s_reclaim.kcompcached_running, 0);
		}

		set_current_state(TASK_INTERRUPTIBLE);
		schedule();
	}

	return 0;
}
Ejemplo n.º 2
0
/*
 * RTCC thread entry
 */
static int rtcc_thread(void * nothing)
{
	unsigned long nr_to_reclaim, nr_reclaimed, nr_swapped;
#if RTCC_DBG
	unsigned long dt;
	struct timeval tv1, tv2;
#endif

	set_freezable();

	for ( ; ; ) {
		try_to_freeze();
		if (kthread_should_stop())
			break;

		if (likely(atomic_read(&krtccd_running) == 1)) {
#if RTCC_DBG
			do_gettimeofday(&tv1);
#endif
			swap_toplimit = get_swapped_pages() + get_anon_pages() / 2;
			swap_toplimit = min(swap_toplimit, total_swap_pages);

			nr_to_reclaim = get_reclaim_count();
			nr_swapped = 0;

			nr_reclaimed = rtcc_reclaim_pages(nr_to_reclaim, 200, &nr_swapped);
			nr_krtccd_swapped += nr_swapped;

			printk("reclaimed %ld (swapped %ld) pages.\n", nr_reclaimed, nr_swapped);

			if (likely(rtcc_boost_mode == 0)) {
				if (get_rtcc_grade() <= 0) {
					// If free memory is enough, cancel reclaim
					atomic_set(&need_to_reclaim, 0);
				} else if ((swap_toplimit - get_swapped_pages()) <= rtcc_grade[RTCC_GRADE_NUM-2]) {
					// If swap space is more than anon, also cancel reclaim
					atomic_set(&need_to_reclaim, 0);
				}
			} else if (get_anon_pages() < swap_toplimit / 4) {
				rtcc_boost_mode = 0;
				printk("swapped %ldMB enough, exit boost mode.\n", get_swapped_pages()/256);
			} else if (time_after(jiffies, boost_end_jiffy)) {
				rtcc_boost_mode = 0;
				printk("time out, swapped %ldMB, exit boost mode.\n", get_swapped_pages()/256);
			}

			atomic_set(&krtccd_running, 0);

#if RTCC_DBG
			do_gettimeofday(&tv2);
			dt = tv2.tv_sec*1000000 + tv2.tv_usec - tv1.tv_sec*1000000 - tv1.tv_usec;
			printk("cost %ldms, %ldus one page, ", dt/1000, dt/nr_reclaimed);
#endif
		}

		set_current_state(TASK_INTERRUPTIBLE);
		schedule();
	}

	return 0;
}