DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Mattias Rönnblom" <hofors@lysator.liu.se>
To: "Mattias Rönnblom" <hofors@lysator.liu.se>,
	"dev@dpdk.org" <dev@dpdk.org>
Cc: "Mattias Rönnblom" <mattias.ronnblom@ericsson.com>
Subject: rte_malloc() and alignment
Date: Tue, 6 Feb 2024 17:17:31 +0100	[thread overview]
Message-ID: <cde568b2-ba57-4e0f-a84a-4c1ba8ba57b5@lysator.liu.se> (raw)

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.

             reply	other threads:[~2024-02-06 16:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06 16:17 Mattias Rönnblom [this message]
2024-02-07  4:46 ` Stephen Hemminger
2024-02-07  8:05   ` Dmitry Kozlyuk
2024-02-07  8:23   ` Mattias Rönnblom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cde568b2-ba57-4e0f-a84a-4c1ba8ba57b5@lysator.liu.se \
    --to=hofors@lysator.liu.se \
    --cc=dev@dpdk.org \
    --cc=mattias.ronnblom@ericsson.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).