Commit d7be394f authored by Sasha Levin's avatar Sasha Levin Committed by Greg Kroah-Hartman

staging: zcache: don't limit number of pools per client

Currently the amount of pools each client can use is limited to 16, this is
and arbitrary limit which isn't really required by current implementation.

This places and arbitrary limit on the number of mounted filesystems that
can use cleancache.

This patch removes that limit and uses IDR to do sparse mapping of pools
in each client.
Signed-off-by: default avatarSasha Levin <levinsasha928@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7489301a
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <linux/math64.h> #include <linux/math64.h>
#include <linux/crypto.h> #include <linux/crypto.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/idr.h>
#include "tmem.h" #include "tmem.h"
#include "../zsmalloc/zsmalloc.h" #include "../zsmalloc/zsmalloc.h"
...@@ -53,15 +54,13 @@ ...@@ -53,15 +54,13 @@
(__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC) (__GFP_FS | __GFP_NORETRY | __GFP_NOWARN | __GFP_NOMEMALLOC)
#endif #endif
#define MAX_POOLS_PER_CLIENT 16
#define MAX_CLIENTS 16 #define MAX_CLIENTS 16
#define LOCAL_CLIENT ((uint16_t)-1) #define LOCAL_CLIENT ((uint16_t)-1)
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
struct zcache_client { struct zcache_client {
struct tmem_pool *tmem_pools[MAX_POOLS_PER_CLIENT]; struct idr tmem_pools;
struct zs_pool *zspool; struct zs_pool *zspool;
bool allocated; bool allocated;
atomic_t refcount; atomic_t refcount;
...@@ -949,11 +948,9 @@ static struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid) ...@@ -949,11 +948,9 @@ static struct tmem_pool *zcache_get_pool_by_id(uint16_t cli_id, uint16_t poolid)
goto out; goto out;
atomic_inc(&cli->refcount); atomic_inc(&cli->refcount);
} }
if (poolid < MAX_POOLS_PER_CLIENT) { pool = idr_find(&cli->tmem_pools, poolid);
pool = cli->tmem_pools[poolid]; if (pool != NULL)
if (pool != NULL) atomic_inc(&pool->refcount);
atomic_inc(&pool->refcount);
}
out: out:
return pool; return pool;
} }
...@@ -987,6 +984,7 @@ int zcache_new_client(uint16_t cli_id) ...@@ -987,6 +984,7 @@ int zcache_new_client(uint16_t cli_id)
cli->zspool = zs_create_pool("zcache", ZCACHE_GFP_MASK); cli->zspool = zs_create_pool("zcache", ZCACHE_GFP_MASK);
if (cli->zspool == NULL) if (cli->zspool == NULL)
goto out; goto out;
idr_init(&cli->tmem_pools);
#endif #endif
ret = 0; ret = 0;
out: out:
...@@ -1673,10 +1671,10 @@ static int zcache_destroy_pool(int cli_id, int pool_id) ...@@ -1673,10 +1671,10 @@ static int zcache_destroy_pool(int cli_id, int pool_id)
if (cli == NULL) if (cli == NULL)
goto out; goto out;
atomic_inc(&cli->refcount); atomic_inc(&cli->refcount);
pool = cli->tmem_pools[pool_id]; pool = idr_find(&cli->tmem_pools, pool_id);
if (pool == NULL) if (pool == NULL)
goto out; goto out;
cli->tmem_pools[pool_id] = NULL; idr_remove(&cli->tmem_pools, pool_id);
/* wait for pool activity on other cpus to quiesce */ /* wait for pool activity on other cpus to quiesce */
while (atomic_read(&pool->refcount) != 0) while (atomic_read(&pool->refcount) != 0)
; ;
...@@ -1696,6 +1694,7 @@ static int zcache_new_pool(uint16_t cli_id, uint32_t flags) ...@@ -1696,6 +1694,7 @@ static int zcache_new_pool(uint16_t cli_id, uint32_t flags)
int poolid = -1; int poolid = -1;
struct tmem_pool *pool; struct tmem_pool *pool;
struct zcache_client *cli = NULL; struct zcache_client *cli = NULL;
int r;
if (cli_id == LOCAL_CLIENT) if (cli_id == LOCAL_CLIENT)
cli = &zcache_host; cli = &zcache_host;
...@@ -1710,20 +1709,25 @@ static int zcache_new_pool(uint16_t cli_id, uint32_t flags) ...@@ -1710,20 +1709,25 @@ static int zcache_new_pool(uint16_t cli_id, uint32_t flags)
goto out; goto out;
} }
for (poolid = 0; poolid < MAX_POOLS_PER_CLIENT; poolid++) do {
if (cli->tmem_pools[poolid] == NULL) r = idr_pre_get(&cli->tmem_pools, GFP_ATOMIC);
break; if (r != 1) {
if (poolid >= MAX_POOLS_PER_CLIENT) { kfree(pool);
pr_info("zcache: pool creation failed: max exceeded\n"); 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); kfree(pool);
poolid = -1;
goto out; goto out;
} }
atomic_set(&pool->refcount, 0); atomic_set(&pool->refcount, 0);
pool->client = cli; pool->client = cli;
pool->pool_id = poolid; pool->pool_id = poolid;
tmem_new_pool(pool, flags); tmem_new_pool(pool, flags);
cli->tmem_pools[poolid] = pool;
pr_info("zcache: created %s tmem pool, id=%d, client=%d\n", pr_info("zcache: created %s tmem pool, id=%d, client=%d\n",
flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral", flags & TMEM_POOL_PERSIST ? "persistent" : "ephemeral",
poolid, cli_id); poolid, cli_id);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment