Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 235850
b: refs/heads/master
c: 939b3f0
h: refs/heads/master
v: v3
  • Loading branch information
Robert Jennings authored and Greg Kroah-Hartman committed Feb 4, 2011
1 parent 4c67a84 commit a395bc5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 43 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 2787f959d6c5fb258d964218ac75346019f49ee9
refs/heads/master: 939b3f0b1415755d534a20f4067e6b367e1e4021
73 changes: 31 additions & 42 deletions trunk/drivers/staging/zram/xvmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,55 +212,15 @@ static void insert_block(struct xv_pool *pool, struct page *page, u32 offset,
__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 = NULL;
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 = NULL;
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 @@ -276,6 +236,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 @@ -384,7 +373,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

0 comments on commit a395bc5

Please sign in to comment.