Skip to content

Instantly share code, notes, and snippets.

@kazuho
kazuho / addmib.pl
Last active February 14, 2025 01:48
tiny memory load generator
#! /usr/bin/perl
use strict;
use warnings;
while (my $l = <STDIN>) {
chomp $l;
if ($l !~ /MiB/ and $l =~ /([0-9]+,[0-9,]+)/) {
$l .= toMiB($1);
}
@kazuho
kazuho / quest3-termux.md
Last active November 15, 2024 16:42
Meta Quest 3のlinuxセットアップ

想定読者

  • linuxに関する基本的な知識があるソフトウェアエンジニアもしくはヘビーユーザで、Quest 3のlinuxをGUI環境で使いたい人
  • apkのインストールとか説明しませんが、Quest 3に入れたやつは、アプリ一覧からカテゴリでUntrusted Sourcesみたいなのを選ぶと出てきます
  • termuxの上にlinux distroを載せるのは、遅いのでやりません(下記ベンチマーク参照)。prefixed-rootだろうがシングルユーザだろうがmusl libcだろうが我々なら大丈夫だ!
  • linuxアプリのインストールは特記事項ない限り省略します。勝手にpkg installとかして

ベンチマーク

@kazuho
kazuho / markdown.md
Last active November 8, 2024 03:32
Linuxカーネルのreadahead、うまく動いてないケースがあるのかも

大きなテキストファイルをawkで処理するときにcatで投げ込むと速い理由のような事象が発生する原因についての推察。

自信はあまりない!

Linuxカーネルのreadahead実装についての理解

  • __do_page_cache_readaheadは、次にreadaheadを実行すべきページについてのみReadaheadフラグをたてる
  • 次にreadaheadを実行すべきページ「以降の全てのページ」ではない
  • do_generic_file_readはReadaheadフラグの立っているページをreadするタイミングでpage_cache_async_readaheadを呼ぶ
  • page_cache_async_readaheadはBDI_sync_congestedが立っている場合はreadaheadしない
@kazuho
kazuho / thundering-herd.pl
Last active October 15, 2024 15:52
thundering herd checker for select-accept pattern
#! /usr/bin/perl
#
# to test:
# 1) run this script with either "accept" or "select-accept" as the argument
# (the script listens to 127.0.0.1:12345)
# 2) telnet localhost 12345
# 3) if you see "accept failed", there is the thundering herd problem
#
#
use strict;
@kazuho
kazuho / freespace.rb
Last active July 4, 2024 07:37
calculate amount of disk space returned, once all the given files and directories are removed
#!/usr/bin/env ruby
require 'find'
BLOCK_SIZE = 512 # ブロックサイズは通常 512 バイト
def calculate_freed_space(paths)
inodes = {}
total_blocks = 0
processed_files = {}
@kazuho
kazuho / sshd-tcpd.socket
Last active July 3, 2024 14:29
sshd + tcp wrappers
# こいつは systemctl enable sshd-tcpd.socket する
[Unit]
Description=ssh
ConditionPathExists=!/etc/ssh/sshd_not_to_be_run
Conflicts=ssh.socket
[Socket]
ListenStream=22
Accept=yes
fizz = function f() {
fizz = function () {
fizz = function () {
fizz = f
return "Fizz"
}
}
}
buzz = function f() {
@kazuho
kazuho / nespresso.scad
Created January 8, 2024 10:34
Nespressoカプセルホルダ(OpenSCAD形式)レイヤ0.2mm前提
Rtop = 12;
Htop = 25;
Rin = 15;
Rout = 20;
H = 2 + (Rout - Rin) / 1.5;
thick = 1.2;
rows = 7;
cols = 5;
for (i = [0:cols - 1]) {
# 必要なモジュールのインポート
import numpy as np
import scipy.stats as stats
# カウントされた足の本数
counts = np.array([57, 62, 63, 60, 57, 60, 58, 60, 61, 62])
# つるとかめの個体数は合計で20匹
total_animals = 20
2752512 bytes alive from 0x7f8e184d27d1, alloc=84, free=0, collision=0
X509_VAL_it at ??:?
SSL_set_ciphersuites at ??:?
966000 bytes alive from 0x7f8e185b746e, alloc=29642, free=26548, collision=0
CRYPTO_zalloc at ??:?
229376 bytes alive from 0x7f8e184d27d1, alloc=7, free=0, collision=0
X509_VAL_it at ??:?