Memory

Memory

Memory is the part of the computer where your program and data are while they are being used by the CPU. Contrast this to a hard disk or floppy, where the program is sitting on the disk and is not being used. (Of course with operating systems like Linux, parts of both the program and the data can be stored on the disk, even as the program is running.) There are two types of memory that are most common talked about: RAM and cache.

In most memory today, an extra bit is added for each byte. This is a parity bit. Parity is a simple way of detecting errors within a memory chip (among other things). If an odd number of bits is set, the parity bit will be set to make the total number of bits set an even number (most memory uses even parity). For example, if three bits are set, the parity bit will also be set to make the total bits set four.

When data is written, the number of set bits is calculated and the parity bit is set accordingly. When the data is read, the parity bit is also read. If the total number of bits set is even, all is well. However, if an odd number of data bits is set and the parity bit is not set, or if an even number of data bits is set and the parity bit is set, a parity error has occurred.

When a parity error occurs in memory, the state of the system is uncertain. To prevent any further problems, the parity checking logic generates a Non-maskable Interrupt (NMI), and the CPU immediately jumps to special codes called NMI service routines.

When Linux is interrupted with an NMI as the result of a parity error, it too realizes things are not good, and the system panics. The panic causes the system to stop everything and shut down. Certain machines support ECC (Error Correcting Code) RAM, which corrects parity problems before it kills your system.