diff --git a/include/spdk/env.h b/include/spdk/env.h index 70dce6322..8c0fa8b79 100644 --- a/include/spdk/env.h +++ b/include/spdk/env.h @@ -80,12 +80,24 @@ void spdk_env_init(const struct spdk_env_opts *opts); */ void *spdk_malloc(size_t size, size_t align, uint64_t *phys_addr); +/** + * Allocate a pinned, physically contiguous memory buffer with the + * given size, alignment and socket id. + */ +void *spdk_malloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id); + /** * Allocate a pinned, physically contiguous memory buffer with the * given size and alignment. The buffer will be zeroed. */ void *spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr); +/** + * Allocate a pinned, physically contiguous memory buffer with the + * given size, alignment and socket id. The buffer will be zeroed. + */ +void *spdk_zmalloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id); + /** * Resize the allocated and pinned memory buffer with the given * new size and alignment. Existing contents are preserved. diff --git a/lib/env_dpdk/env.c b/lib/env_dpdk/env.c index 6c63b92db..eaaeaf1de 100644 --- a/lib/env_dpdk/env.c +++ b/lib/env_dpdk/env.c @@ -44,9 +44,9 @@ #include void * -spdk_malloc(size_t size, size_t align, uint64_t *phys_addr) +spdk_malloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id) { - void *buf = rte_malloc(NULL, size, align); + void *buf = rte_malloc_socket(NULL, size, align, socket_id); if (buf && phys_addr) { *phys_addr = rte_malloc_virt2phy(buf); } @@ -54,15 +54,27 @@ 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) +spdk_zmalloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id) { - void *buf = spdk_malloc(size, align, phys_addr); + void *buf = spdk_malloc_socket(size, align, phys_addr, socket_id); if (buf) { memset(buf, 0, size); } return buf; } +void * +spdk_malloc(size_t size, size_t align, uint64_t *phys_addr) +{ + return spdk_malloc_socket(size, align, phys_addr, SPDK_ENV_SOCKET_ID_ANY); +} + +void * +spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr) +{ + return spdk_zmalloc_socket(size, align, phys_addr, SPDK_ENV_SOCKET_ID_ANY); +} + void * spdk_realloc(void *buf, size_t size, size_t align, uint64_t *phys_addr) { diff --git a/test/lib/test_env.c b/test/lib/test_env.c index 8b1a1b59c..02358a094 100644 --- a/test/lib/test_env.c +++ b/test/lib/test_env.c @@ -62,6 +62,18 @@ spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr) return buf; } +void * +spdk_malloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id) +{ + return spdk_malloc(size, align, phys_addr); +} + +void * +spdk_zmalloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id) +{ + return spdk_zmalloc(size, align, phys_addr); +} + void * spdk_realloc(void *buf, size_t size, size_t align, uint64_t *phys_addr) {