Raspberry Pi の PG table size の変更方法
Raspberry Pi 環境で Envoy Proxy の Out of memory エラーを解消するために、カーネルのページテーブルサイズを変更する手順を解説します。
背景
Raspberry Pi のデフォルトのページテーブルサイズは3(CONFIG_PGTABLE_LEVELS=3)です。
しかし、この設定では Envoy Pod を起動すると以下のような Out of memory エラーが発生する場合があります。
external/com_github_google_tcmalloc/tcmalloc/system-alloc.cc:625] MmapAligned() failed - unable to allocate with tag (hint, size, alignment) - is something limiting address placement? 0x3484c0000000 1073741824 1073741824 @ 0x558a1b1294 0x558a1ad558 0x558a1acdf8 0x558a18df6c 0x558a1aa368 0x558a1aa14c 0x558a182fb8 0x558a0aeac8 0x558a0ab5ec 0x558a17a3c0 0x7f868f857c │external/com_github_google_tcmalloc/tcmalloc/arena.cc:58] FATAL ERROR: Out of memory trying to allocate internal tcmalloc data (bytes, object-size); is something preventing mmap from succeeding (sandbox, VSS limitations)? 131072 632 @ 0x558a1b15fc 0x558a18dffc 0x558a1aa368 0x558a1aa14c 0x558a182fb8 0x558a0aeac8 0x558a0ab5ec 0x558a17a3c0 0x7f868f857cこのため、ページテーブルサイズを4に変更するためのカーネルのビルドを行います。
手順
# working when running as root# install build requirementsapt install -y git bc bison flex libssl-dev make libncurses5-dev# clone and download kernel sourcescd /optgit clone --depth=1 https://github.com/raspberrypi/linuxcd linux
# create kernel config#RASPI 4: `make bcm2711_defconfig`#RASPI 5: `make bcm2712_defconfig`
# # DO OTHER TUNINGS HERE via `make menuconfig`
# set PG table size to 4 instead of default 3sed -i 's/CONFIG_PGTABLE_LEVELS=3/CONFIG_PGTABLE_LEVELS=4/' .config
# set enabled CONFIG_ARM64_VA_BITS_48 and merge configcat > .config-fragment << EOFCONFIG_ARM64_VA_BITS_48=yEOF./scripts/kconfig/merge_config.sh .config .config-fragment
# compile (requires a lot of time on raspi 4)make -j4 Image.gz modules dtbsmake modules_install
# copy compiled resourcescp arch/arm64/boot/dts/broadcom/*.dtb /boot/cp arch/arm64/boot/dts/overlays/*.dtb* /boot/overlays/cp arch/arm64/boot/dts/overlays/README /boot/overlays/cp arch/arm64/boot/Image.gz /boot/firmware/kernel8.img
# use new kernelecho "kernel=kernel8.img" | tee -a /boot/firmware/config.txt
reboot参照
https://github.com/envoyproxy/envoy/issues/23339#issuecomment-1987403294