* @note Memory area must not contain any allocated elements to allow its
* removal from the heap
*
+ * @note All other processes must detach from the memory chunk prior to it being
+ * removed from the heap.
+ *
* @param heap_name
* Name of the heap to remove memory from
* @param va_addr
int __rte_experimental
rte_malloc_heap_memory_attach(const char *heap_name, void *va_addr, size_t len);
+/**
+ * Detach from a chunk of external memory in secondary process.
+ *
+ * @note This function must be called in before any attempt is made to remove
+ * external memory from the heap in another process. This function does *not*
+ * need to be called if a call to ``rte_malloc_heap_memory_remove`` will be
+ * called in current process.
+ *
+ * @param heap_name
+ * Heap name to which this chunk of memory belongs
+ * @param va_addr
+ * Start address of memory chunk to attach to
+ * @param len
+ * Length of memory chunk to attach to
+ * @return
+ * 0 on successful detach
+ * -1 on unsuccessful detach, with rte_errno set to indicate cause for error:
+ * EINVAL - one of the parameters was invalid
+ * EPERM - attempted to detach memory from a reserved heap
+ * ENOENT - heap or memory chunk was not found
+ */
+int __rte_experimental
+rte_malloc_heap_memory_detach(const char *heap_name, void *va_addr, size_t len);
+
/**
* Creates a new empty malloc heap with a specified name.
*
void *va_addr;
size_t len;
int result;
+ bool attach;
};
static int
-attach_mem_walk(const struct rte_memseg_list *msl, void *arg)
+sync_mem_walk(const struct rte_memseg_list *msl, void *arg)
{
struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
struct sync_mem_walk_arg *wa = arg;
msl_idx = msl - mcfg->memsegs;
found_msl = &mcfg->memsegs[msl_idx];
- ret = rte_fbarray_attach(&found_msl->memseg_arr);
+ if (wa->attach)
+ ret = rte_fbarray_attach(&found_msl->memseg_arr);
+ else
+ ret = rte_fbarray_detach(&found_msl->memseg_arr);
if (ret < 0)
wa->result = -rte_errno;
return 0;
}
-int
-rte_malloc_heap_memory_attach(const char *heap_name, void *va_addr, size_t len)
+static int
+sync_memory(const char *heap_name, void *va_addr, size_t len, bool attach)
{
struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
struct malloc_heap *heap = NULL;
ret = -1;
goto unlock;
}
- /* we shouldn't be able to attach to internal heaps */
+ /* we shouldn't be able to sync to internal heaps */
if (heap->socket_id < RTE_MAX_NUMA_NODES) {
rte_errno = EPERM;
ret = -1;
goto unlock;
}
- /* find corresponding memseg list to attach to */
+ /* find corresponding memseg list to sync to */
wa.va_addr = va_addr;
wa.len = len;
wa.result = -ENOENT; /* fail unless explicitly told to succeed */
+ wa.attach = attach;
/* we're already holding a read lock */
- rte_memseg_list_walk_thread_unsafe(attach_mem_walk, &wa);
+ rte_memseg_list_walk_thread_unsafe(sync_mem_walk, &wa);
if (wa.result < 0) {
rte_errno = -wa.result;
return ret;
}
+int
+rte_malloc_heap_memory_attach(const char *heap_name, void *va_addr, size_t len)
+{
+ return sync_memory(heap_name, va_addr, len, true);
+}
+
+int
+rte_malloc_heap_memory_detach(const char *heap_name, void *va_addr, size_t len)
+{
+ return sync_memory(heap_name, va_addr, len, false);
+}
+
int
rte_malloc_heap_create(const char *heap_name)
{