2009-09-22 04:56:53 +00:00
|
|
|
/*
|
2010-06-01 08:01:25 +00:00
|
|
|
* Compressed RAM block device
|
2009-09-22 04:56:53 +00:00
|
|
|
*
|
2010-01-28 15:51:35 +00:00
|
|
|
* Copyright (C) 2008, 2009, 2010 Nitin Gupta
|
2014-01-30 23:45:55 +00:00
|
|
|
* 2012, 2013 Minchan Kim
|
2009-09-22 04:56:53 +00:00
|
|
|
*
|
|
|
|
* This code is released using a dual license strategy: BSD/GPL
|
|
|
|
* You can choose the licence that better fits your requirements.
|
|
|
|
*
|
|
|
|
* Released under the terms of 3-clause BSD License
|
|
|
|
* Released under the terms of GNU General Public License Version 2.0
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-06-01 08:01:25 +00:00
|
|
|
#ifndef _ZRAM_DRV_H_
|
|
|
|
#define _ZRAM_DRV_H_
|
2009-09-22 04:56:53 +00:00
|
|
|
|
2010-01-28 15:43:37 +00:00
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/mutex.h>
|
2014-01-30 23:45:50 +00:00
|
|
|
#include <linux/zsmalloc.h>
|
2009-09-22 04:56:53 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some arbitrary value. This is just to catch
|
|
|
|
* invalid value for num_devices module parameter.
|
|
|
|
*/
|
|
|
|
static const unsigned max_num_devices = 32;
|
|
|
|
|
|
|
|
/*-- Configurable parameters */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pages that compress to size greater than this are stored
|
|
|
|
* uncompressed in memory.
|
|
|
|
*/
|
2011-09-09 23:01:00 +00:00
|
|
|
static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
|
2009-09-22 04:56:53 +00:00
|
|
|
|
|
|
|
/*
|
2010-05-13 08:54:21 +00:00
|
|
|
* NOTE: max_zpage_size must be less than or equal to:
|
2012-10-09 23:49:52 +00:00
|
|
|
* ZS_MAX_ALLOC_SIZE. Otherwise, zs_malloc() would
|
|
|
|
* always return failure.
|
2009-09-22 04:56:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*-- End of configurable params */
|
|
|
|
|
|
|
|
#define SECTOR_SHIFT 9
|
|
|
|
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
|
|
|
|
#define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
|
|
|
|
#define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
|
2011-06-10 13:28:48 +00:00
|
|
|
#define ZRAM_LOGICAL_BLOCK_SHIFT 12
|
|
|
|
#define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT)
|
|
|
|
#define ZRAM_SECTOR_PER_LOGICAL_BLOCK \
|
|
|
|
(1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT))
|
2009-09-22 04:56:53 +00:00
|
|
|
|
2010-06-01 08:01:25 +00:00
|
|
|
/* Flags for zram pages (table[page_no].flags) */
|
|
|
|
enum zram_pageflags {
|
2009-09-22 04:56:53 +00:00
|
|
|
/* Page consists entirely of zeros */
|
2010-06-01 08:01:25 +00:00
|
|
|
ZRAM_ZERO,
|
2009-09-22 04:56:53 +00:00
|
|
|
|
2010-06-01 08:01:25 +00:00
|
|
|
__NR_ZRAM_PAGEFLAGS,
|
2009-09-22 04:56:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*-- Data structures */
|
|
|
|
|
2010-06-01 08:01:25 +00:00
|
|
|
/* Allocated for each disk page */
|
2009-09-22 04:56:53 +00:00
|
|
|
struct table {
|
2012-06-08 06:39:25 +00:00
|
|
|
unsigned long handle;
|
2012-01-09 22:51:59 +00:00
|
|
|
u16 size; /* object size (excluding header) */
|
2009-09-22 04:56:53 +00:00
|
|
|
u8 count; /* object ref count (not yet used) */
|
|
|
|
u8 flags;
|
2012-06-07 23:03:48 +00:00
|
|
|
} __aligned(4);
|
2009-09-22 04:56:53 +00:00
|
|
|
|
2010-06-01 08:01:25 +00:00
|
|
|
struct zram_stats {
|
2013-06-06 16:07:31 +00:00
|
|
|
atomic64_t compr_size; /* compressed size of pages stored */
|
|
|
|
atomic64_t num_reads; /* failed + successful */
|
|
|
|
atomic64_t num_writes; /* --do-- */
|
|
|
|
atomic64_t failed_reads; /* should NEVER! happen */
|
|
|
|
atomic64_t failed_writes; /* can happen when memory is too low */
|
|
|
|
atomic64_t invalid_io; /* non-page-aligned I/O requests */
|
|
|
|
atomic64_t notify_free; /* no. of swap slot free notifications */
|
2014-01-30 23:46:02 +00:00
|
|
|
atomic_t pages_zero; /* no. of zero filled pages */
|
|
|
|
atomic_t pages_stored; /* no. of pages currently stored */
|
2009-09-22 04:56:53 +00:00
|
|
|
};
|
|
|
|
|
2013-02-05 23:48:53 +00:00
|
|
|
struct zram_meta {
|
2014-01-30 23:46:03 +00:00
|
|
|
rwlock_t tb_lock; /* protect table */
|
2009-09-22 04:56:53 +00:00
|
|
|
void *compress_workmem;
|
|
|
|
void *compress_buffer;
|
|
|
|
struct table *table;
|
2013-02-05 23:48:53 +00:00
|
|
|
struct zs_pool *mem_pool;
|
2014-01-30 23:46:06 +00:00
|
|
|
struct mutex buffer_lock; /* protect compress buffers */
|
2013-02-05 23:48:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct zram {
|
|
|
|
struct zram_meta *meta;
|
2009-09-22 04:56:53 +00:00
|
|
|
struct request_queue *queue;
|
|
|
|
struct gendisk *disk;
|
2011-09-06 13:02:11 +00:00
|
|
|
/* Prevent concurrent execution of device init, reset and R/W request */
|
|
|
|
struct rw_semaphore init_lock;
|
2009-09-22 04:56:53 +00:00
|
|
|
/*
|
2010-06-01 08:01:25 +00:00
|
|
|
* This is the limit on amount of *uncompressed* worth of data
|
|
|
|
* we can store in a disk.
|
2009-09-22 04:56:53 +00:00
|
|
|
*/
|
2010-08-09 17:26:47 +00:00
|
|
|
u64 disksize; /* bytes */
|
2009-09-22 04:56:53 +00:00
|
|
|
|
2010-06-01 08:01:25 +00:00
|
|
|
struct zram_stats stats;
|
2009-09-22 04:56:53 +00:00
|
|
|
};
|
2010-01-28 15:43:37 +00:00
|
|
|
#endif
|