script: add Magic Ring Buffer comment

This commit is contained in:
Nigel Tao committed 2026-06-23 10:47:26 +10:00
1 parent 731578a4e7
commit e0a44a0c40
1 file changed
+11 -7
+11 -7
View File
@@ -19,14 +19,18 @@
// without having to explicitly wrap around the ring-buffer boundaries.
//
// This is similar to the technique discussed in
// https://lo.calho.st/quick-hacks/employing-black-magic-in-the-linux-page-table/
// https://lo.calho.st/posts/black-magic-buffer/
//
// This program differs from that web page's discussion by mapping the physical
// memory three times, not just two. This lets us read or write, implicitly
// wrapping, both forwards (after the middle mapping's end) and backwards
// (before the middle mapping's start). That web page only considers forwards
// reads or writes. Backwards reads are useful when decoding a Lempel-Ziv style
// compression format, copying from history (recently decoded bytes).
// It's also known as the Magic Ring Buffer:
// https://fgiesen.wordpress.com/2012/07/21/the-magic-ring-buffer/
//
// This program differs from those blog posts' discussion by mapping the
// physical memory three times, not just two. This lets us read or write,
// implicitly wrapping, both forwards (after the middle mapping's end) and
// backwards (before the middle mapping's start). Those blog posts only
// consider forwards reads or writes. Backwards reads are useful when decoding
// a Lempel-Ziv style compression format, copying from history (recently
// decoded bytes).
//
// Its output should be:
//