[PATCH v12 1/6] memarea: introduce memarea library

fengchengwen fengchengwen at huawei.com
Fri Jan 20 09:20:56 CET 2023


Hi Morten,

On 2023/1/15 15:58, Morten Brørup wrote:
>> From: Chengwen Feng [mailto:fengchengwen at huawei.com]
>> Sent: Saturday, 14 January 2023 12.50
>>
>> The memarea library is an allocator of variable-size object which based
>> on a memory region.
>>
>> This patch provides rte_memarea_create() and rte_memarea_destroy() API.
>>
>> Signed-off-by: Chengwen Feng <fengchengwen at huawei.com>
>> Reviewed-by: Dongdong Liu <liudongdong3 at huawei.com>
>> ---
> 
> [...]
> 
>> +struct memarea_obj {
>> +	TAILQ_ENTRY(memarea_obj) obj_node;
>> +	TAILQ_ENTRY(memarea_obj) free_node;
>> +	size_t                   size;
>> +	size_t                   alloc_size;
>> +	uint32_t                 magic;
>> +};
> 
> The magic cookie is for debug purposes only, and should be enclosed by #ifdef RTE_LIBRTE_MEMAREA_DEBUG, like in the mempool library [1].

In the mempool the cookie mechanism is under debug macro, the main reason should be performance considerations.

And community recommends that compilation macro be used as little as possible.

So I think we could add the following new API like:

/*
 * Enable audit in alloc/free/audit.
 */
rte_memarea_audit_enable(struct rte_memarea *ma)

/*
 * Disable audit in alloc/free/audit.
 */
rte_memarea_audit_disable(struct rte_memarea *ma)

/*
 * if ptr is NULL, then audit the all objects.
 * else, only audit the object which the ptr pointers.
 * if audit fail, will return an error code, and the error log will emit.
 *
 * The audit is performed only when the audit function is enabled for the memarea.
 */
int rte_memarea_audit_object(struct rte_memarea *ma, void *ptr)


So for an application, it can invoke rte_memarea_audit() in its code without macro control.
If it considers that memory corruption may occur in a certain scenario, the audit function can be enabled, so could find it by error log or retcode.

This method causes slight performance loss. But it's guaranteed that there's no need to recompile, and a binary can be done.

> 
> [1]: https://elixir.bootlin.com/dpdk/latest/source/lib/mempool/rte_mempool.h#L154
> 
> With that added:
> 
> Series-acked-by: Morten Brørup <mb at smartsharesystems.com>
> 
> 
> .
> 


More information about the dev mailing list