From 621f96f7aa5dd4315f8783cab0f6745e7e84d076 Mon Sep 17 00:00:00 2001 From: GangCao Date: Mon, 7 Nov 2016 03:19:31 -0500 Subject: [PATCH] util/bit_array: use spdk_realloc for process sharing Change-Id: I8fe49388e7bec9306474f27de7c17e767dfa19e8 Signed-off-by: GangCao --- include/spdk/env.h | 7 +++++++ lib/env/env.c | 10 ++++++++++ lib/util/bit_array.c | 5 +++-- test/lib/nvme/unit/test_env.c | 6 ++++++ test/lib/util/bit_array/bit_array_ut.c | 12 ++++++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) diff --git a/include/spdk/env.h b/include/spdk/env.h index 6a68565a4..a9a65acf8 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -63,6 +63,13 @@ spdk_malloc(size_t size, size_t align, uint64_t *phys_addr); void * spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr); +/** + * Resize the allocated and pinned memory buffer with the given + * new size and alignment. Existing contents are preserved. + */ +void * +spdk_realloc(void *buf, size_t size, size_t align, uint64_t *phys_addr); + /** * Free a memory buffer previously allocated with spdk_zmalloc. * This call is never made from the performance path. diff --git a/lib/env/env.c b/lib/env/env.c index d27588698..5fbf49bd9 100644 --- a/lib/env/env.c +++ b/lib/env/env.c @@ -63,6 +63,16 @@ spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr) return buf; } +void * +spdk_realloc(void *buf, size_t size, size_t align, uint64_t *phys_addr) +{ + void *new_buf = rte_realloc(buf, size, align); + if (new_buf && phys_addr) { + *phys_addr = rte_malloc_virt2phy(new_buf); + } + return new_buf; +} + void spdk_free(void *buf) { diff --git a/lib/util/bit_array.c b/lib/util/bit_array.c index de1b2efdd..6019a8544 100644 --- a/lib/util/bit_array.c +++ b/lib/util/bit_array.c @@ -32,6 +32,7 @@ */ #include "spdk/bit_array.h" +#include "spdk/env.h" #include #include @@ -77,7 +78,7 @@ spdk_bit_array_free(struct spdk_bit_array **bap) ba = *bap; *bap = NULL; - free(ba); + spdk_free(ba); } static inline uint32_t @@ -113,7 +114,7 @@ spdk_bit_array_resize(struct spdk_bit_array **bap, uint32_t num_bits) */ new_size += SPDK_BIT_ARRAY_WORD_BYTES; - new_ba = (struct spdk_bit_array *)realloc(*bap, new_size); + new_ba = (struct spdk_bit_array *)spdk_realloc(*bap, new_size, 64, NULL); if (!new_ba) { return -ENOMEM; } diff --git a/test/lib/nvme/unit/test_env.c b/test/lib/nvme/unit/test_env.c index 222c2e855..a28f471db 100644 --- a/test/lib/nvme/unit/test_env.c +++ b/test/lib/nvme/unit/test_env.c @@ -51,6 +51,12 @@ spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr) return buf; } +void * +spdk_realloc(void *buf, size_t size, size_t align, uint64_t *phys_addr) +{ + return realloc(buf, size); +} + void spdk_free(void *buf) { free(buf); diff --git a/test/lib/util/bit_array/bit_array_ut.c b/test/lib/util/bit_array/bit_array_ut.c index 6949a400d..b89cf2626 100644 --- a/test/lib/util/bit_array/bit_array_ut.c +++ b/test/lib/util/bit_array/bit_array_ut.c @@ -37,6 +37,18 @@ #include "bit_array.c" +void * +spdk_realloc(void *buf, size_t size, size_t align, uint64_t *phys_addr) +{ + return realloc(buf, size); +} + +void +spdk_free(void *buf) +{ + free(buf); +} + static void test_1bit(void) {