--- /dev/null
+# Comment/uncomment the following line to disable/enable debugging
+#DEBUG = y
+
+# Add your debugging flag (or not) to CFLAGS
+ifeq ($(DEBUG),y)
+ DEBFLAGS = -O -g # "-O" is needed to expand inlines
+else
+ DEBFLAGS = -O2
+endif
+
+EXTRA_CFLAGS += $(DEBFLAGS) -I$(LDDINCDIR)
+
+ifneq ($(KERNELRELEASE),)
+# call from kernel build system
+
+obj-m := wb_to_wc.o
+
+else
+
+KERNELDIR ?= /lib/modules/$(shell uname -r)/build
+PWD := $(shell pwd)
+
+default:
+ $(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINCDIR=$(PWD)/../include modules
+
+endif
+
+clean:
+ rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
+
+depend .depend dep:
+ $(CC) $(CFLAGS) -M *.c > .depend
+
+
+ifeq (.depend,$(wildcard .depend))
+include .depend
+endif
--- /dev/null
+#include <linux/module.h>
+#include <linux/kthread.h>
+#include <linux/pagemap.h>
+#include <linux/init.h>
+#define WB_TO_WC "0.1"
+
+MODULE_AUTHOR("Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>");
+MODULE_DESCRIPTION("wb_to_wc_and_back");
+MODULE_LICENSE("GPL");
+MODULE_VERSION(WB_TO_WC);
+
+#define MAX_PAGES 20
+static int thread(void *arg)
+{
+ struct page *a[MAX_PAGES];
+ unsigned int i, j;
+ do {
+ for (j = 0, i = 0;i < MAX_PAGES; i++, j++) {
+ a[i] = alloc_page(GFP_KERNEL);
+ if (!a[i])
+ break;
+ }
+ set_pages_array_wc(a, j);
+ set_current_state(TASK_INTERRUPTIBLE);
+ schedule_timeout_interruptible(HZ);
+ for (i = 0; i < j; i++) {
+ unsigned long *addr = page_address(a[i]);
+ if (addr) {
+ memset(addr, 0xc2, PAGE_SIZE);
+ }
+ }
+ set_pages_array_wb(a, j);
+ for (i = 0; i< MAX_PAGES; i++) {
+ if (a[i])
+ __free_page(a[i]);
+ a[i] = NULL;
+ }
+ } while (!kthread_should_stop());
+ return 0;
+}
+static struct task_struct *t;
+static int __init wb_to_wc_init(void)
+{
+ t = kthread_run(thread, NULL, "wb_to_wc_and_back");
+ return 0;
+}
+static void __exit wb_to_wc_exit(void)
+{
+ if (t)
+ kthread_stop(t);
+}
+module_init(wb_to_wc_init);
+module_exit(wb_to_wc_exit);