Commit 621f96f7 authored by GangCao's avatar GangCao Committed by Daniel Verkamp
Browse files

util/bit_array: use spdk_realloc for process sharing



Change-Id: I8fe49388e7bec9306474f27de7c17e767dfa19e8
Signed-off-by: default avatarGangCao <gang.cao@intel.com>
parent 84b7670d
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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.
+10 −0
Original line number Diff line number Diff line
@@ -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)
{
+3 −2
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@
 */

#include "spdk/bit_array.h"
#include "spdk/env.h"

#include <assert.h>
#include <errno.h>
@@ -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;
	}
+6 −0
Original line number Diff line number Diff line
@@ -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);
+12 −0
Original line number Diff line number Diff line
@@ -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)
{