前段时间从组里面拿到一块顶配的树莓派5(16GB内存),准备搞点东西玩玩,却发现Redis死活无法启动,查看下日志后直接懵逼😅

<jemalloc>: Unsupported system page size
Could not connect to Redis at 127.0.0.1:6379: Connection refused
<jemalloc>: Unsupported system page size
zmalloc: Out of memory trying to allocate 56 bytes
Aborted

好好好,啥叫Unsupported system page size?于是按照网上说的输入getconf PAGE_SIZE看看情况

getconf PAGE_SIZE
16384

嚯,16KB,话说System Page Size这玩意我从来就没有注意到过,于是打开自己的WSL看看情况

getconf PAGE_SIZE
4096

OKOK,那现在的情况就显而易见了:Redis因为Jemalloc的问题无法在树莓派5上运行了。解决方法有两种

1.修改Kernel.img

想必树莓派的研究人员也是考虑到过这种情况的,所以也准备了Page Size为4KB的Kernel

网上有很多相关教程,这里就直接粘贴进来供大家参考

在/boot/firmware/config.txt添加这一行

kernel=kernel8.img

然后重启树莓派

然后Redis就能正常启动了

2.重新编译Redis

这个方案是可行的!重新编译后Jemalloc会自动识别树莓派的16KB PageSize,因此就能正常运行,这里贴下我正常运行的配置,使用的Linux发行版是Debian

安装依赖:

sudo apt-get install -y --no-install-recommends ca-certificates wget dpkg-dev gcc g++ libc6-dev libssl-dev make git cmake python3 python3-pip python3-venv python3-dev unzip rsync clang automake autoconf libtool

下载源码包进行Make编译

wget -O redis-8.0.3.tar.gz https://github.com/redis/redis/archive/refs/tags/8.0.3.tar.gz
tar xvf redis-8.0.3.tar.gz
export BUILD_TLS=yes BUILD_WITH_MODULES=yes DISABLE_WERRORS=yes
make -j "$(nproc)" all

如果手滑,做了些不该做的操作的话,直接make distclean清理目录

make distclean

虽然不用sudo也能运行,但有条件的话还是建议使用sudo

sudo ./src/redis-server redis.conf

如果是远程访问Redis的话还需要做安全配置更改,这里就不说了

后记

去树莓派社区看为什么他们选择设置16KB的Page Size,得到的答复是会有7%的性能提升(Why to run 16k page size for RPi5?)

image-20250801160645050

然后下面老哥的评价让我有些无语😅

If you have some software that does have problems with 16k pages then that is what you should be looking at, not complaining that the os breaks them.

emmm……虽然我情感上支持这位老哥说的,但当我试图尝试其他软件,也因为16KB这个问题运行不起来后(KeyDB,InfluxDB),我决定写这篇Blog记录这个问题

以及:我不认为,为了这7%的性能提升,值得我去挨个编译那些不支持的软件🤔

Anyway,我觉得要是有空的话,我倒是想探究下这7%的性能增长是怎么来的