From 97f3104bc7b8f305409105d19b7e6d6d87d56da5 Mon Sep 17 00:00:00 2001 From: Cunyin Chang Date: Mon, 23 Oct 2017 13:45:26 +0800 Subject: [PATCH] blobfs: Add conf parse for blobfs. This patch make the cache buffer shift of blobfs configurable. We can configure the cache buffer shift according workload, it will help to improve the performance. Change-Id: Ied1c2e5d6fd9eaa7aa0759c03c654fcf2e77aa23 Signed-off-by: Cunyin Chang Reviewed-on: https://review.gerrithub.io/383381 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Ziye Yang Reviewed-by: Ben Walker --- lib/blobfs/blobfs.c | 22 +++++++++++++++++++ lib/blobfs/tree.c | 2 ++ lib/blobfs/tree.h | 10 +++++---- .../blobfs/blobfs_async_ut/blobfs_async_ut.c | 14 ++++++++++++ .../blobfs/blobfs_sync_ut/blobfs_sync_ut.c | 14 ++++++++++++ 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/lib/blobfs/blobfs.c b/lib/blobfs/blobfs.c index fad9b3cc3..e58f202fe 100644 --- a/lib/blobfs/blobfs.c +++ b/lib/blobfs/blobfs.c @@ -34,6 +34,7 @@ #include "spdk/stdinc.h" #include "spdk/blobfs.h" +#include "spdk/conf.h" #include "blobfs_internal.h" #include "spdk/queue.h" @@ -401,6 +402,23 @@ init_cb(void *ctx, struct spdk_blob_store *bs, int bserrno) free_fs_request(req); } +static void +fs_conf_parse(void) +{ + struct spdk_conf_section *sp; + + sp = spdk_conf_find_section(NULL, "Blobfs"); + if (sp == NULL) { + g_fs_cache_buffer_shift = CACHE_BUFFER_SHIFT_DEFAULT; + return; + } + + g_fs_cache_buffer_shift = spdk_conf_section_get_intval(sp, "CacheBufferShift"); + if (g_fs_cache_buffer_shift <= 0) { + g_fs_cache_buffer_shift = CACHE_BUFFER_SHIFT_DEFAULT; + } +} + static struct spdk_filesystem * fs_alloc(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn) { @@ -449,6 +467,8 @@ spdk_fs_init(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn, return; } + fs_conf_parse(); + req = alloc_fs_request(fs->md_target.md_fs_channel); if (req == NULL) { spdk_put_io_channel(fs->md_target.md_io_channel); @@ -657,6 +677,8 @@ spdk_fs_load(struct spdk_bs_dev *dev, fs_send_request_fn send_request_fn, return; } + fs_conf_parse(); + req = alloc_fs_request(fs->md_target.md_fs_channel); if (req == NULL) { spdk_put_io_channel(fs->md_target.md_io_channel); diff --git a/lib/blobfs/tree.c b/lib/blobfs/tree.c index cd841284f..ffb6bce60 100644 --- a/lib/blobfs/tree.c +++ b/lib/blobfs/tree.c @@ -41,6 +41,8 @@ #include "spdk/env.h" #include "spdk_internal/log.h" +uint32_t g_fs_cache_buffer_shift = CACHE_BUFFER_SHIFT_DEFAULT; + struct cache_buffer * spdk_tree_find_buffer(struct cache_tree *tree, uint64_t offset) { diff --git a/lib/blobfs/tree.h b/lib/blobfs/tree.h index 0a9ba62a3..9bde83c65 100644 --- a/lib/blobfs/tree.h +++ b/lib/blobfs/tree.h @@ -43,14 +43,16 @@ struct cache_buffer { bool in_progress; }; -#define CACHE_BUFFER_SHIFT (18) -#define CACHE_BUFFER_SIZE (1U << CACHE_BUFFER_SHIFT) +extern uint32_t g_fs_cache_buffer_shift; + +#define CACHE_BUFFER_SHIFT_DEFAULT 18 +#define CACHE_BUFFER_SIZE (1U << g_fs_cache_buffer_shift) #define NEXT_CACHE_BUFFER_OFFSET(offset) \ - (((offset + CACHE_BUFFER_SIZE) >> CACHE_BUFFER_SHIFT) << CACHE_BUFFER_SHIFT) + (((offset + CACHE_BUFFER_SIZE) >> g_fs_cache_buffer_shift) << g_fs_cache_buffer_shift) #define CACHE_TREE_SHIFT 6 #define CACHE_TREE_WIDTH (1U << CACHE_TREE_SHIFT) -#define CACHE_TREE_LEVEL_SHIFT(level) (CACHE_BUFFER_SHIFT + (level) * CACHE_TREE_SHIFT) +#define CACHE_TREE_LEVEL_SHIFT(level) (g_fs_cache_buffer_shift + (level) * CACHE_TREE_SHIFT) #define CACHE_TREE_LEVEL_SIZE(level) (1ULL << CACHE_TREE_LEVEL_SHIFT(level)) #define CACHE_TREE_LEVEL_MASK(level) (CACHE_TREE_LEVEL_SIZE(level) - 1) #define CACHE_TREE_INDEX(level, offset) ((offset >> CACHE_TREE_LEVEL_SHIFT(level)) & (CACHE_TREE_WIDTH - 1)) diff --git a/test/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c b/test/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c index 37da16985..f81d91beb 100644 --- a/test/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c +++ b/test/lib/blobfs/blobfs_async_ut/blobfs_async_ut.c @@ -47,6 +47,20 @@ struct spdk_filesystem *g_fs; struct spdk_file *g_file; int g_fserrno; +/* Return NULL to test hardcoded defaults. */ +struct spdk_conf_section * +spdk_conf_find_section(struct spdk_conf *cp, const char *name) +{ + return NULL; +} + +/* Return -1 to test hardcoded defaults. */ +int +spdk_conf_section_get_intval(struct spdk_conf_section *sp, const char *key) +{ + return -1; +} + static void _fs_send_msg(spdk_thread_fn fn, void *ctx, void *thread_ctx) { diff --git a/test/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c b/test/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c index b7c707b74..08ec2b447 100644 --- a/test/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c +++ b/test/lib/blobfs/blobfs_sync_ut/blobfs_sync_ut.c @@ -49,6 +49,20 @@ struct spdk_filesystem *g_fs; struct spdk_file *g_file; int g_fserrno; +/* Return NULL to test hardcoded defaults. */ +struct spdk_conf_section * +spdk_conf_find_section(struct spdk_conf *cp, const char *name) +{ + return NULL; +} + +/* Return -1 to test hardcoded defaults. */ +int +spdk_conf_section_get_intval(struct spdk_conf_section *sp, const char *key) +{ + return -1; +} + static void _fs_send_msg(spdk_thread_fn fn, void *ctx, void *thread_ctx) {