Skip to content

Add CachePadded variants with capped max alignment#1118

Open
Jules-Bertholet wants to merge 3 commits intocrossbeam-rs:masterfrom
Jules-Bertholet:cache-padded-max
Open

Add CachePadded variants with capped max alignment#1118
Jules-Bertholet wants to merge 3 commits intocrossbeam-rs:masterfrom
Jules-Bertholet:cache-padded-max

Conversation

@Jules-Bertholet
Copy link
Copy Markdown
Contributor

@Jules-Bertholet Jules-Bertholet commented Jun 10, 2024

These are useful for ensuring that values cross as few cache lines as possible, without restricting whether they can share one.

These are useful for ensuring that values don't *cross* a cache line,
without restricting whether they can *share* one.
@taiki-e
Copy link
Copy Markdown
Member

taiki-e commented Jun 10, 2024

ensuring that values don't cross a cache line

Given how we set our aarch64 and x86_64's alignments, I don't think this implementation is sufficient.

I'm also interested in what concrete cases this would be useful.

@Jules-Bertholet
Copy link
Copy Markdown
Contributor Author

Jules-Bertholet commented Jun 10, 2024

My phrasing of "don't cross a cache line" was suboptimal; I've changed it to "cross as few cache lines as possible", which is what I really want. My use case is that I have a large, but not too large, value (a lookup table), and I want it to take up as few cache lines as possible.

@Jules-Bertholet
Copy link
Copy Markdown
Contributor Author

Given how we set our aarch64 and x86_64's alignments, I don't think this implementation is sufficient.

Could you elaborate?

@taiki-e
Copy link
Copy Markdown
Member

taiki-e commented Feb 14, 2026

Given how we set our aarch64 and x86_64's alignments, I don't think this implementation is sufficient.

Could you elaborate?

On some CPUs, cache line is 64-byte, and on some, it is 128-byte. We choice 128-byte to avoid false sharing in either case, but if you wish to use it for a purpose other than avoiding false sharing, the opposite choice may be necessary. (By the way, on AArch64, there is CPU with 256-byte cache line (A64FX), but we ignore it at this time since it is very rare.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants