Linux server memory check

If your server crashes regularly it could be a buggy kernel, a driver, power supply or any other hardware part. Memory (RAM) is one of the critical server parts. Bad memory can cause various problems such as random Linux server restart or program segfaults.

Generally, I recommend using memtester command. It is an effective userspace tester for stress-testing the memory subsystem. It is very effective at finding intermittent and non deterministic faults under Linux.

Recently Rahul shah email me another interesting method for testing memory. His idea is based upon md5 checksum and dd command.

First find out memory site using free command.
$ free

 total       used       free     shared    buffers     cached
Mem:        768304     555616     212688          0      22012     270996
-/+ buffers/cache:     262608     505696
Swap:       979956          0     979956

In above example my server has 768304K memory. Now use dd command as follows:
$ dd if=/dev/urandom bs=768304 of=/tmp/memtest count=1050
$ md5sum /tmp/memtest; md5sum /tmp/memtest; md5sum /tmp/memtest

According to him if the checksums do not match, you have faulty memory guaranteed. Read dd command man page to understand all options. dd will create /tmp/memtest file. It will cache data in memory by filling up all memory during read operation. Using md5sum command you are reading same data from memory (as it was cached).

Look like a good hack to me. However I still recommend using memtester userland program. Another option is to use memtest86 program ISO. Download ISO, burn the same on a CD, reboot your system with it test it (it may take more time). From project home page:
Memtest86 is thorough, stand alone memory test for x86 architecture computers. BIOS based memory tests are a quick, cursory check and often miss many of the failures that are detected by Memtest86.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 7 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
7 comments… add one
  • Darren Griffith Dec 22, 2006 @ 8:41

    md5sum does *not* keep its entire target in memory. The md5 algorithm, as I understand it, uses the hash value of the previous block of data to compute the hash value of the next block. So only the previous hash value and the current block of data need to be in memory at a given time. So the above test is useless. It will *not* exercise all of your machine’s memory.

    You can observe md5sum’s memory usage by looking at the output of ps or top.

  • Bob Glassberg Feb 16, 2007 @ 17:38

    ‘Free’ command is not in Solaris. Nor does ‘Vmstat’ on Linux give equivalent info for ‘swap memory’ as ‘vmstat’ gives on Solaris. Do you know of any command common to both systems that would give me info on swap memory in fairly similar format?

  • Magare Sep 15, 2008 @ 22:38

    md5check actually uses shutil.copyfileobj to copy the file (which reads and writes 16KB chunks at a time), and then seeks back to the start of the source file, reads the whole thing into memory in one go, and computes its MD5. So it is not useless.
    And you use it in single user mode.

  • Unihost Brasil - Servidores de hospedagem Nov 16, 2010 @ 9:45

    There’s another way to test the memory using a shell script:

    Alex M. – Tech Support – Unihost Brasil

  • Joseph Bloe Mar 1, 2014 @ 13:01

    “According to him if the checksums do not match, you have faulty memory guaranteed.”

    If you drive has write issues (meaning it can’t write all of the same data each time), it will also cause the above behavior.

    Saying such definite things is very misleading to those who don’t know any better.

  • Joseph Bloe Mar 1, 2014 @ 13:02

    Someone should also take a stab at the idea of “testing memory” while a kernel is loaded :/

    It’s one reason things like memtest are supposed to be executed at boot, not after a kernel has loaded (since you can’t possibly test the RAM the kernel occupies).

  • David Feb 13, 2017 @ 0:25

    memtest86 is not accurate either, we’ve had many occasions that multiple successful passes ran using memtest86 but still getting errors when actually using all the memory in Linux.
    I would recommend running memtest86 as well as the md5sum method multiple times to be sure.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum