~ubuntu-branches/ubuntu/precise/linux-lts-saucy/precise-proposed

« back to all changes in this revision

Viewing changes to drivers/staging/zram/zram_drv.h

  • Committer: Package Import Robot
  • Author(s): Tim Gardner
  • Date: 2013-10-09 13:31:18 UTC
  • Revision ID: package-import@ubuntu.com-20131009133118-l5q5o2hmtz96hefq
Tags: upstream-3.11.0
ImportĀ upstreamĀ versionĀ 3.11.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Compressed RAM block device
 
3
 *
 
4
 * Copyright (C) 2008, 2009, 2010  Nitin Gupta
 
5
 *
 
6
 * This code is released using a dual license strategy: BSD/GPL
 
7
 * You can choose the licence that better fits your requirements.
 
8
 *
 
9
 * Released under the terms of 3-clause BSD License
 
10
 * Released under the terms of GNU General Public License Version 2.0
 
11
 *
 
12
 * Project home: http://compcache.googlecode.com
 
13
 */
 
14
 
 
15
#ifndef _ZRAM_DRV_H_
 
16
#define _ZRAM_DRV_H_
 
17
 
 
18
#include <linux/spinlock.h>
 
19
#include <linux/mutex.h>
 
20
 
 
21
#include "../zsmalloc/zsmalloc.h"
 
22
 
 
23
/*
 
24
 * Some arbitrary value. This is just to catch
 
25
 * invalid value for num_devices module parameter.
 
26
 */
 
27
static const unsigned max_num_devices = 32;
 
28
 
 
29
/*-- Configurable parameters */
 
30
 
 
31
/*
 
32
 * Pages that compress to size greater than this are stored
 
33
 * uncompressed in memory.
 
34
 */
 
35
static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
 
36
 
 
37
/*
 
38
 * NOTE: max_zpage_size must be less than or equal to:
 
39
 *   ZS_MAX_ALLOC_SIZE. Otherwise, zs_malloc() would
 
40
 * always return failure.
 
41
 */
 
42
 
 
43
/*-- End of configurable params */
 
44
 
 
45
#define SECTOR_SHIFT            9
 
46
#define SECTOR_SIZE             (1 << SECTOR_SHIFT)
 
47
#define SECTORS_PER_PAGE_SHIFT  (PAGE_SHIFT - SECTOR_SHIFT)
 
48
#define SECTORS_PER_PAGE        (1 << SECTORS_PER_PAGE_SHIFT)
 
49
#define ZRAM_LOGICAL_BLOCK_SHIFT 12
 
50
#define ZRAM_LOGICAL_BLOCK_SIZE (1 << ZRAM_LOGICAL_BLOCK_SHIFT)
 
51
#define ZRAM_SECTOR_PER_LOGICAL_BLOCK   \
 
52
        (1 << (ZRAM_LOGICAL_BLOCK_SHIFT - SECTOR_SHIFT))
 
53
 
 
54
/* Flags for zram pages (table[page_no].flags) */
 
55
enum zram_pageflags {
 
56
        /* Page consists entirely of zeros */
 
57
        ZRAM_ZERO,
 
58
 
 
59
        __NR_ZRAM_PAGEFLAGS,
 
60
};
 
61
 
 
62
/*-- Data structures */
 
63
 
 
64
/* Allocated for each disk page */
 
65
struct table {
 
66
        unsigned long handle;
 
67
        u16 size;       /* object size (excluding header) */
 
68
        u8 count;       /* object ref count (not yet used) */
 
69
        u8 flags;
 
70
} __aligned(4);
 
71
 
 
72
/*
 
73
 * All 64bit fields should only be manipulated by 64bit atomic accessors.
 
74
 * All modifications to 32bit counter should be protected by zram->lock.
 
75
 */
 
76
struct zram_stats {
 
77
        atomic64_t compr_size;  /* compressed size of pages stored */
 
78
        atomic64_t num_reads;   /* failed + successful */
 
79
        atomic64_t num_writes;  /* --do-- */
 
80
        atomic64_t failed_reads;        /* should NEVER! happen */
 
81
        atomic64_t failed_writes;       /* can happen when memory is too low */
 
82
        atomic64_t invalid_io;  /* non-page-aligned I/O requests */
 
83
        atomic64_t notify_free; /* no. of swap slot free notifications */
 
84
        u32 pages_zero;         /* no. of zero filled pages */
 
85
        u32 pages_stored;       /* no. of pages currently stored */
 
86
        u32 good_compress;      /* % of pages with compression ratio<=50% */
 
87
        u32 bad_compress;       /* % of pages with compression ratio>=75% */
 
88
};
 
89
 
 
90
struct zram_meta {
 
91
        void *compress_workmem;
 
92
        void *compress_buffer;
 
93
        struct table *table;
 
94
        struct zs_pool *mem_pool;
 
95
};
 
96
 
 
97
struct zram {
 
98
        struct zram_meta *meta;
 
99
        struct rw_semaphore lock; /* protect compression buffers, table,
 
100
                                   * 32bit stat counters against concurrent
 
101
                                   * notifications, reads and writes */
 
102
        struct request_queue *queue;
 
103
        struct gendisk *disk;
 
104
        int init_done;
 
105
        /* Prevent concurrent execution of device init, reset and R/W request */
 
106
        struct rw_semaphore init_lock;
 
107
        /*
 
108
         * This is the limit on amount of *uncompressed* worth of data
 
109
         * we can store in a disk.
 
110
         */
 
111
        u64 disksize;   /* bytes */
 
112
 
 
113
        struct zram_stats stats;
 
114
};
 
115
#endif