Skip to contentSkip to conversation

rte_zmalloc() returning non-zeroed memory on FreeBSD

dpdk-users Thomas Monjalon 3 participants 4 messages Aug 11, 2016 – Aug 16, 2016 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

Hi,

2016-08-10 23:30, Verkamp, Daniel:

Quoted 9 lines

It seems that with DPDK 16.07, rte_zmalloc() and related functions no longer return zeroed memory reliably on FreeBSD.

I notice that commit b78c9175118f7d61022ddc5c62ce54a1bd73cea5 ("mem: do not zero out memory on zmalloc") removed the explicit memset() that used to ensure the buffer was zeroed; its log message says:

"Zeroing out memory on rte_zmalloc_socket is not required anymore since all allocated memory is already zeroed."

On Linux, the memory is zeroed by the kernel.
Then the zero value is maintained in the rte_malloc pool by rte_free.

Quoted 6 lines

However, I don't see how this is guaranteed (at least for FreeBSD), and it is not true in practice. I've attached a minimized reproducer program - running it twice in a row fails reliably for me.

Is there a missing step in FreeBSD, or is it a more general problem for other platforms?

I guess the initial value from the kernel has been verified only on Linux. We could re-add a memset for FreeBSD.

#2 lore raw
Quoted 33 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Thomas Monjalon
Sent: Thursday, August 11, 2016 12:05 AM
To: [email protected]; [email protected]; Gonzalez Monroy, Sergio; Richardson, Bruce
Cc: Verkamp, Daniel
Subject: Re: [dpdk-dev] [dpdk-users] rte_zmalloc() returning non-zeroed memory on FreeBSD

Hi,

2016-08-10 23:30, Verkamp, Daniel:

Quoted 4 lines

It seems that with DPDK 16.07, rte_zmalloc() and related functions no longer return zeroed memory reliably on FreeBSD.

I notice that commit b78c9175118f7d61022ddc5c62ce54a1bd73cea5 ("mem:

do

Quoted 1 line

not zero out memory on zmalloc") removed the explicit memset() that

used

Quoted 4 lines

to ensure the buffer was zeroed; its log message says:

"Zeroing out memory on rte_zmalloc_socket is not required anymore since all allocated memory is already zeroed."

On Linux, the memory is zeroed by the kernel.
Then the zero value is maintained in the rte_malloc pool by rte_free.

Quoted 4 lines

However, I don't see how this is guaranteed (at least for FreeBSD), and it is not true in practice. I've attached a minimized reproducer program - running it twice in a row fails reliably for me.

Quoted 5 lines
Quoted 2 lines

Is there a missing step in FreeBSD, or is it a more general problem for other platforms?

I guess the initial value from the kernel has been verified only on Linux. We could re-add a memset for FreeBSD.

The problem is that the FreeBSD contigmem driver does not re-zero the huge pages each time they are mmap'd - they are only zeroed when contigmem initially loads. I will push a patch for this shortly.

#3 lore raw
Quoted 31 lines · James R
Quoted 31 lines

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Thomas Monjalon
Sent: Thursday, August 11, 2016 12:05 AM
To: [email protected]; [email protected]; Gonzalez Monroy, Sergio; Richardson, Bruce
Cc: Verkamp, Daniel
Subject: Re: [dpdk-dev] [dpdk-users] rte_zmalloc() returning non-zeroed memory on FreeBSD

Hi,

2016-08-10 23:30, Verkamp, Daniel:

Quoted 4 lines

It seems that with DPDK 16.07, rte_zmalloc() and related functions no longer return zeroed memory reliably on FreeBSD.

I notice that commit b78c9175118f7d61022ddc5c62ce54a1bd73cea5 ("mem:

do

Quoted 1 line

not zero out memory on zmalloc") removed the explicit memset() that

used

Quoted 4 lines

to ensure the buffer was zeroed; its log message says:

"Zeroing out memory on rte_zmalloc_socket is not required anymore since all allocated memory is already zeroed."

On Linux, the memory is zeroed by the kernel.
Then the zero value is maintained in the rte_malloc pool by rte_free.

Quoted 4 lines

However, I don't see how this is guaranteed (at least for FreeBSD), and it is not true in practice. I've attached a minimized reproducer program - running it twice in a row fails reliably for me.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Is there a missing step in FreeBSD, or is it a more general problem for other platforms?

I guess the initial value from the kernel has been verified only on Linux. We could re-add a memset for FreeBSD.

The problem is that the FreeBSD contigmem driver does not re-zero the huge pages each time they are mmap'd - they are only zeroed when contigmem initially loads. I will push a patch for this shortly.

So that is the case where we run the app more than once, right? I missed that, I only ran it once.

Sergio

#4 lore raw
Quoted 13 lines

-----Original Message-----
From: Gonzalez Monroy, Sergio
Sent: Tuesday, August 16, 2016 12:37 AM
To: Harris, James R; Thomas Monjalon; [email protected]; [email protected]; Richardson, Bruce
Cc: Verkamp, Daniel
Subject: Re: [dpdk-dev] [dpdk-users] rte_zmalloc() returning non-zeroed memory on FreeBSD

Quoted 1 line · James R

<snip>

Quoted 7 lines
Quoted 1 line

The problem is that the FreeBSD contigmem driver does not re-zero the

huge

Quoted 2 lines

pages each time they are mmap'd - they are only zeroed when contigmem initially loads. I will push a patch for this shortly.

So that is the case where we run the app more than once, right? I missed that, I only ran it once.

Correct - it works OK the first time. The problem only occurs if you run the app more than once (unless you unload and reload contigmem before running the app a second time).

-Jim