ECC memory: catching flipped bits
Video 037 of 140 in Virtualization Foundations, in the unit “Memory: RAM, addresses and virtual memory”. 4:01, with English and Hindi audio.
A server can run for years without a reboot, and during that time a bit stored in its memory can flip by accident. Left alone, such errors change data without any warning. This article explains why memory bits flip, how ECC memory corrects one flipped bit and detects two, why a database server needs this protection, and how to read the error counts that Ubuntu keeps.
What you will learn
- Server memory stores extra check bits beside each group of data.
- ECC corrects one flipped bit in a group, and detects two.
- Corrected errors are a warning. Uncorrected errors can crash the work that uses them.
- Watch the error counts, and replace failing memory early.
Why a memory bit can flip
Server memory, called DRAM, keeps each bit as a tiny electric charge. A particle from space can strike a memory cell and change that charge, which flips the bit. Electrical noise on the circuit can disturb a stored bit in the same way.
A worn chip or a faulty slot can make the same bit go wrong again and again. Left alone, these errors change stored data without any warning.
How ECC corrects one flipped bit and detects two
ECC stands for error-correcting code. Each group of 64 data bits is stored with 8 extra check bits, which are worked out from the data. Then, on every read:
- The controller works the check bits out again from the data it received.
- It compares the new check bits with the stored ones. If they match, the data is good.
- If exactly one bit has flipped, the check bits show which bit it was. The bit is corrected and the event is logged.
- If two bits have flipped, ECC detects the problem but cannot fix it. The server reports an uncorrectable error, rather than use bad data quietly.
Why a server needs ECC
Think of a database working on a month of a company's orders. Much of that work happens in memory. Without ECC, one flipped bit could change an amount, and nothing would say so. Memory that reports its own errors gives you a chance to find the problem before the wrong number is used.
What corrected and uncorrected errors mean
- Corrections keep coming: a memory cell that is always being corrected is failing. Replace it early.
- An uncorrected error: the program or virtual machine that used that data may crash.
You notice these problems through rising error counts in the system, or a crash that the logs tie to memory.
How to read ECC error counts on Ubuntu
On Ubuntu, a kernel part called EDAC, for error detection and correction, counts memory errors for each memory controller. Its figures appear as small files in the sys folder. The folder that lists the controllers comes first.
ls /sys/devices/system/edac/mc/The file ce_count holds the number of corrected errors on that controller. The file ue_count holds the number of uncorrected errors, which the controller could not fix.
cat /sys/devices/system/edac/mc/mc0/ce_countcat /sys/devices/system/edac/mc/mc0/ue_countNote: Zero is the healthy state. A rising corrected count, or any uncorrected error, means it is time to check the hardware. If the EDAC folder is missing or empty, the counts are not available on that machine, because they depend on the driver for its memory controller.
Try it yourself
You need an Ubuntu machine. You will list the memory controllers, then read the corrected and uncorrected error counts for the first one. If the folder is missing, the counts are not available on that machine.
List the memory controllers that EDAC manages on this machine. There is one folder for each.
ls /sys/devices/system/edac/mc/What you should see: One folder per memory controller that the EDAC driver manages.
Read the number of corrected errors on the first controller. Corrected errors are fixed by ECC, but a rising count is a warning.
cat /sys/devices/system/edac/mc/mc0/ce_countWhat you should see: The number of corrected errors on that controller.
Read the number of uncorrected errors on the same controller. Zero is the healthy state.
cat /sys/devices/system/edac/mc/mc0/ue_countWhat you should see: The number of uncorrected errors. Above zero needs attention.
Terms
- DRAM
- Dynamic random access memory, the kind of memory that keeps each bit as a tiny electric charge.
- ECC
- Error-correcting code, extra check bits stored with data so that the memory can fix one flipped bit and detect two.
- Check bits
- Extra bits worked out from a group of data bits, which show whether the data has changed.
- Uncorrectable error
- A memory error with two or more flipped bits, which ECC detects but cannot fix.
Check yourself
How many flipped bits can ECC correct, and how many can it only detect?
It corrects one flipped bit in a group, and it detects two flipped bits but cannot fix them.
Why does ECC store check bits alongside the data?
The check bits are worked out from the data, so every read can compare them with the stored ones and find a flipped bit.
What should you do when the uncorrected error count is above zero?
Check the hardware, because an uncorrected error means some data could not be fixed and may have caused a crash.
Previous: Bits, bytes, GB and GiB. Next: Why every program gets its own address space.