Skip to content

Instantly share code, notes, and snippets.

@muriloadriano
Created October 3, 2013 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muriloadriano/d5343a50e802dea8d868 to your computer and use it in GitHub Desktop.
Save muriloadriano/d5343a50e802dea8d868 to your computer and use it in GitHub Desktop.
Cleancache backend implementation
#include <linux/cleancache.h>
#include <linux/init.h>
#include <linux/module.h>
/* Allocation flags */
#define ZCOMPRAM_GFP_MASK (GFP_ATOMIC | __GFP_NORETRY | __GFP_NOWARN)
/* Initial page pool: 32 MB (2^13 * 4KB) in pages */
#define ZCOMPRAM_ORDER 13
/* The pool holding the compressed pages */
struct page* page_pool;
/* Clean cache operations implementation */
static void zcompram_cleancache_put_page(int pool_id,
struct cleancache_filekey key,
pgoff_t index, struct page *page)
{
printk(KERN_INFO "ZCOMPRAM: PUT PAGE %d %ld %p\n", pool_id, index, page);
}
static int zcompram_cleancache_get_page(int pool_id,
struct cleancache_filekey key,
pgoff_t index, struct page *page)
{
printk(KERN_INFO "ZCOMPRAM: GET PAGE %d %ld %p\n", pool_id, index, page);
return -1;
}
static void zcompram_cleancache_flush_page(int pool_id,
struct cleancache_filekey key,
pgoff_t index)
{
printk(KERN_INFO "ZCOMPRAM: FLUSH PAGE\n");
}
static void zcompram_cleancache_flush_inode(int pool_id,
struct cleancache_filekey key)
{
printk(KERN_INFO "ZCOMPRAM: FLUSH INODE\n");
}
static void zcompram_cleancache_flush_fs(int pool_id)
{
printk(KERN_INFO "ZCOMPRAM: FLUSH FS\n");
}
static int zcompram_cleancache_init_fs(size_t pagesize)
{
printk(KERN_INFO "ZCOMPRAM: INIT FS\n");
return -1;
}
static int zcompram_cleancache_init_shared_fs(char *uuid, size_t pagesize)
{
printk(KERN_INFO "ZCOMPRAM: FLUSH INIT SHARED\n");
return -1;
}
static struct cleancache_ops zcompram_cleancache_ops = {
.put_page = zcompram_cleancache_put_page,
.get_page = zcompram_cleancache_get_page,
.invalidate_page = zcompram_cleancache_flush_page,
.invalidate_inode = zcompram_cleancache_flush_inode,
.invalidate_fs = zcompram_cleancache_flush_fs,
.init_shared_fs = zcompram_cleancache_init_shared_fs,
.init_fs = zcompram_cleancache_init_fs
};
struct cleancache_ops zcompram_cleancache_register_ops(void)
{
struct cleancache_ops old_ops =
cleancache_register_ops(&zcompram_cleancache_ops);
return old_ops;
}
static int __init zcompram_init(void)
{
printk(KERN_INFO ">> ZCOMPRAM INIT\n");
page_pool = alloc_pages(ZCOMPRAM_GFP_MASK, ZCOMPRAM_ORDER);
zcompram_cleancache_register_ops();
if (cleancache_enabled) {
printk(KERN_INFO ">> ZCOMPRAM: cleancache_enabled\n");
}
else {
printk(KERN_INFO ">> ZCOMPRAM: cleancache_disabled\n");
}
return 0;
}
static void zcompram_exit(void)
{
__free_pages(page_pool, ZCOMPRAM_ORDER);
}
module_init(zcompram_init);
module_exit(zcompram_exit);
MODULE_LICENSE("GPL");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment