From 26fd68e02c5c6a37e2f7ac0c7e7de8b2d48176b5 Mon Sep 17 00:00:00 2001 From: Teiva Harsanyi Date: Tue, 5 Mar 2024 21:19:34 +0100 Subject: [PATCH] Highlight 92 --- docs/92-false-sharing.md | 2 +- site/92-false-sharing/index.html | 4 ++-- site/sitemap.xml.gz | Bin 342 -> 342 bytes 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/92-false-sharing.md b/docs/92-false-sharing.md index 7aba6e8..22e1f4f 100644 --- a/docs/92-false-sharing.md +++ b/docs/92-false-sharing.md @@ -96,7 +96,7 @@ So how do we solve false sharing? There are two main solutions. The first solution is to use the same approach we’ve shown but ensure that `sumA` and `sumB` aren’t part of the same cache line. For example, we can update the `Result` struct to add _padding_ between the fields. Padding is a technique to allocate extra memory. Because an `int64` requires an 8-byte allocation and a cache line 64 bytes long, we need 64 – 8 = 56 bytes of padding: -```go +```go hl_lines="3" type Result struct { sumA int64 _ [56]byte // Padding diff --git a/site/92-false-sharing/index.html b/site/92-false-sharing/index.html index 536102a..0cf5994 100644 --- a/site/92-false-sharing/index.html +++ b/site/92-false-sharing/index.html @@ -924,8 +924,8 @@

The first solution is to use the same approach we’ve shown but ensure that sumA and sumB aren’t part of the same cache line. For example, we can update the Result struct to add padding between the fields. Padding is a technique to allocate extra memory. Because an int64 requires an 8-byte allocation and a cache line 64 bytes long, we need 64 – 8 = 56 bytes of padding:

type Result struct {
     sumA int64
-    _    [56]byte // Padding
-    sumB int64
+    _    [56]byte // Padding
+    sumB int64
 }
 

The next figure shows a possible memory allocation. Using padding, sumA and sumB will always be part of different memory blocks and hence different cache lines.

diff --git a/site/sitemap.xml.gz b/site/sitemap.xml.gz index c838c720c409cf7431606056d0491c744dad42a9..3d3d1fcd69bc0d482e9399d7c5322b941e655b5d 100644 GIT binary patch delta 15 Wcmcb{bd8BkzMF%?scs`%03!e;_XIfr delta 15 Wcmcb{bd8BkzMF&NZNWyi07d{Qvjo-v