/* Thread function performing automatic memory scanning. Unreferenced objects at the end of a memory scan are reported but only the first time.  */
static int kmemleak_scan_thread(void *arg)
/* Thread function performing automatic memory scanning. Unreferenced objects at the end of a memory scan are reported but only the first time.  */
static int kmemleak_scan_thread(void *arg)
{
	static int first_run = 1;
	pr_info("Automatic memory scanning thread started\n");
	set_user_nice(current, 10);
	if (first_run) {
		first_run = 0;
		ssleep(SECS_FIRST_SCAN);
	}
	while (!kthread_should_stop()) {
		signed long timeout = jiffies_scan_wait;
		mutex_lock(&scan_mutex);
		kmemleak_scan();
		mutex_unlock(&scan_mutex);
		while (timeout && !kthread_should_stop())
			timeout = schedule_timeout_interruptible(timeout);
	}
	pr_info("Automatic memory scanning thread ended\n");
	return 0;
}