Raspberry Pi 4B
Planning
Why Upgrade the Raspberry Pi 3B?
I use my own Wi-Fi access point, because I want my firewall and other
security features, and making them happen on a commercial appliance was not
possible. However, I have a mysterious symptom on my host(s) that run
hostapd. For years the AP will run without problems, but then it gets into
a mode where every few days the CPU freezes, with these details:
- The freeze happens on the RPi 3b and on an Intel NUC6CAYH (Celeron J3455),
which serves as my main router.
- The lightdm greeter is visible and looks normal.
- But the keyboard and mouse are inert, cursor doesn't move, keystrokes
don't appear in the widget that's supposed to have focus.
- The host does not respond to ping, ssh, etc.
- On Wi-Fi, all the stations have been kicked off and are complaining.
- After reboot, there is nothing in log files. In /var/log/debug
you find normal-looking messages for a machine doing nothing special.
Then dmesg output from the reboot. No data whatsoever between them.
When does it freeze, and when not?
- Only host(s) running hostapd are affected.
- There is a vague suggestion that high Wi-Fi traffic makes a freeze
more likely, but objective evidence is not available.
- The AP host will run for days and then freeze. Most recently, a freeze one
day after a weekly security update and reboot, then another freeze
four days later, and has survived 5 days after that.
- Freezes have happened on Jacinth (Intel Celeron, x86_64) and Holly
(Raspberry Pi 3B, ARM 64bit).
- Freezes have happened on 3 different NICs, both Realtek and Mediatek,
using the Mediatek in-kernel drivers and the Realtek KMS driver
package.
- SuSE package rtl8812au-kmp-default for Realtek 8812au wireless, for
various NICs including currently Alfa 802.11ac Ultra-Range
AC1200 USB adapter.
- driver mt76x2u.ko.zst for MediaTek Inc. MT7612U
802.11a/b/g/n/ac Wireless Adapter, in Terow ROW02FD and
Alfa AWUS036ACM.
- Tentative conclusion: A buggy driver is probably not the problem.
Defective hardware also is probably not the problem.
The consensus of forum discussions is that there is a memory issue and
kswapd gets into a high CPU utilization state. Jimc says:
- In current kernels (6.4.8 now installed) kswapd has become a
kernel thread, kswap.
- It's hard to be sure what other people are reporting: is kswapd
actually using the CPU, or are we mixing I/O activity with CPU?
- The reported behavior sounds a lot like thrashing, i.e. a lot of
very active swaps in and out, because RAM is overcommitted.
- And that would be caused by a memory leak in the culprit program.
- One forum poster had the problem on a RPi 3B with Raspbian. He put
OpenWRT on it. Problem was just as bad.
- Forum posters have been complaining about freezes for decades,
earliest that I actually read was from 2007, and they attribute it
to an unfixed (or unfixable?) bug in Linux memory management. Jimc's
confidence in that last conclusion is low.
- Sooner or later the OOM killer is going to kill something important,
causing the symptoms.
One user had the problem on a RPi 3B+ with hostapd. He upgraded to a RPi 4B
with 4Gb RAM, and the problem went away. Jimc says: more likely, the problem
occurred less frequently because of more available memory. Although it's
conceivable that the culprit program actually uses a lot of memory and a leak
is not involved.
I'm also annoyed with my RPi 3B's because:
- They don't have enough resources to run Firefox, excluding them from a
desktop replacement role.
- They're rather slow, making system updates painfully long.
- No realtime clock, requiring cockamamie kludges at boot.
- Cannot turn off power from software (or hibernate, which on Linux is the
same thing). I have an external switch but it's tacky.
Specifications of Raspberry Pi 4B
Note: these specs were extracted around 2023-08-17. On 2023-09-28 the
Raspberry Pi 5 was announced. I'm considering upgrading one or both RPi 3B's
to RPi 4B's, but I'll seriously consider the RPi 5 instead.
- Raspberry Pi project website
- 4B product page.
Unstarred specifications below are from this page.
- Wikipedia article
about the product family. '*' indicates feature descriptions from
this article; unstarred items are from the specifications on the project
website
- SoC: Broadcom BCM2711 64bit quad core, 1.8GHz. ARM Cortex-A72 (ARM v8),
1Mb L2 cache shared among all cores. Capable of hosting virtual machines.
- Graphics: *Broadcom VideoCore VI, 500MHz. Video RAM is shared with
the CPU. All normal resolutions can be produced.
- Graphics Ports (simultaneously): Two micro-HDMI ports up to 4kp60 (4k
pixels image width, not interleaved, up to 60Hz refresh rate), with digital
audio output. Plus one 2-lane MIPI DSI display port (for a panel) and one
2-lane MIPI CSI camera port. Plus compsite video on the 3.5mm stereo audio
jack.
- Graphics software: H.265 (4Kp60 decode), H.264 (1080p60 decode,
1080p30 encode), OpenGL ES 31, Vulkan 1.0 (See the note below for versions
and licensing.)
- RAM: 1, 2, 4, 8Gb, LPDDR4-3200 SDRAM, selected at purchase
- 40 pin extended GPIO, backward compatible with older RPi models.
- 4 wire 3.5mm jack for stereo audio; 4th wire for a microphone; jack is
shared with composite video.
-
Disc
: Micro-SD card slot (SDXC and earlier); addressing limit is
2e11 bytes (terabytes), which is beyond what is commercially available;
user provides their own card.
- Communications: Bluetooth 5.0 (Low Energy BLE); IEEE 802.11ac Wi-Fi in 2.4
and 5.0GHz bands; IEEE 802.3ab gigabit Ethernet. There is an onboard
antenna.
- Two USB-3.0 ports and two USB-2.0 ports
- *There is no realtime clock. Accessory clocks are available.
- Inception: 2019-06-xx (8Gb RAM in 2020-05-xx)
- Booting: *From Micro SD card or USB device
- Power required: 5V DC via USB-C or GPIO header, 3A (15W) recommended, 2.5A
will work if USB devices draw 0.5A or less. User provides their own power
supply; an
official
power supply is available but not required. PoE
(power over Ethernet) is available with an accessory.
- Typical power: *1.5W idle, 6.7W maxed out (with video, keyboard, mouse
and Wi-Fi active).
- Operating temperature: 0 to 50C ambient. SoC max temperature is 85C. The
bare board is supposed to not need a fan, but cases (sold separately)
reduce airflow and often include a fan. At high temperatures the firmware
throttles the clock speed and supply voltage to reduce power.
- Dimensions: 85.6 x 56.5 x 17mm, 45g
For the graphics software: I'm using the aarch64 (ARM) port of OpenSuSE
Tumbleweed. Installed
means this package was either originally part of
the then-current Tumbleseed RPi image, or was obtained from Packman, and it was
updated at the time of writing to the indicated version through SuSE's normal
processes. No license fee was required. The packages are also available in
the RaspberryPi OS images and updates; and Ubuntu equivalents are mentioned
in forum posts.
- H.265: Package libx265-199-3.5-1699.2.pm.35.aarch64 from
Packman, GPL-2.0+ (FOSS)
- H.264: Package
libx264-164-0.164+git20220602.baee400f-1699.1.pm.8.aarch64 from
Packman, GPL-2.0+ (FOSS)
- OpenGL ES 31: Package libglvnd-1.7.0-1.1.aarch64 from SuSE, MIT
license (FOSS)
- Vulkan 1.0: Package libvulkan1-1.3.268.0-1.1.aarch64 from SuSE,
Apache license (FOSS).
Components Needed
These are what I want. Whether I will be able to get them is
another matter.
Raspberry Pi 4B motherboard. B indicates the presence of an Ethernet
connector (RJ45).
Power brick, 5V 3A, USB-C connector. An on-off switch on the brick
is preferred; inline in the power cable is acceptable; but my RPi 3B power
bricks have neither and I bought separate 120V NEMA 5-15P/S switches.
Case. A clear case is more cool than a black one. Referring to
attractiveness, not temperature. Because the case restricts airflow,
and because the RPi 4B can use more power than the 3B, I should look for a fan
also.
SD card. Currently 64Gb is about the smallest you can get, and is
plenty for an access point. But in a desktop replacement role, more storage
would be useful. I don't know how fast the RPi can go, but a slow card
can make the rest of the machine disappointing.
I would like an antenna for Wi-Fi and Bluetooth. This will take some
searching. Reviewer says the onboard antenna works. Presumably it is shared
between both services.
I would also like a realtime clock.
I should look at a packaged kit, only if they have everything I want.
Choosing a SD Card
What suitable SD cards are available on Amazon? Size 64Gb, micro SD form
(but Amazon's searcher includes a lot of full size cards). Here's a summary
list.
- Samsung 256Gb EVO Select, UHS-I, $19.99
- SanDisk 64Gb Ultra UHS-I, 120Mb/s, $8.99, $12.75 for two
- SanDisk Extreme 64Gb UHS-I 170Mb/s, $10.99 (also 160Mb/s for $9.76)
- SanDisk Extreme Pro 64Gb, UHS-I 200Mb/s read, 90Mb/s write, $12.85
- Plus lots of za-pai, i.e. no-name vendors that aren't trustworthy
I'm guessing at the workload of a modern Linux OS: installing software
updates is the major writing task, which will be sequential. Writing for
payload
tasks is a distant second, and is probably random. The biggest
reading task is to get shared libraries into memory, which is done by mapping
them, and then the CPU bounces randomly among short surbroutines in various
libraries, whereupon individual blocks of pre-allocated memory are stuffed with
code from disc. In other words, the code is read in random order. Sequential
reading, e.g. from the browser cache, is in second place. A database server
would read and write randomly and frequently, but none of my machines do a lot
of database action.
Web articles about SD cards: Vendors seem to concentrate on cards for
digital comeras, for which the most important workload is sequential writing;
a card in a video camera has to keep up with the video stream, and a still
camera has to snap and store images in quick succession.
In second place is sequential reading, for displaying photos. Random access
is irrelevant on a camera.
-
Types of SD Cards Explained by David Coleman, updated 2023-11-06
Kinds of SD cards, and particularly, what various speed ratings
mean. UHS-I appears to be limited to 104MB/s (bytes).
-
Fastest Micro SD Cards by David Coleman, this data from 2023-07-04,
currently last updated 2023-12-23
His speed tests and recommendations. Ranked by sequential write speed
(advertised), for video cameras. I'm only including vendors I've heard of,
and keeping only Micro-SD. It looks like he tested 64Gb cards. (Can a
RPi 3B use these cards? Not the first two, it has a UHS-I socket, not
UHS-II.)
- Verbatim Pro+ II V90 : read 295Mb/s, write 245MB/s. (UHS-II, V90)
Amazon: out of stock and availability unknown.
- Kingston Canvas React Plus V90 : read 285 MB/s (UHS-II V90)
Amazon: $14.32, may be different product from the one reviewed.
Includes full size adapter and USB reader (UHS-I).
Measured: r-seq 200.5, w-seq 268.4, r-rnd 244.2, w-rnd 186.3 MB/s
- SanDisk Extreme Pro V30 : read 170MB/s, write 90 MB/s (UHS-I V30 A2)
Measured: r-seq 88.8 w-seq 93.6 r-rnd 92.4 w-rnd 80.4 MB/s rated 170/90
This is model number SDSQXCZ; SDSQXCY, SDSQXBZ have near identical
speeds.
- He tested 61 card brands and variants. He buys one of everything.
-
Raspberry Pi Micro-SD Card Performance Comparison (2019)
by Jeff Geerling, 2019-07-10 (4 years ago).
SD cards are mainly aimed at the camera market, for which
sequential write speed is the most important. For the apps and games
sector, i.e. RPi, random reads and writes dominate. Jeff ran 4 benchmarks
on a bunch of cards: "hdparm" seems to test sequential reading; "dd-write"
for sequential writing, "4k-read" and 4k-write" for 4k blocks in random
locations. 10 top of the line cards (in 2019) were tested, all 64Gb, all
on RPi-4B.
- hdparm: 40.78 .. 43.95 MB/s (sequential read)
- dd-write: 6.6 .. 39.6 MB/s (sequential write); median was 35.5 MB/s,
others were pathetic.
- 4k-read: 1.56 .. 10.77 MB/s; 2nd slowest was 6.57 MB/s.
- 4k-write: 3.85 .. 0.66 MB/s; median was 1.74 MB/s
There is a rating metric, prefixed with 'A', for apps and games. In
another blog post, Jeff tested some A-rated cards in his RPi's and found
that they were no better than the cards represented here.
Jimc's disc tester reads the entire disc sequentially (looking for errors).
Holly has a Samsung SDHC 32Gb EVO Select ($11.99 in 2018) which is not one
of the tested cards. On this tester it achieved 17 MB/s. Piki's disc did
20MB/s. The cards in Jeff's blog post were over twice as fast.
So which card should I get? Let's choose between:
- SanDisk 64Gb Ultra UHS-I, 120Mb/s, $8.99 ($12.75 for two)
- SanDisk Extreme 64Gb UHS-I 170Mb/s, $10.99
David Coleman tests the SanDisk Extreme Pro.
Advertixed seq read 170Mb/s, seq write 90Mb/s (UHS-I <= 104MB/s)
His tests: seq read 88.8, seq write 93.6, rnd read 92.4, rnd write 80.4
This is model SDSQXCZ. Also available models ending in Y G P ; the Y
is actually slightly better than the Z, G and P are noticeably slower.
Plus there are other SanDisk cards that are fast but not quite as fast.
David says that new models are often very similar to previous, so if you
can't find exactly the tested card, you're pretty safe with a neighbor.
That's the case on Amazon.
Amazon product page for SanDisk 64Gb Extreme Pro MicroSD UHS-I card:
Model: SDSQXCU-064G-GN6MA;
Spec-oids: C10 U3 V30 A2 200MB/s read, 90MB/s write (when pigs fly, a UHS-I
card upper bound is 104MB/s). $12.86 sold by MemoryWhiz
fulfilled
by Amazon. This is the card I ended up getting for the new RPi 4B.
Raspberry Pi Kits
I'm looking for a RPi-4B motherboard, case, thermal
management, various etc items. The main item I want to get myself is
the SD card. (Most kits include the SD card.)
Vilros Basic Starter Kit for Raspberry Pi 4 with Fan Cooled ABS Case, $115
- $120 - $140 for 2-4-8 Gb board. Sold by Prestige Milano
fulfilled by
Amazon. Free
Amazon tech support included.
Contents: The board. ABS transparent case.
Fan. Zipper pouch. Power supply with on-off switch (on a plug strip it would
cover at least 2 plugs). One adapter cable for Micro-HDMI to full size. Set
of 4 heat radiators. Quick start guide. Does not include SD card, keyboard or
mouse. Glowing reviews. Only complaint: the instructions for setting up the
fan have an error in what pins to use (find and follow the revised
instructions). Also at least some fans have low vs high speed, and high speed
isn't super noisy but one reviewer mentions picking low speed because he wants
it quieter.
Amazon order:
- Ordered 2023-08-17, promised 08-18
- SanDisk 64GB Extreme PRO microSD UHS-I Card, $12.86
- Vilros Basic Starter Kit for Raspberry Pi 4 (8Gb), $139.99
Tidbits
- Witty Pi 4
- This is an add-on multifunction board with all the features from
normal desktop machines that you wish the RPi had.
- It has a realtime clock with battery, and a power switch, and a DC-DC
converter from 6-30V to 5V (or a USB connector, use one or the other).
3 amps to the RPi. I'm not sure if the USB connector is micro-USB or
type C, which is what the RPi-4 has.
- Also can shut down the RPi from software and wake on a schedule.
- Form factor: a HAT. This is a standard size module that fits on the
RPi's expansions bus.
- Price: 27 EUR (currently 29.55 USD).
- Available from: their site, but not seen on Amazon.
- The Witty Pi 4 board also works on RPi-3B, same for the cases.
- Also, clear acrylic case for RPi-3B or RPI-4B with space for one HAT
such as this one. Price: 7.27 EUR = 7.96 USD. There's also a case for
2 HATs: Witty Pi and 7 port USB hub. 7.66 EUR = 8.38 USD.
- The Witty Pi 4 is very attractive but I decided to keep things simple
and defer this board.
- ETL or Intertek
Intertek (formerly Edison Testing Labs, ETL) is an OHSA Nationally
Recognized Testing Laboratory. They have a "global network" of testing
laboratories, and are recognized by USA-OHSA, Canada, Mexico, and other
countries including South America. Old world coverage: not sure. They
are the same general idea as Underwriters Laboratories (UL), but with more
modern product hype.
- SunFounder
PiPower
UPS Power Supply for Raspberry Pi
- $29.99 sold by
SunFounder Direct
fulfilled by Amazon.
Battery included. It attaches under the RPi (mechanically and electrically
compatible with most RPi models (not RPi 400, duh) and several other SBCs).
Feed power (between outages) into the USB-C connector on the PiPower board.
It charges the battery and power goes through a jumper cable (USB-A to
USB-C, micro-USB also available) to the RPi. Output 5V 3A. Battery: LiIon
7.4V 2 amp hours, should run the RPi for 3-4 hours.
New Hostname
- The plan was to replace Holly, but now Holly is going to stay as an AP.
My usual procedure would be to call the new one Orion (name reserved for a
host being set up), then on successful setup I would junk the old Holly
hardware and rename Orion to Holly.
- But Holly is not going away. Meaning a new name.
Which the new machine could start using immediately.
- First choice was Kaa, the wise old python in Rudyard Kipling's Jungle
Book. The WAF (Wife Acceptance Factor) of this name was low.
- Names of my
Novanima kittens: Iris Jacinth Ken Lucent Mica Night Oso Petra
Quin Rose Selen Titania Orion Valeria Wolf Xena. Not used so far: Ken
Lucent Night Quin Valeria Wolf. Let's make it Quin.
- While testing Firefox on the RPi 4B, I hit a perfect logo image for a
Beaver, which
immediately became the name of the new machine.
- Rename documentation directory symlink. Assign a fixed IP in my address
range. Add Beaver to hostdata.db and install. Has to wait until I know
the MAC address.
Photo and Image Credit