B Duncan Ltd
Field Failures Traced to Kernel Memory Fragmentation
Six months to fail, and nothing left behind to say why
In brief
A client’s controllers were quietly resetting to factory defaults at one customer’s sites. We got the fault to happen overnight on the bench, found the cause, and fixed it with the client’s developers.
Results
- A six-month field fault reproduced on the bench overnight
- Root cause fixed, and the field failures stopped
- Fix released inside the customer’s update window
Summary
A global manufacturer’s embedded Linux controllers were losing their settings at one of its largest customers. A few months after a routine firmware update, units started coming back up on factory defaults and kept running without their safety-critical settings. The manufacturer’s own team had spent months trying to reproduce it. We were first booked for two days. The client kept extending the work as findings came in, and it ran to fifteen weeks.
The problem
The units didn’t crash or drop offline. They kept running on default settings and looked healthy. The customer only caught it because they checked the configuration of every unit remotely, and a customer who didn’t check might never have known.
There was very little to go on. Four units had failed, each after three to six months of running without a restart. Their event logs looked normal right up to the failure. Both redundant copies of the settings database were corrupt at once. And when a controller found no valid settings, it erased its event history as well, so each failure wiped the record of what led up to it.
No other customer had reported anything like it, and the client’s test lab couldn’t make it happen.
What we did
A fault that takes six months to show up is very hard to work on. You can’t wait six months to find out whether a theory is right, and you can’t prove a fix that way either. From the first day, the aim was to make it fail on the bench, on demand.
We started by listing every point where the settings could be lost, from the build to power-up, against everything that could lose them: the flash chip, RAM, the bootloader, the kernel flash driver, the database code, and the firmware upgrade path. Each combination was tested or ruled out in the code. We even checked whether someone could have got in over the communications link and erased the settings.
The first real find came in week one. The code that saved the settings assumed every flash write worked and never checked. If a write failed, it still wrote the checksum, treated the save as done, and went on to erase the other copy ready for the next save. That explained how both copies could end up bad, but not why the writes were failing in the first place.

We built two tools along the way. One decoded raw flash dumps and checked every stage of a save against the copy in RAM, so we could see how far a save had got before it went wrong. The other hammered the same flash and memory paths the save used, to push a bench unit towards failure faster than normal running would.
Four weeks in, a bench unit failed the same way as the field units: both copies corrupt, settings gone, nothing in the log. But it only happened with our stress tool running, so it showed how the settings were lost without showing what drove it in the field.
In the field, the customer’s logs showed that one communications queue on a field unit had handled nearly 70 million events and was permanently full. The signals at that customer’s sites were noisy, and every small change in a measurement became an event, several times a second. No other installation came close to that load.
Six weeks in, we fed noisy signals into a bench unit running the customer’s firmware, unmodified, and left it overnight. By the morning it had lost its settings. From then on, every fix could be tested on the bench in a day instead of waited on for months.
Root cause
Unusually high event load
Noisy measurements at this customer’s sites generated far more measurement-change events, and far more CPU load, than any other installation.
Kernel memory fragments
The controller had 16 MB of RAM. Every queued event reserved 2 kB of kernel memory, though most needed about 32 bytes, and hundreds could be waiting at once. Months of allocating and freeing broke the free memory into small pieces.
Flash driver allocation fails
The firmware update had grown the settings from 60 kB to 89 kB, and the nightly save needed one unbroken 128 kB block of kernel memory to write them. After months of fragmentation, there was eventually no such block left.
Save fails silently
The save code didn’t check whether the write had worked. It wrote the checksum anyway, for settings that were never written.
Settings lost at next power cycle
After two failed saves, both copies were invalid. At the next power cycle the controller found no valid database and loaded factory defaults.
Display and comms freeze
The same event load starved the user interface and the communications link of CPU time, which is why operators saw them lock up.

Results

To test the fixes, we ran two bench units side by side on the same noisy signals, one on the old firmware and one on the new. The old firmware corrupted its settings almost as soon as testing started. The new firmware didn’t, and its peak CPU load was about 40% lower.
The customer had only a short window to update every unit in the field, so the fixes were frozen, tested, and released with the client’s developers within a few weeks. The field failures stopped.
Why it matters
The failure came from three common faults:
- An unbounded event rate
- An oversized allocation
- An unchecked return value
None of them fails normal testing on its own. It took this customer’s noisy signals and months without a restart to line them up.
When a save failed, the write call returned an error that nothing checked. The other copy of the settings was still good at that point. The controller could have kept it, logged the error, and restarted, which would have cleared the fragmentation and let the next save work. Instead it erased the good copy. The fixed code reads back every save and only erases the old copy once the new one checks out.
Firmware that runs for years without a restart needs defensive programming. Check every call that can fail, and decide in advance what the safe response is. In event-driven designs the worst-case load comes from the field, not the lab, so limit how many events can be created, how big each one is, and how much memory any single operation can ask for. When something does fail, make it visible. A stopped controller is safer than one running on the wrong settings.