staging: zcache: introduce zero filled pages handler
authorWanpeng Li <liwanp@linux.vnet.ibm.com>
Fri, 15 Mar 2013 02:34:16 +0000 (10:34 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 19 Mar 2013 00:24:35 +0000 (17:24 -0700)
Introduce zero-filled pages handler to capture and handle zero pages.

Acked-by: Dan Magenheimer <dan.magenheimer@oracle.com>
Signed-off-by: Wanpeng Li <liwanp@linux.vnet.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/zcache/zcache-main.c

index 7a6dd966931bb78fba747d132b130d2718df3f49..86ead8d96796858d8d70da214c71ac532b08b7ef 100644 (file)
@@ -277,6 +277,32 @@ static void zcache_obj_free(struct tmem_obj *obj, struct tmem_pool *pool)
        kmem_cache_free(zcache_obj_cache, obj);
 }
 
+static bool page_is_zero_filled(void *ptr)
+{
+       unsigned int pos;
+       unsigned long *page;
+
+       page = (unsigned long *)ptr;
+
+       for (pos = 0; pos < PAGE_SIZE / sizeof(*page); pos++) {
+               if (page[pos])
+                       return false;
+       }
+
+       return true;
+}
+
+static void handle_zero_filled_page(void *page)
+{
+       void *user_mem;
+
+       user_mem = kmap_atomic(page);
+       memset(user_mem, 0, PAGE_SIZE);
+       kunmap_atomic(user_mem);
+
+       flush_dcache_page(page);
+}
+
 static struct tmem_hostops zcache_hostops = {
        .obj_alloc = zcache_obj_alloc,
        .obj_free = zcache_obj_free,