Skip to content

Commit 3a4b1d7

Browse files
committed
Docs: Arm & AMD pointer tagging
- AMD Upper Address Ignore - Arm Top Byte Ignore - Arm Memory Tagging Extension
1 parent ead0cd2 commit 3a4b1d7

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

less_slow.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,7 @@ yyjson_alc yyjson_wrap_arena_prepend(arena_t &arena) noexcept {
28812881

28822882
/**
28832883
* There is also an even cooler way to allocate memory! @b Pointer-tagging! 🏷️
2884-
* 64-bit address space is a lie! Most systems only use 48 bits for addresses,
2884+
* 64-bit address space is a lie! Many systems only use 48 bits for addresses,
28852885
* some even less. So, we can use the remaining bits to store metadata about
28862886
* the allocated block, like its size, or the arena it came from.
28872887
*
@@ -2893,22 +2893,31 @@ yyjson_alc yyjson_wrap_arena_prepend(arena_t &arena) noexcept {
28932893
* Byte Order: Little Endian
28942894
*
28952895
* 48-bit virtual addressing allows mapping up to @b 256-TiB of virtual space,
2896-
* leaving 16 bits for metadata. On Armv8-A there is a Top Byte Ignore @b (TBI)
2897-
* mode, that frees 8 bits for such metadata, but it may not be enough for our
2898-
* current use-case.
2896+
* leaving 16 bits for metadata. But there is a catch! On every OS and CPU vendor,
2897+
* the mechanic is different. On Intel-based Linux systems, for example, the
2898+
* feature is called "Linear Address Masking" or @b LAM for short. It has 2 modes:
28992899
*
2900-
* There is a catch! On every OS and CPU vendor, the mechanic is different.
2901-
* On Intel-based Linux systems, for example, the feature is called "Linear Address
2902-
* Masking" or @b LAM for short. It can be configured in 2 modes
2903-
*
2904-
* - LAM_U57: 57-bit linear addresses, 7 bits for metadata
2905-
* - LAM_U48: 48-bit linear addresses, 16 bits for metadata
2900+
* - LAM_U57: 57-bit addresses with a 5-level TLB, 7 bits for metadata in @b [57:62]
2901+
* - LAM_U48: 48-bit addresses with a 4-level TLB, 15 bits for metadata in @b [48:62]
29062902
*
29072903
* The Linux kernel itself has to be compiled with LAM support, and the feature must
2908-
* also be enabled for the current running process.
2904+
* also be enabled for the current running process. The bit #63 can't be touched!
2905+
* Nightmare, and it doesn't get better 😱
2906+
*
2907+
* On AMD, a similar feature is called "Upper Address Ignore" @b (UAI) and exposes
2908+
* 7 bits for metadata @b [57:62].
2909+
*
2910+
* On Armv8-A there is a Top Byte Ignore @b (TBI) mode, that frees 8 bits for such
2911+
* metadata, and on Armv8.5-A there is a Memory Tagging Extension @b (MTE) that
2912+
* allows software to access a 4-bit allocation tag in bits @b [56:59], the lower
2913+
* nibble of the top byte of the address.
29092914
*
29102915
* @see "Support for Intel's Linear Address Masking" on Linux Weekly News:
29112916
* https://lwn.net/Articles/902094/
2917+
* @see "AMD Posts New Linux Code For Zen 4's UAI Feature" on Phoronix:
2918+
* https://www.phoronix.com/news/AMD-Linux-UAI-Zen-4-Tagging
2919+
* @see "Memory Tagging Extension (MTE) in AArch64 Linux" in the Kernel docs:
2920+
* https://docs.kernel.org/6.5/arch/arm64/memory-tagging-extension.html
29122921
*/
29132922

29142923
#if defined(__x86_64__) && defined(__linux__)

0 commit comments

Comments
 (0)