blobfs: cleanup cache pool

Keep a global counter of the number of opened
blobfs instances.  Allocate the cache pool when the
first instance is opened, and free the cache pool
when the last instance closes.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I99db2b587b738badcd2a54c9f5dc6ec8370ce22c

Reviewed-on: https://review.gerrithub.io/362606
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2017-05-25 11:55:11 -07:00 committed by Ben Walker
parent a8e1295d4b
commit e045a02ca0

View File

@ -54,6 +54,8 @@
static uint64_t g_fs_cache_size = BLOBFS_CACHE_SIZE;
static struct spdk_mempool *g_cache_pool;
static TAILQ_HEAD(, spdk_file) g_caches;
static int g_fs_count = 0;
static pthread_mutex_t g_cache_init_lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_spinlock_t g_caches_lock;
static void
@ -190,9 +192,7 @@ static void cache_free_buffers(struct spdk_file *file);
static void
__initialize_cache(void)
{
if (g_cache_pool != NULL) {
return;
}
assert(g_cache_pool == NULL);
g_cache_pool = spdk_mempool_create("spdk_fs_cache",
g_fs_cache_size / CACHE_BUFFER_SIZE,
@ -201,6 +201,15 @@ __initialize_cache(void)
pthread_spin_init(&g_caches_lock, 0);
}
static void
__free_cache(void)
{
assert(g_cache_pool != NULL);
spdk_mempool_free(g_cache_pool);
g_cache_pool = NULL;
}
static uint64_t
__file_get_blob_size(struct spdk_file *file)
{
@ -332,6 +341,13 @@ common_fs_bs_init(struct spdk_filesystem *fs, struct spdk_blob_store *bs)
fs->sync_target.sync_fs_channel->bs_channel = spdk_bs_alloc_io_channel(fs->bs,
SPDK_IO_PRIORITY_DEFAULT);
fs->sync_target.sync_fs_channel->send_request = __send_request_direct;
pthread_mutex_lock(&g_cache_init_lock);
if (g_fs_count == 0) {
__initialize_cache();
}
g_fs_count++;
pthread_mutex_unlock(&g_cache_init_lock);
}
static void
@ -382,8 +398,6 @@ fs_alloc(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn)
spdk_io_device_register(&fs->io_target, _spdk_fs_io_channel_create, _spdk_fs_channel_destroy,
sizeof(struct spdk_fs_channel));
__initialize_cache();
return fs;
}
@ -542,6 +556,13 @@ unload_cb(void *ctx, int bserrno)
struct spdk_fs_cb_args *args = &req->args;
struct spdk_filesystem *fs = args->fs;
pthread_mutex_lock(&g_cache_init_lock);
g_fs_count--;
if (g_fs_count == 0) {
__free_cache();
}
pthread_mutex_unlock(&g_cache_init_lock);
args->fn.fs_op(args->arg, bserrno);
free(req);