Some Bits: Nelson's log

Linux and bad memory

This post has more than the usual flailing around. Don’t follow this advice.

My Intel NUC server is failing, twice now it’s corrupted database files with single bit errors. I confirmed with memtest86+ that the problem is bad RAM. I’ve got new hardware on order but meanwhile I want to make things work again.

First I used memtest86+ in summary mode (pressing F1 and F4) to get the above display. It’s telling me that RAM is bad between 868MB and 996MB, also with the hex addresses. Probably not all 130+ MB there is bad but who knows. (In detail I can see that the 5th bit is bad, mostly in a single 4k page. Happily this coincides exactly with the data corruption I was seeing in my database files.)

Then I convinced Linux not to use this RAM by adding the memmap=140M!860M to the Linux command line (by editing /etc/default/grub.) That avoids the whole region memtest86+ identified as bad. This Stack Exchange discussion was very helpful in figuring it out, and this web page has a great detailed explanation of how memmap works. The real purpose of this option is to tell Linux not to touch the memory because some other fancy performance system is using those addresses specially. I rebooted and confirmed the reservation was happening thanks to this line in dmesg:

[ 0.000000] reserve setup_data: [mem 0x0000000035c00000-0x000000003e7fffff] persistent (type 12)

Some fuckups I encountered along the way:

  • Linux has a CONFIG_MEMTEST where it can run a simple RAM check and automatically avoid RAM that tests bad. Apparently memtest=17 is a good setting, according to the cargo cult. I never got the system to boot with this; it’d just go to a blank screen and nothing would happen. I waited 20+ minutes, longer than the 4 minutes one guy who had 128GB of RAM said it took. Perhaps the system overheated and froze up.
  • The old way to do deal with flaky memory was using the BADRAM setting with a confusing mask. This apparently was never in a standard Linux kernel but the patch is in Ubuntu’s kernel. But it doesn’t work in UEFI Secure Boot so forget it.
  • A bug in ubuntu installer from 2016 left /etc/default/grub.d/50-curtin-settings.cfg lying around with a variable that clobbers my setting in /etc/default/grub with the empty string. Here it is eight years later and I just now got hit by the legacy of this bug. (They sorta fixed it, but didn’t do anything to repair systems that had the bug). So I was making changes to the GRUB config, always a scary and confusing thing, and they weren’t taking.
  • Sometimes on booting my poor machine would display “alloc magic is broken at 0x.....” early in the GRUB boot process, I think loading the init ramdisk. Searching Google for this error gives even less than the usual semi-useless info. But one common explanation is.. bad RAM! I noticed the address in the error was close to where my error is, so I think flaky RAM caused it. No idea why it works sometimes and not others, but it seems to work better after I let the system cool down a bit.

Truthfully, every time I’ve tried to use software to cope with flaky hardware it’s ended badly like this. Better just to throw money at the problem and get new hardware. I have an embarassingly cheap N100 system on order, hoping it’s not total garbage.