[dpdk-dev] How *rte_zmalloc_socket* ensure that the memory is zero'd ?

Stephen Hemminger stephen at networkplumber.org
Wed Jul 17 06:51:06 CEST 2019


On Wed, 17 Jul 2019 02:26:57 GMT
He Peng <xnhp0320 at icloud.com> wrote:

> Hi,
> 
> In file dpdk/lib/librte_eal/common/rte_malloc.c:
> 
> /*
> * Allocate memory on default heap.
> */
> void *
> rte_malloc(const char *type, size_t size, unsigned align)
> {
>   return rte_malloc_socket(type, size, align, SOCKET_ID_ANY);
> }
> 
> /*
> * Allocate zero'd memory on specified heap.
> */
> void *
> rte_zmalloc_socket(const char *type, size_t size, unsigned align, int socket)
> {
>   return rte_malloc_socket(type, size, align, socket);
> }
> 
> Looks like the *rte_malloc* and *rte_zmalloc_socket* is the same, then, how the latter function ensure the memory allocated by is zeroed?

This is done because touching the memory on free is faster than cache cold memory during allocation.

If you look at recent DPDK the behavior changes slightly if MALLOC_DEBUG is enabled.
If DEBUG is enabled freed memory is clobbered with a 0x6b so that any buggy program
is likely to crash when using freed memory. 


More information about the dev mailing list