Skip to content

Instantly share code, notes, and snippets.

View MaskRay's full-sized avatar
🏠
Working from home. Need food

Fangrui Song MaskRay

🏠
Working from home. Need food
View GitHub Profile
@MaskRay
MaskRay / be_prefix_varint.c
Last active November 17, 2025 04:30
variants of Little Endian Base 128 where the length information is in the first byte
#include <assert.h>
#include <inttypes.h>
#include <stdbit.h>
#include <stdio.h>
#include <string.h>
/*
Big-endian prefix varint encoding for 64-bit integers.
The first byte determines the total length using most significant bits.
@MaskRay
MaskRay / eh_frame_results.csv
Last active October 24, 2025 07:13
Analyze .eh_frame section size distribution across executables and shared libraries on a Linux system
File Total_VM_KB EH_Frame_VM_KB EH_Frame_Ratio
/usr/bin/s390x-linux-gnu-lto-dump-14 26112.0 1863.68 7.1373
/usr/bin/pnmcrop 18.7 0.34765625 1.8591
/usr/bin/uclampset 17.9 1.23 6.8715
/usr/bin/atktopbm 6.36 0.18359375 2.8867
/usr/bin/getent 26.1 1.3 4.9808
/usr/bin/systemd-firstboot 52.1 1.2 2.3033
/usr/bin/busctl 82.9 1.79 2.1592
/usr/bin/arm-linux-gnueabi-g++ 1853.44 113.0 6.0968
/usr/bin/loadunimap 22.2 0.765625 3.4488
@MaskRay
MaskRay / suffixvarint.c
Created October 6, 2025 05:54
unsigned 70-bit suffixvarint (little-endian)
#include <assert.h>
#include <stdbit.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
/*
little-endian suffix varint
xxxxxxx1: 7 value bits, 1 byte
@MaskRay
MaskRay / bench.rb
Last active September 17, 2025 17:14
https://maskray.me/blog/2025-08-31-benchmarking-compression-programs program, distributed under the terms of both the MIT license and the Apache License (Version 2.0)
#!/usr/bin/env ruby
# This program downloads and builds several compression utilities, benchmarks their compression and decompression
# performance on a specific input file including memory consumption, and finally generates HTML charts.
require 'benchmark'
require 'digest'
require 'etc'
require 'fileutils'
require 'json'
require 'net/http'
require 'optparse'
@MaskRay
MaskRay / bad.log
Created August 23, 2025 18:21
journalctl-b.log, good vs bad (system freeze)
Aug 23 10:58:15 blitz kernel: Linux version 6.16.1-arch1-1 (linux@archlinux) (gcc (GCC) 15.2.1 20250813, GNU ld (GNU Binutils) 2.45.0) #1 SMP PREEMPT_DYNAMIC Fri, 15 Aug 2025 16:04:43 +0000
Aug 23 10:58:15 blitz kernel: Command line: BOOT_IMAGE=/vmlinuz-linux root=/dev/nvme0n1p3
Aug 23 10:58:15 blitz kernel: x86/CPU: Model not found in latest microcode list
Aug 23 10:58:15 blitz kernel: x86/split lock detection: #AC: crashing the kernel on kernel split_locks and warning on user-space split_locks
Aug 23 10:58:15 blitz kernel: BIOS-provided physical RAM map:
Aug 23 10:58:15 blitz kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009efff] usable
Aug 23 10:58:15 blitz kernel: BIOS-e820: [mem 0x000000000009f000-0x00000000000fffff] reserved
Aug 23 10:58:15 blitz kernel: BIOS-e820: [mem 0x0000000000100000-0x000000005df8afff] usable
Aug 23 10:58:15 blitz kernel: BIOS-e820: [mem 0x000000005df8b000-0x000000005e88afff] reserved
Aug 23 10:58:15 blitz kernel: BIOS-e820: [mem 0x000000005e88b000-0x00000000606befff] usab
@MaskRay
MaskRay / journalctl-b.log
Created August 5, 2025 05:11
Linux version 6.15.8-arch1-2 (linux@archlinux), random freeze
Aug 04 20:13:02 blitz kernel: Linux version 6.15.8-arch1-2 (linux@archlinux) (gcc (GCC) 15.1.1 20250729, GNU ld (GNU Binutils) 2.45.0) #1 SMP PREEMPT_DYNAMIC Tue, 29 Jul 2025 15:05:00 +0000
Aug 04 20:13:02 blitz kernel: Command line: BOOT_IMAGE=/vmlinuz-linux root=/dev/nvme0n1p3
Aug 04 20:13:02 blitz kernel: x86/split lock detection: #AC: crashing the kernel on kernel split_locks and warning on user-space split_locks
Aug 04 20:13:02 blitz kernel: BIOS-provided physical RAM map:
Aug 04 20:13:02 blitz kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009efff] usable
Aug 04 20:13:02 blitz kernel: BIOS-e820: [mem 0x000000000009f000-0x00000000000fffff] reserved
Aug 04 20:13:02 blitz kernel: BIOS-e820: [mem 0x0000000000100000-0x000000005df8afff] usable
Aug 04 20:13:02 blitz kernel: BIOS-e820: [mem 0x000000005df8b000-0x000000005e88afff] reserved
Aug 04 20:13:02 blitz kernel: BIOS-e820: [mem 0x000000005e88b000-0x00000000606befff] usable
Aug 04 20:13:02 blitz kernel: BIOS-e820: [mem 0x00000000606bf000-0x0000000062
@MaskRay
MaskRay / iwlwifi-bug.md
Created July 15, 2025 05:02
iwlwifi bug report, Intel Wi-Fi 7 BE200

Intel(R) Wi-Fi 7 BE200 320MHz, kernel warning and freeze

When I run sudo iwctl station wlan0 connect wifiname for the first time during a boot, iwctl would error

No matching method found
Failed to retrieve IWD dbus objects, quitting...
@MaskRay
MaskRay / journalctl-b.log
Last active July 15, 2025 04:47
Eurocom Blitz Ultra 2, Ubuntu 24.04, no system freeze
Jul 14 18:20:35 blitz kernel: Linux version 6.11.0-29-generic (buildd@lcy02-amd64-008) (x86_64-linux-gnu-gcc-13 (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0, GNU ld (GNU Binutils for Ubuntu) 2.42) #29~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jun 26 14:16:59 UTC 2 (Ubuntu 6.11.0-29.29~24.04.1-generic 6.11.11)
Jul 14 18:20:35 blitz kernel: Command line: BOOT_IMAGE=/boot/vmlinuz-6.11.0-29-generic root=UUID=bbe63c72-8360-4612-996c-1f26ef0ef727 ro quiet splash vt.handoff=7
Jul 14 18:20:35 blitz kernel: KERNEL supported cpus:
Jul 14 18:20:35 blitz kernel: Intel GenuineIntel
Jul 14 18:20:35 blitz kernel: AMD AuthenticAMD
Jul 14 18:20:35 blitz kernel: Hygon HygonGenuine
Jul 14 18:20:35 blitz kernel: Centaur CentaurHauls
Jul 14 18:20:35 blitz kernel: zhaoxin Shanghai
Jul 14 18:20:35 blitz kernel: x86/split lock detection: #AC: crashing the kernel on kernel split_locks and warning on user-space split_locks
Jul 14 18:20:35 blitz kernel: BIOS-provided physical RAM map:
@MaskRay
MaskRay / journalctl-b.log
Created July 13, 2025 03:39
Eurocom Blitz Ultra 2, no kernel "bad"/"oops" record before freezing
Jul 12 16:53:19 hacking kernel: Linux version 6.15.6-arch1-1 (linux@archlinux) (gcc (GCC) 15.1.1 20250425, GNU ld (GNU Binutils) 2.44.0) #1 SMP PREEMPT_DYNAMIC Thu, 10 Jul 2025 17:10:18 +0000
Jul 12 16:53:19 hacking kernel: Command line: initrd=\intel-ucode.img initrd=\initramfs-linux.img root=UUID=2403f944-7fdf-4185-8119-4f6fd8f7f887 rw intel_idle.max_cstate=2
Jul 12 16:53:19 hacking kernel: x86/split lock detection: #AC: crashing the kernel on kernel split_locks and warning on user-space split_locks
Jul 12 16:53:19 hacking kernel: BIOS-provided physical RAM map:
Jul 12 16:53:19 hacking kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009efff] usable
Jul 12 16:53:19 hacking kernel: BIOS-e820: [mem 0x000000000009f000-0x00000000000fffff] reserved
Jul 12 16:53:19 hacking kernel: BIOS-e820: [mem 0x0000000000100000-0x000000005df8afff] usable
Jul 12 16:53:19 hacking kernel: BIOS-e820: [mem 0x000000005df8b000-0x000000005e88afff] reserved
Jul 12 16:53:19 hacking kernel: BIOS-e820: [mem 0x000000005e88b000-0x0000
@MaskRay
MaskRay / journalctl-b.log
Created July 12, 2025 22:41
Eurocom Ultra Blitz 2 freeze 15:25 kernel log, 15:33 freeze
Jul 12 15:12:14 hacking kernel: Linux version 6.15.6-arch1-1 (linux@archlinux) (gcc (GCC) 15.1.1 20250425, GNU ld (GNU Binutils) 2.44.0) #1 SMP PREEMPT_DYNAMIC Thu, 10 Jul 2025 17:10:18 +0000
Jul 12 15:12:14 hacking kernel: Command line: initrd=\intel-ucode.img initrd=\initramfs-linux.img root=UUID=2403f944-7fdf-4185-8119-4f6fd8f7f887 rw intel_idle.max_cstate=2
Jul 12 15:12:14 hacking kernel: x86/split lock detection: #AC: crashing the kernel on kernel split_locks and warning on user-space split_locks
Jul 12 15:12:14 hacking kernel: BIOS-provided physical RAM map:
Jul 12 15:12:14 hacking kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009efff] usable
Jul 12 15:12:14 hacking kernel: BIOS-e820: [mem 0x000000000009f000-0x00000000000fffff] reserved
Jul 12 15:12:14 hacking kernel: BIOS-e820: [mem 0x0000000000100000-0x000000005df8afff] usable
Jul 12 15:12:14 hacking kernel: BIOS-e820: [mem 0x000000005df8b000-0x000000005e88afff] reserved
Jul 12 15:12:14 hacking kernel: BIOS-e820: [mem 0x000000005e88b000-0x0000