~ubuntu-branches/ubuntu/trusty/linux-ti-omap/trusty

« back to all changes in this revision

Viewing changes to ubuntu/compcache/ramzswap.h

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Bader, Amit Kucheria
  • Date: 2010-03-23 18:05:12 UTC
  • Revision ID: james.westby@ubuntu.com-20100323180512-iavj906ocnphdubp
Tags: 2.6.33-500.3
[ Amit Kucheria ]

* [Config] Fix the debug package name to end in -dbgsym
* SAUCE: Add the ubuntu/ drivers to omap
* SAUCE: Re-export the symbols for aufs
* [Config] Enable AUFS and COMPCACHE

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Compressed RAM based swap device
 
3
 *
 
4
 * Copyright (C) 2008, 2009  Nitin Gupta
 
5
 *
 
6
 * This RAM based block device acts as swap disk.
 
7
 * Pages swapped to this device are compressed and
 
8
 * stored in memory.
 
9
 *
 
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 _RAMZSWAP_H_
 
16
#define _RAMZSWAP_H_
 
17
 
 
18
#include "xvmalloc.h"
 
19
 
 
20
/*
 
21
 * Stored at beginning of each compressed object.
 
22
 *
 
23
 * It stores back-reference to table entry which points to this
 
24
 * object. This is required to support memory defragmentation or
 
25
 * migrating compressed pages to backing swap disk.
 
26
 */
 
27
struct zobj_header {
 
28
#if 0
 
29
        u32 table_idx;
 
30
#endif
 
31
};
 
32
 
 
33
/*-- Configurable parameters */
 
34
 
 
35
/* Default ramzswap disk size: 25% of total RAM */
 
36
#define DEFAULT_DISKSIZE_PERC_RAM       25
 
37
#define DEFAULT_MEMLIMIT_PERC_RAM       15
 
38
 
 
39
/*
 
40
 * Max compressed page size when backing device is provided.
 
41
 * Pages that compress to size greater than this are sent to
 
42
 * physical swap disk.
 
43
 */
 
44
#define MAX_CPAGE_SIZE_BDEV     (PAGE_SIZE / 2)
 
45
 
 
46
/*
 
47
 * Max compressed page size when there is no backing dev.
 
48
 * Pages that compress to size greater than this are stored
 
49
 * uncompressed in memory.
 
50
 */
 
51
#define MAX_CPAGE_SIZE_NOBDEV   (PAGE_SIZE / 4 * 3)
 
52
 
 
53
/*
 
54
 * NOTE: MAX_CPAGE_SIZE_{BDEV,NOBDEV} sizes must be
 
55
 * less than or equal to:
 
56
 *   XV_MAX_ALLOC_SIZE - sizeof(struct zobj_header)
 
57
 * since otherwise xvMalloc would always return failure.
 
58
 */
 
59
 
 
60
/*-- End of configurable params */
 
61
 
 
62
#define SECTOR_SHIFT            9
 
63
#define SECTOR_SIZE             (1 << SECTOR_SHIFT)
 
64
#define SECTORS_PER_PAGE_SHIFT  (PAGE_SHIFT - SECTOR_SHIFT)
 
65
#define SECTORS_PER_PAGE        (1 << SECTORS_PER_PAGE_SHIFT)
 
66
 
 
67
/* Message prefix */
 
68
#define C "ramzswap: "
 
69
 
 
70
/* Debugging and Stats */
 
71
#define NOP     do { } while (0)
 
72
 
 
73
#if defined(CONFIG_BLK_DEV_RAMZSWAP_STATS)
 
74
#define STATS
 
75
#endif
 
76
 
 
77
#if defined(STATS)
 
78
#define stat_inc(stat)                  ((stat)++)
 
79
#define stat_dec(stat)                  ((stat)--)
 
80
#define stat_inc_if_less(stat, val1, val2) \
 
81
                                ((stat) += ((val1) < (val2) ? 1 : 0))
 
82
#define stat_dec_if_less(stat, val1, val2) \
 
83
                                ((stat) -= ((val1) < (val2) ? 1 : 0))
 
84
#else   /* STATS */
 
85
#define stat_inc(x)                     NOP
 
86
#define stat_dec(x)                     NOP
 
87
#define stat_inc_if_less(x, v1, v2)     NOP
 
88
#define stat_dec_if_less(x, v1, v2)     NOP
 
89
#endif  /* STATS */
 
90
 
 
91
/* Flags for ramzswap pages (table[page_no].flags) */
 
92
enum rzs_pageflags {
 
93
        /* Page is stored uncompressed */
 
94
        RZS_UNCOMPRESSED,
 
95
 
 
96
        /* Page consists entirely of zeros */
 
97
        RZS_ZERO,
 
98
 
 
99
        __NR_RZS_PAGEFLAGS,
 
100
};
 
101
 
 
102
/*-- Data structures */
 
103
 
 
104
/* Indexed by page no. */
 
105
struct table {
 
106
        u32 pagenum;
 
107
        u16 offset;
 
108
        u8 count;       /* object ref count (not yet used) */
 
109
        u8 flags;
 
110
};
 
111
 
 
112
struct ramzswap {
 
113
        struct xv_pool *mem_pool;
 
114
        void *compress_workmem;
 
115
        void *compress_buffer;
 
116
        struct table *table;
 
117
        struct mutex lock;
 
118
        struct gendisk *disk;
 
119
        /*
 
120
         * This is limit on compressed data size (stats.compr_size)
 
121
         * Its applicable only when backing swap device is present.
 
122
         */
 
123
        size_t memlimit;        /* bytes */
 
124
        /*
 
125
         * This is limit on amount of *uncompressed* worth of data
 
126
         * we can hold. When backing swap device is provided, it is
 
127
         * set equal to device size.
 
128
         */
 
129
        size_t disksize;        /* bytes */
 
130
 
 
131
        /* backing swap device info */
 
132
        struct block_device *backing_swap;
 
133
        struct file *swap_file;
 
134
        int old_block_size;
 
135
};
 
136
 
 
137
struct ramzswap_stats {
 
138
        /* basic stats */
 
139
        size_t compr_size;      /* compressed size of pages stored -
 
140
                                 * needed to enforce memlimit */
 
141
        /* more stats */
 
142
#if defined(STATS)
 
143
        u64 num_reads;          /* failed + successful */
 
144
        u64 num_writes;         /* --do-- */
 
145
        u64 failed_reads;       /* can happen when memory is too low */
 
146
        u64 failed_writes;      /* should NEVER! happen */
 
147
        u64 invalid_io;         /* non-swap I/O requests */
 
148
        u64 pages_discard;      /* no. of pages freed by discard callback */
 
149
        u32 pages_zero;         /* no. of zero filled pages */
 
150
        u32 pages_stored;       /* no. of pages currently stored */
 
151
        u32 good_compress;      /* no. of pages with compression ratio<=50% */
 
152
        u32 pages_expand;       /* no. of incompressible pages */
 
153
        u64 bdev_num_reads;     /* no. of reads on backing dev */
 
154
        u64 bdev_num_writes;    /* no. of writes on backing dev */
 
155
#endif
 
156
};
 
157
/*-- */
 
158
 
 
159
#endif