DPDK patches and discussions
 help / color / mirror / Atom feed
* rte_malloc() and alignment
@ 2024-02-06 16:17 Mattias Rönnblom
  2024-02-07  4:46 ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Mattias Rönnblom @ 2024-02-06 16:17 UTC (permalink / raw)
  To: Mattias Rönnblom, dev; +Cc: Mattias Rönnblom

The rte_malloc() API documentation has the following to say about the 
align parameter:

"If 0, the return is a pointer that is suitably aligned for any kind of 
variable (in the same manner as malloc()). Otherwise, the return is a 
pointer that is a multiple of align. In this case, it must be a power of 
two. (Minimum alignment is the cacheline size, i.e. 64-bytes)"

After reading this, one might be left with the impression that the 
parenthesis refers to only the "otherwise" (non-zero-align) case, since 
surely, cache line alignment should be sufficient for any kind of 
variable and it semantics would be "in the same manner as malloc()".

However, in the actual RTE malloc implementation, any align parameter 
value less than RTE_CACHE_LINE_SIZE results in an alignment of 
RTE_CACHE_LINE_SIZE, unless I'm missing something.

Is there any conceivable scenario where passing a non-zero align 
parameter is useful?

Would it be an improvement to rephrase the documentation to:

"The alignment of the allocated memory meets all of the following criteria:
1) able to hold any built-in type.
2) be at least as large as the align parameter.
3) be at least as large as RTE_CACHE_LINE_SIZE.

The align parameter must be a power-of-2 or 0.
"

...so it actually describes what is implemented? And also adds the 
theoretical (?) case of a built-in type requiring > RTE_CACHE_LINE_SIZE 
amount of alignment.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-02-07  8:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-06 16:17 rte_malloc() and alignment Mattias Rönnblom
2024-02-07  4:46 ` Stephen Hemminger
2024-02-07  8:05   ` Dmitry Kozlyuk
2024-02-07  8:23   ` Mattias Rönnblom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).