All insightsEngineering

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.

Published
Read
5 min
In this note · 3 sections
  1. 01We blamed the wrong thing
  2. 02So what fixed it?
  3. 03What we’d change about the bench

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.

On 0.1.10, lookup time climbs steadily to about 645 ms per file; on 0.1.11 it climbs to about 250 ms across the silhouettes, then restarts near 25 ms for the airline logos. 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.

Flash reads per logo lookup against the KB of inline files that sort ahead of a logo, for six image builds. 0.1.10 and the same files in the new write order both sit near 465 reads at 106 KB, though the new order's chain is 109 pairs instead of 144. Moving the silhouettes or lowering the limit to 288 bytes lands near 260 to 295 reads at about 52 to 56 KB. 0.1.11 sits at 97 reads and 3 KB. 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:

PYTHON
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:        break

We 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.

More insights

All insights →
  1. Engineering · Read · 1 min

    Eight minutes from advisory to offline. Patching came second.

    When NGINX2Root dropped, we took the affected service off the internet before patching anything. Here’s why that was the faster safe move.

    XORS Studio

  2. Engineering · Read · 6 min

    Building an AI-powered pipeline to process returns

    We built a pipeline to automatically read return forms, processing 81% of a batch without human review. AI agents perform multiple roles within the pipeline to improve accuracy.

    Edward Yan

  3. Engineering · Read · 4 min

    How we built an AI auditor for healthcare paperwork

    A pair of diabetic shoes costs the government a few hundred dollars. One wrong date in the paperwork can cost the supplier all of it, years later. We built an auditor that reads the paperwork before it ships, and the AI was the easy part.

    Ahmed Panju

Start a project

Tell us what you need to ship.

Message us, or pick a day below. We reply within 24 hours.

x@xors.xyz
XORS Studio
Book a call
Talk to one of our engineers.
  1. 1Pick a day on the calendar.
  2. 2One of our 7 senior engineers runs the call.
  3. 3Tell us the problem. We plan the build with you on the call.
30 minutes
Google Meet

Within 24 hours you get a written plan and a price. It is free, and it is yours to keep.

 
AvailableSelected
Pick a day
About: “Our hardware test timed out. A longer timeout would have passed a slow filesystem.”

Calendly shows the open times for this day. You book the call there.

See open times →