From: "Gary Guo" <gary@garyguo.net>
To: "Alice Ryhl" <aliceryhl@google.com>, "Gary Guo" <gary@garyguo.net>
Cc: "Alexandre Courbot" <acourbot@nvidia.com>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org
Subject: Re: [PATCH] rust: add `CacheAligned` for easy cache line alignment of values
Date: Wed, 28 Jan 2026 15:05:37 +0000 [thread overview]
Message-ID: <DG0BD0NGT1HH.1PVFYFO0CCT6N@garyguo.net> (raw)
In-Reply-To: <aXohLx77gHe9b_oJ@google.com>
On Wed Jan 28, 2026 at 2:46 PM GMT, Alice Ryhl wrote:
> On Wed, Jan 28, 2026 at 02:41:05PM +0000, Gary Guo wrote:
>> On Wed Jan 28, 2026 at 2:25 PM GMT, Alexandre Courbot wrote:
>> > On Wed Jan 28, 2026 at 11:05 PM JST, Andreas Hindborg wrote:
>> > While 64 bytes is the most common cache line size, AFAIK this is not
>> > a universal value? Can we expose and use `L1_CACHE_BYTES` here?
>>
>> On all archs that we do support today, I think the value is always 64. However
>> it'd worth putting a FIXME or TODO (or assertion, maybe?) in case new archs gets
>> addded where this isn't true.
>
> Are you sure? From Tokio:
>
>> Starting from Intel's Sandy Bridge, spatial prefetcher is now pulling pairs of 64-byte cache
>> lines at a time, so we have to align to 128 bytes rather than 64.
A cache line is still 64B, even if a prefetcher might pull in multiple cache
lines.
The hardware prefetcher usually only engage when a sequential access pattern is
discovered. So if you're doing array access with increasing index, it would
engage and pull in next cache line; however if you are performing random access
(e.g. following a link list), it would not engage, as otherwise you're
effectively having half the number of cache lines available in your L1 cache.
If the software need to fight the hardware prefetcher in general (where there's
no regular seqential access pattern) by spreading things further apart in
memory, it means that the hardware prefetcher has failed its task and is a bad
design :)
>>
>> Sources:
>> - https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-optimization-manual.pdf
>> - https://github.com/facebook/folly/blob/1b5288e6eea6df074758f877c849b6e73bbb9fbb/folly/lang/Align.h#L107
>>
>> ARM's big.LITTLE architecture has asymmetric cores and "big" cores have 128-byte cache line size.
>>
>> Sources:
>> - https://www.mono-project.com/news/2016/09/12/arm64-icache/
arch/arm64/include/asm/cache.h defines L1_CACHE_BYTES as 64.
>>
>> powerpc64 has 128-byte cache line size.
>>
>> Sources:
>> - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_ppc64x.go#L9
There's no PPC support today in kernel Rust today.
Best,
Gary
>
> https://github.com/tokio-rs/tokio/blob/master/tokio/src/util/cacheline.rs#L85
next prev parent reply other threads:[~2026-01-28 15:05 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 14:05 Andreas Hindborg
2026-01-28 14:25 ` Alexandre Courbot
2026-01-28 14:41 ` Gary Guo
2026-01-28 14:45 ` Miguel Ojeda
2026-01-28 18:19 ` Andreas Hindborg
2026-01-28 14:46 ` Alice Ryhl
2026-01-28 15:05 ` Gary Guo [this message]
2026-05-18 13:41 ` Andreas Hindborg
2026-05-18 16:22 ` Gary Guo
2026-05-19 8:18 ` Andreas Hindborg
2026-05-19 10:35 ` Gary Guo
2026-05-19 11:28 ` Andreas Hindborg
2026-01-28 14:26 ` Miguel Ojeda
2026-01-28 14:34 ` Miguel Ojeda
2026-01-28 18:23 ` Andreas Hindborg
2026-01-28 18:41 ` Miguel Ojeda
2026-01-28 14:32 ` Gary Guo
2026-01-28 18:27 ` Andreas Hindborg
2026-05-19 9:16 ` Andreas Hindborg
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=DG0BD0NGT1HH.1PVFYFO0CCT6N@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tmgross@umich.edu \
/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
all inboxes | Powered by JetHome®