summaryrefslogtreecommitdiff
path: root/linux/shrinker.c
diff options
context:
space:
mode:
Diffstat (limited to 'linux/shrinker.c')
-rw-r--r--linux/shrinker.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/linux/shrinker.c b/linux/shrinker.c
index 23e288d8..0b5715b3 100644
--- a/linux/shrinker.c
+++ b/linux/shrinker.c
@@ -1,6 +1,7 @@
#include <stdio.h>
+#include <linux/kthread.h>
#include <linux/list.h>
#include <linux/mm.h>
#include <linux/mutex.h>
@@ -126,3 +127,31 @@ void run_shrinkers(gfp_t gfp_mask, bool allocation_failed)
}
mutex_unlock(&shrinker_lock);
}
+
+static int shrinker_thread(void *arg)
+{
+ while (!kthread_should_stop()) {
+ sleep(1);
+ run_shrinkers(GFP_KERNEL, false);
+ }
+
+ return 0;
+}
+
+struct task_struct *shrinker_task;
+
+__attribute__((constructor(103)))
+static void shrinker_thread_init(void)
+{
+ shrinker_task = kthread_run(shrinker_thread, NULL, "shrinkers");
+ BUG_ON(IS_ERR(shrinker_task));
+}
+
+__attribute__((destructor(103)))
+static void shrinker_thread_exit(void)
+{
+ int ret = kthread_stop(shrinker_task);
+ BUG_ON(ret);
+
+ shrinker_task = NULL;
+}