Our hardware test timed out. A longer timeout would have passed a slow filesystem.
A new filesystem image for Flightwall’s wall displays stalled on our test bench. We nearly fixed it by waiting longer, blamed the wrong thing, then rebuilt the image eight ways on a laptop to find out what actually made it slow.
In this note · 3 sections
On the afternoon of November 4, our hardware test bench gave up on a new filesystem image for Flightwall’s wall displays. The board had printed nothing for four minutes.
The bench is a Mac mini with two Flightwall boards plugged into it. It flashes each build, records what the board prints, and grades the log. This run used a test build that reads all 874 files in the image before starting the display, to make sure nothing had gone missing. Four minutes of silence looked a lot like a hang.
It wasn’t one. Our normal firmware, which skips that check, booted the same filesystem and had the flight display up in 36 seconds. The files were all there. Reading them was just slow.
That matters, because a wall reads from this filesystem all day: every time it switches flights, every 3 seconds by default, it looks up the airline’s logo. We mounted the image on a laptop with the wall’s settings and counted flash reads per lookup. It needed about three times as many as the image already on the walls.
The easy fix was to give the bench more time, and we did raise the limit to 25 minutes. That alone would have turned the run green. But the same change also timed every file and ran the production image alongside. On the boards, a lookup on the new image took 330 ms on average. On production it took 96 ms, though production has fewer files. The image we shipped the next morning, with all 874, took 97 ms.
Lookup time per 50 files, in the order the test read them, on one board’s first boot (the first 850 of 874 files).
We blamed the wrong thing
LittleFS stores a directory as a chain of small metadata blocks, kept in alphabetical order, and it finds a file by reading that chain from the front. It can also tuck a small file inside the chain itself, so the file doesn’t use up a whole 4 KB block. Picture a phone book where some entries have a short letter pasted in next to them. To find a name, you read past every letter pasted in ahead of it.
The new image builder tucked in every file up to 512 bytes, the most the wall allows, and wrote them alphabetically. The logo directory, which also held 348 small aircraft silhouettes, came out as a chain of 144 block pairs, against 16 on production.
That long chain was the obvious culprit, and the first drafts of this post blamed it. But the fix we shipped on November 5 changed three things at once, so nobody had checked. A week later we did. We rebuilt the real files on the laptop eight ways (two size limits for tucked-in files, two write orders, silhouettes in the logo folder or their own) and counted reads for each of the 505 airline logos. The laptop’s LittleFS is slightly newer than the wall’s, so treat its counts as a ranking; they rank the images the same way the boards do.
The chain turned out to matter very little. Writing the same files in a different order made it a quarter shorter, 109 pairs instead of 144, and lookups got slightly worse: 468 reads instead of 464.
What did track the cost, roughly, was how much tucked-in data sat ahead of each logo in the alphabet: 106 KB on average for 0.1.10, every byte of it read and checksummed on the way.
Two builds share the top right; the shorter chain saved nothing. The two builds that didn’t fit aren’t shown.
So what fixed it?
The new write order didn’t make anything faster. It saved space. Writing the files that need their own blocks first, and the tucked-in ones last and smallest first, freed about 70 blocks. Without that room, a 288-byte limit doesn’t fit the partition at all; both builds that tried failed.
The speed came from the other two changes. At 288 bytes, 271 logos moved out into blocks of their own, leaving 28 tucked in where there had been 299. Moving the silhouettes took 348 small files out from in front of the logos, and that alone cut reads by 44%. Together the three changes cut them by 79%, from 464 to 97.
The builder now tries limits from 32 bytes upward and keeps the first image that still leaves 16 blocks free for the wall’s own writes:
INLINE_LIMITS = tuple(range(32, 513, 32))MIN_FREE_BLOCKS = 16 limits = [limit for limit in INLINE_LIMITS if limit < geometry.inline_max] + [geometry.inline_max]for limit in limits: image, used_blocks = _format_and_write( data_dir, size_bytes, files, geometry, limit) # ... if block_count - used_blocks >= MIN_FREE_BLOCKS: breakWe had also looked at going back to the old image tool, mklittlefs, which only tucks in files of 64 bytes or less. Stored that way, the files needed 946 blocks, and the partition has 623. The tool didn’t complain. It stored 579 of the 875 files, left one silhouette empty, and exited with success.
Version 0.1.11 went to production the next morning, and 0.1.10 never left the bench. Its slowest lookup took 680 ms; since a wall clears its screen slots before drawing each new flight, that would have left the logo space blank for almost a quarter of each flight, if we’re reading the drawing code right. The silhouettes stayed slow (the climb on the left of the first chart) until November 10, when the wall started drawing them from eight images built into the firmware.
What we’d change about the bench
Our grader printed every one of those timings and checked none of them. Bigger projects don’t work that way. Mozilla’s Perfherder, which watches Firefox’s performance, raises an alert by default when a number moves by 2%. LittleFS’s own release notes compare benchmark read counts with the previous release, the same kind of number our laptop script produces. Test labs like LAVA can also switch a board’s power off and on remotely; ours still needs someone to pull the plug.
The laptop count needs no hardware, and it isn’t part of our image build yet. If it were, even a loose rule, such as failing any image that needs 25% more reads per logo than the one on the walls, would have caught 0.1.10 before it got near a board. It wouldn’t have caught the silhouettes, though. They were new, so there was nothing to compare them with.