Skip to content

Commit

Permalink
updated to patched ZRAM (thanks to @faux123)
Browse files Browse the repository at this point in the history
  • Loading branch information
DooMLoRD authored and Napstar-xda committed May 28, 2012
1 parent 168c4b9 commit 9034ae5
Show file tree
Hide file tree
Showing 11 changed files with 606 additions and 333 deletions.
7 changes: 7 additions & 0 deletions kernel/arch/arm/configs/uckernel_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,14 @@ CONFIG_ANDROID_LOW_MEMORY_KILLER=y
# RAR Register Driver
#
# CONFIG_IIO is not set
CONFIG_XVMALLOC=y
CONFIG_ZRAM=y
CONFIG_ZRAM_NUM_DEVICES=1
CONFIG_ZRAM_DEFAULT_PERCENTAGE=25
# CONFIG_ZRAM_DEBUG is not set
CONFIG_ZRAM_LZO=y
# CONFIG_ZRAM_SNAPPY is not set
CONFIG_ZRAM_DEFAULT_DISKSIZE=100663296
# CONFIG_BATMAN_ADV is not set
# CONFIG_FB_SM7XX is not set

Expand Down
3 changes: 2 additions & 1 deletion kernel/drivers/staging/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ obj-$(CONFIG_RAR_REGISTER) += rar_register/
obj-$(CONFIG_MRST_RAR_HANDLER) += memrar/
obj-$(CONFIG_DX_SEP) += sep/
obj-$(CONFIG_IIO) += iio/
obj-$(CONFIG_ZRAM) += zram/
obj-$(CONFIG_ZRAM) += zram/
obj-$(CONFIG_XVMALLOC) += zram/
obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/
obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/
obj-$(CONFIG_BATMAN_ADV) += batman-adv/
Expand Down
60 changes: 57 additions & 3 deletions kernel/drivers/staging/zram/Kconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
config XVMALLOC
bool
default n

config ZRAM
tristate "Compressed RAM block device support"
depends on BLOCK
select LZO_COMPRESS
select LZO_DECOMPRESS
depends on BLOCK && SYSFS
select XVMALLOC
default n
help
Creates virtual block devices called /dev/zramX (X = 0, 1, ...).
Expand All @@ -15,3 +18,54 @@ config ZRAM

See zram.txt for more information.
Project home: http://compcache.googlecode.com/

config ZRAM_NUM_DEVICES
int "Default number of zram devices"
depends on ZRAM
range 1 32
default 1
help
Select default number of zram devices. You can override this value
using 'num_devices' module parameter.

config ZRAM_DEFAULT_PERCENTAGE
int "Default number of zram percentage"
depends on ZRAM
range 10 80
default 25
help
Select default zram disk size: percentage of total RAM

config ZRAM_DEBUG
bool "Compressed RAM block device debug support"
depends on ZRAM
default n
help
This option adds additional debugging code to the compressed
RAM block device driver.

choice ZRAM_COMPRESS
prompt "compression method"
depends on ZRAM
default ZRAM_LZO
help
Select the compression method used by zram.
LZO is the default. Snappy compresses a bit worse (around ~2%) but
much (~2x) faster, at least on x86-64.
config ZRAM_LZO
bool "LZO compression"
select LZO_COMPRESS
select LZO_DECOMPRESS
config ZRAM_SNAPPY
bool "Snappy compression"
depends on SNAPPY_COMPRESS
depends on SNAPPY_DECOMPRESS
endchoice

config ZRAM_DEFAULT_DISKSIZE
int "Default size of zram in bytes"
depends on ZRAM
default 100663296
help
Set default zram disk size (default ~ 96MB)

3 changes: 2 additions & 1 deletion kernel/drivers/staging/zram/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
zram-y := zram_drv.o zram_sysfs.o xvmalloc.o
zram-y := zram_drv.o zram_sysfs.o

obj-$(CONFIG_ZRAM) += zram.o
obj-$(CONFIG_XVMALLOC) += xvmalloc.o
91 changes: 47 additions & 44 deletions kernel/drivers/staging/zram/xvmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
* Released under the terms of GNU General Public License Version 2.0
*/

#ifdef CONFIG_ZRAM_DEBUG
#define DEBUG
#endif

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/highmem.h>
Expand Down Expand Up @@ -46,7 +52,7 @@ static void clear_flag(struct block_header *block, enum blockflags flag)
}

/*
* Given <page, offset> pair, provide a derefrencable pointer.
* Given <page, offset> pair, provide a dereferencable pointer.
* This is called from xv_malloc/xv_free path, so it
* needs to be fast.
*/
Expand Down Expand Up @@ -187,7 +193,7 @@ static void insert_block(struct xv_pool *pool, struct page *page, u32 offset,
slindex = get_index_for_insert(block->size);
flindex = slindex / BITS_PER_LONG;

block->link.prev_page = 0;
block->link.prev_page = NULL;
block->link.prev_offset = 0;
block->link.next_page = pool->freelist[slindex].page;
block->link.next_offset = pool->freelist[slindex].offset;
Expand All @@ -200,61 +206,23 @@ static void insert_block(struct xv_pool *pool, struct page *page, u32 offset,
nextblock->link.prev_page = page;
nextblock->link.prev_offset = offset;
put_ptr_atomic(nextblock, KM_USER1);
/* If there was a next page then the free bits are set. */
return;
}

__set_bit(slindex % BITS_PER_LONG, &pool->slbitmap[flindex]);
__set_bit(flindex, &pool->flbitmap);
}

/*
* Remove block from head of freelist. Index 'slindex' identifies the freelist.
*/
static void remove_block_head(struct xv_pool *pool,
struct block_header *block, u32 slindex)
{
struct block_header *tmpblock;
u32 flindex = slindex / BITS_PER_LONG;

pool->freelist[slindex].page = block->link.next_page;
pool->freelist[slindex].offset = block->link.next_offset;
block->link.prev_page = 0;
block->link.prev_offset = 0;

if (!pool->freelist[slindex].page) {
__clear_bit(slindex % BITS_PER_LONG, &pool->slbitmap[flindex]);
if (!pool->slbitmap[flindex])
__clear_bit(flindex, &pool->flbitmap);
} else {
/*
* DEBUG ONLY: We need not reinitialize freelist head previous
* pointer to 0 - we never depend on its value. But just for
* sanity, lets do it.
*/
tmpblock = get_ptr_atomic(pool->freelist[slindex].page,
pool->freelist[slindex].offset, KM_USER1);
tmpblock->link.prev_page = 0;
tmpblock->link.prev_offset = 0;
put_ptr_atomic(tmpblock, KM_USER1);
}
}

/*
* Remove block from freelist. Index 'slindex' identifies the freelist.
*/
static void remove_block(struct xv_pool *pool, struct page *page, u32 offset,
struct block_header *block, u32 slindex)
{
u32 flindex;
u32 flindex = slindex / BITS_PER_LONG;
struct block_header *tmpblock;

if (pool->freelist[slindex].page == page
&& pool->freelist[slindex].offset == offset) {
remove_block_head(pool, block, slindex);
return;
}

flindex = slindex / BITS_PER_LONG;

if (block->link.prev_page) {
tmpblock = get_ptr_atomic(block->link.prev_page,
block->link.prev_offset, KM_USER1);
Expand All @@ -270,6 +238,35 @@ static void remove_block(struct xv_pool *pool, struct page *page, u32 offset,
tmpblock->link.prev_offset = block->link.prev_offset;
put_ptr_atomic(tmpblock, KM_USER1);
}

/* Is this block is at the head of the freelist? */
if (pool->freelist[slindex].page == page
&& pool->freelist[slindex].offset == offset) {

pool->freelist[slindex].page = block->link.next_page;
pool->freelist[slindex].offset = block->link.next_offset;

if (pool->freelist[slindex].page) {
struct block_header *tmpblock;
tmpblock = get_ptr_atomic(pool->freelist[slindex].page,
pool->freelist[slindex].offset,
KM_USER1);
tmpblock->link.prev_page = NULL;
tmpblock->link.prev_offset = 0;
put_ptr_atomic(tmpblock, KM_USER1);
} else {
/* This freelist bucket is empty */
__clear_bit(slindex % BITS_PER_LONG,
&pool->slbitmap[flindex]);
if (!pool->slbitmap[flindex])
__clear_bit(flindex, &pool->flbitmap);
}
}

block->link.prev_page = NULL;
block->link.prev_offset = 0;
block->link.next_page = NULL;
block->link.next_offset = 0;
}

/*
Expand Down Expand Up @@ -320,11 +317,13 @@ struct xv_pool *xv_create_pool(void)

return pool;
}
EXPORT_SYMBOL_GPL(xv_create_pool);

void xv_destroy_pool(struct xv_pool *pool)
{
kfree(pool);
}
EXPORT_SYMBOL_GPL(xv_destroy_pool);

/**
* xv_malloc - Allocate block of given size from pool.
Expand Down Expand Up @@ -378,7 +377,7 @@ int xv_malloc(struct xv_pool *pool, u32 size, struct page **page,

block = get_ptr_atomic(*page, *offset, KM_USER0);

remove_block_head(pool, block, index);
remove_block(pool, *page, *offset, block, index);

/* Split the block if required */
tmpoffset = *offset + size + XV_ALIGN;
Expand Down Expand Up @@ -413,6 +412,7 @@ int xv_malloc(struct xv_pool *pool, u32 size, struct page **page,

return 0;
}
EXPORT_SYMBOL_GPL(xv_malloc);

/*
* Free block identified with <page, offset>
Expand Down Expand Up @@ -489,6 +489,7 @@ void xv_free(struct xv_pool *pool, struct page *page, u32 offset)
put_ptr_atomic(page_start, KM_USER0);
spin_unlock(&pool->lock);
}
EXPORT_SYMBOL_GPL(xv_free);

u32 xv_get_object_size(void *obj)
{
Expand All @@ -497,6 +498,7 @@ u32 xv_get_object_size(void *obj)
blk = (struct block_header *)((char *)(obj) - XV_ALIGN);
return blk->size;
}
EXPORT_SYMBOL_GPL(xv_get_object_size);

/*
* Returns total memory used by allocator (userdata + metadata)
Expand All @@ -505,3 +507,4 @@ u64 xv_get_total_size_bytes(struct xv_pool *pool)
{
return pool->total_pages << PAGE_SHIFT;
}
EXPORT_SYMBOL_GPL(xv_get_total_size_bytes);
23 changes: 16 additions & 7 deletions kernel/drivers/staging/zram/xvmalloc_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,28 @@
/* User configurable params */

/* Must be power of two */
#ifdef CONFIG_64BIT
#define XV_ALIGN_SHIFT 3
#else
#define XV_ALIGN_SHIFT 2
#endif
#define XV_ALIGN (1 << XV_ALIGN_SHIFT)
#define XV_ALIGN_MASK (XV_ALIGN - 1)

/* This must be greater than sizeof(link_free) */
#define XV_MIN_ALLOC_SIZE 32
#define XV_MAX_ALLOC_SIZE (PAGE_SIZE - XV_ALIGN)

/* Free lists are separated by FL_DELTA bytes */
#define FL_DELTA_SHIFT 3
/*
* Free lists are separated by FL_DELTA bytes
* This value is 3 for 4k pages and 4 for 64k pages, for any
* other page size, a conservative (PAGE_SHIFT - 9) is used.
*/
#if PAGE_SHIFT == 16
#define FL_DELTA_SHIFT 4
#else
#define FL_DELTA_SHIFT (PAGE_SHIFT - 9)
#endif
#define FL_DELTA (1 << FL_DELTA_SHIFT)
#define FL_DELTA_MASK (FL_DELTA - 1)
#define NUM_FREE_LISTS ((XV_MAX_ALLOC_SIZE - XV_MIN_ALLOC_SIZE) \
Expand Down Expand Up @@ -75,12 +87,9 @@ struct block_header {
struct xv_pool {
ulong flbitmap;
ulong slbitmap[MAX_FLI];
spinlock_t lock;

u64 total_pages; /* stats */
struct freelist_entry freelist[NUM_FREE_LISTS];

/* stats */
u64 total_pages;
spinlock_t lock;
};

#endif
Loading

0 comments on commit 9034ae5

Please sign in to comment.