Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 317373
b: refs/heads/master
c: d7be394
h: refs/heads/master
i:
  317371: 21c6d6f
v: v3
  • Loading branch information
Sasha Levin authored and Greg Kroah-Hartman committed Jun 15, 2012
1 parent ef8e630 commit 709a64a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 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: 7489301a1590c2771d27a08d41fa2778791cdf9d
refs/heads/master: d7be394f7c2869e22d2258a1bba257661ca3fc52
38 changes: 21 additions & 17 deletions trunk/drivers/staging/zcache/zcache-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <linux/math64.h>
#include <linux/crypto.h>
#include <linux/string.h>
#include <linux/idr.h>
#include "tmem.h"

#include "../zsmalloc/zsmalloc.h"
Expand All @@ -53,15 +54,13 @@
(__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC)
#endif

#define MAX_POOLS_PER_CLIENT 16

#define MAX_CLIENTS 16
#define LOCAL_CLIENT ((uint16_t)-1)

MODULE_LICENSE("GPL");

struct zcache_client {
struct tmem_pool *tmem_pools[MAX_POOLS_PER_CLIENT];
struct idr tmem_pools;
struct zs_pool *zspool;
bool allocated;
atomic_t refcount;
Expand Down Expand Up @@ -949,11 +948,9 @@ static struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid)
goto out;
atomic_inc(&cli->refcount);
}
if (poolid < MAX_POOLS_PER_CLIENT) {
pool = cli->tmem_pools[poolid];
if (pool != NULL)
atomic_inc(&pool->refcount);
}
pool = idr_find(&cli->tmem_pools, poolid);
if (pool != NULL)
atomic_inc(&pool->refcount);
out:
return pool;
}
Expand Down Expand Up @@ -987,6 +984,7 @@ int zcache_new_client(uint16_t cli_id)
cli->zspool = zs_create_pool("zcache", ZCACHE_GFP_MASK);
if (cli->zspool == NULL)
goto out;
idr_init(&cli->tmem_pools);
#endif
ret = 0;
out:
Expand Down Expand Up @@ -1673,10 +1671,10 @@ static int zcache_destroy_pool(int cli_id, int pool_id)
if (cli == NULL)
goto out;
atomic_inc(&cli->refcount);
pool = cli->tmem_pools[pool_id];
pool = idr_find(&cli->tmem_pools, pool_id);
if (pool == NULL)
goto out;
cli->tmem_pools[pool_id] = NULL;
idr_remove(&cli->tmem_pools, pool_id);
/* wait for pool activity on other cpus to quiesce */
while (atomic_read(&pool->refcount) != 0)
;
Expand All @@ -1696,6 +1694,7 @@ static int zcache_new_pool(uint16_t cli_id, uint32_t flags)
int poolid = -1;
struct tmem_pool *pool;
struct zcache_client *cli = NULL;
int r;

if (cli_id == LOCAL_CLIENT)
cli = &zcache_host;
Expand All @@ -1710,20 +1709,25 @@ static int zcache_new_pool(uint16_t cli_id, uint32_t flags)
goto out;
}

for (poolid = 0; poolid < MAX_POOLS_PER_CLIENT; poolid++)
if (cli->tmem_pools[poolid] == NULL)
break;
if (poolid >= MAX_POOLS_PER_CLIENT) {
pr_info("zcache: pool creation failed: max exceeded\n");
do {
r = idr_pre_get(&cli->tmem_pools, GFP_ATOMIC);
if (r != 1) {
kfree(pool);
pr_info("zcache: pool creation failed: out of memory\n");
goto out;
}
r = idr_get_new(&cli->tmem_pools, pool, &poolid);
} while (r == -EAGAIN);
if (r) {
pr_info("zcache: pool creation failed: error %d\n", r);
kfree(pool);
poolid = -1;
goto out;
}

atomic_set(&pool->refcount, 0);
pool->client = cli;
pool->pool_id = poolid;
tmem_new_pool(pool, flags);
cli->tmem_pools[poolid] = pool;
pr_info("zcache: created %s tmem pool, id=%d, client=%d\n",
flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral",
poolid, cli_id);
Expand Down

0 comments on commit 709a64a

Please sign in to comment.