Some understanding of memory hardware
| The lower-level parts of computers
General: Computer power consumption · Computer noises Memory: Some understanding of memory hardware · CPU cache · Flash memory · Virtual memory · Memory mapped IO and files · RAM disk · Memory limits on 32-bit and 64-bit machines Related: Network wiring notes - Power over Ethernet · 19" rack sizes Unsorted: Interrupts · Computer booting · GPU, GPGPU, OpenCL, CUDA notes |
"What Every Programmer Should Know About Memory" is a good overview of memory architectures, RAM types, reasons bandwidth and access speeds vary.
RAM types
DRAM - Dynamic RAM
- a fairly wide term, mostly for constructions that use a capacitor+transistor per cell - fewer components than many other types, but...
- capacitor leakage means it forgets its state, so this has to be refreshed regularly,
- where 'regularly' means on the rough order of milliseconds (there have been many generations, processes, die sizes, etc. of DRAM)
- and this is a game of statistics - probably many cells are fine for maybe half a second, but we care about integrity of all, then we have to consider the worst case under the worst conditions
- also meaning you need a DRAM controller, more complexity (not something you'd DIY), and not the lowest possible latency
- (and also increasing latency somewhat, though this is less of an issue when you have multiple chips)
- ...but the lower component count per cell, so high-density, and cheaper per storage size
- SDRAM - Synchronous DRAM, a practical design consideration that allows the controller to be easier to deal with, which helps higher data rates
SRAM - Static RAM
- Has a higher component count per cell (6 transistors) than e.g. DRAM
- Retains state as long as power is applied to the chip, no need for refresh, also making it a little lower-latency
- no extra controller needed (so a little simpler to include in designs)
- the higher component count per cell makes it more expensive per storage size
- e.g used in caches, due to speed, and acceptable cost for lower amounts
PSRAM - PseudoStatic RAM
- A design tradeoff, somewhere between SRAM and DRAM in terms of use
- like DRAM in that it has built-in refresh, so functionally it's just as "don't think about it" as SRAM
- it's cheaper than SRAM
- it's slower than DRAM
SRAM makes sense for small internal RAM, PSRAM makes sense for extended RAM (often less lightly coupled) in situations where a bulk of DRAM is not necessary
While not fundamental, there practical choices around microcontrollers and small computers often lead to
- kilobytes (e.g. AVR) of RAM often being SRAM
- megabytes (e.g. ESP and ARM) frequently being PSRAM (or DRAM)
- gigabytes (e.g. RPi) often being DRAM
Non-volatile RAM
We tend to think of RAM as volatile, only useful as an intermediate scratchpad between storage and use, and will lose its contents very soon after it loses power.
Yet there are various designs that are both easily accessible and keep their state.
There is a gliding scale of this, and some other properties.
We may well call it NVM (non-volatile memory) when we haven't yet gotten to some more specific properties,
like how often we may read or write, or how difficult that is.
Say, some variants of EEPROM aren't the easiest to deal with. We like Flash more, even though it's basically a development from EEPROM. But both wear out.
NVRAM on the other hand tends to be easier, more reisable, like FRAM, MRAM, and PRAM, or nvSRAM or even BBSRAM.
nvSRAM - SRAM and EEPROM stuck on the same chip.
- seems intended as a practical improvement on BBSRAM
- and/or a "access common stuff quickly, occasionally write a chunk to EEPROM" style of data logging, black boxes, that sort of thing
- https://en.wikipedia.org/wiki/NvSRAM
BBSRAM - Battery Backed SRAM
- basically just SRAM alongside a lithium battery, so that it'll live a good while
- is sort of cheating, but usefully so.
FRAM - Ferroelectric RAM
- functions more like flash, also limited in amount of use (but with many more cycles)
- read process is destructive (like e.g DRAM), so you need a write-after-read to keep data around
- so it's great for things like round-robin logging (which would be pretty bad for Flash)
- https://electronics.stackexchange.com/questions/58297/whats-the-catch-with-fram
PRAM
DRAM stick types
ECC RAM ('Error correction code')
- can detect many (and correct some) hardware errors in RAM
- The rate of of bit-flips is low, but will happen. If your computations or data are very important to you, you want ECC rather than the regular, non-ECC type.
- See also:
Registered RAM (sometimes buffered RAM) basically places an electronic buffer on the DRAM modules (register as in hardware register)
- offloads some electrical load from the main controller onto these buffers, making it easier to have a mainboard more stably connect more individual memory sticks/chips.
- ...at a small latency hit
- typical in servers, because they can accept more sticks
- Must be supported by the memory controller, which means it is a motherboard design choice to go for registered RAM or not
- pricier (more electronics, fewer units sold)
- because of this correlation with server use, most registered RAM is specifically registered ECC RAM
- yet there is also unregistered ECC, and registered non-ECC, which can be good options on specific designs of simpler servers and beefy workstations.
- sometimes called RDIMM -- in the same context UDIMM is used to refer to unbuffered
- https://en.wikipedia.org/wiki/Registered_memory
FB-DIMM, Fully Buffered DIMM
- same intent as registered RAM - more stable sticks on one controller
- the buffer is now between stick and controller [1] rather than on the stick
- physically different pinout/notching
SO-DIMM (Small Outline DIMM)
- Physically more compact. Used in laptops, some networking hardware, some Mini-ITX
EPP and XMP (Enhanced Performance Profile, Extreme Memory Profiles)
- basically, one-click overclocking for RAM, by storing overclocked timing profiles
- so you can configure faster timings (and Vdimm and such) according to the modules, rather than your trial and error
- normally, memory timing is configured according to a table in the SPD, which are JEDEC-approved ratings and typically conservative.
- EPP and XMP basically means running them as fast as they could go (and typically higher voltage)
In any case, the type of memory must be supported by the memory controller
- DDR2/3/4 - physically won't fit
- Note that while some controllers (e.g. those in CPUs) support two generations, a motherboard will typically have just one type of memory socket
- registered or not
- ECC or not
Historically, RAM controllers were a thing on the motherboard near the CPU, while there are now various cases where the controller is on the CPU.
More on...
DRAM versus SRAM
ECC
Buffered/registered RAM
Encrypted RAM
EPROM, EEPROM, and variants
PROM is Programmable ROM
- can be written exactly once
EPROM is Erasable Programmable ROM.
- often implied UV-EEPROM, erased with UV shone through a quartz window. You would e.g. tape that over to avoid it corrupting later.
EEPROM's extra E means Electrically Erasable
- meaning it's now done under electrical command
- early EEPROM read, wrote, and erased (verify) a single byte at a time. Modern EEPROM can work in larger chunks.
- you only get a limited amount of erases (much like Flash memory. Flash is arguably just an evolution of EEPROM)
Flash memory (intro)
Flash can be considered a refinement on EEPROM. (The name probably came from marketing, helping to distinguish it as its own thing, with distinct properties)
Where EEPROM had to be wiped completely before rewriting, "Flash memory" allows erasing a block that is generally much smaller than the whole thing (and larger than anything you erase a byte at a time), a tradeoff that helps write speed, longevity, use for random-storage needs, and eventually cost.
Something that did not change much between EEPROM and flash is that it
has a limited number of erase cycles, and erase speed is noticeably lower than other use.
Most memory cards and USB stick have one flash chip and a simple controller, which is the cheapest setup,
and why flash rarely broke 10MB/s twenty years ago and cheap ones still don't.
The simplest setup also tends to not have enough wear leveling to last very long.
SSDs are made of flash, but are what you might call managed flash,
which just means the controller you talk to is fancier.
They go faster partly because they have more Flash chips to interleave/parallelize between (RAID-like layout), it hides Flash's relatively slow erase speed (by postponing it, which usually works under home-use loads, but not under heavy load) and which lasts longer by avoiding reuse of the same cell.
On fake flash
Fake flash refers to one of a few scams.
Commonly one where the cards's controller reports a larger size than there is actual storage behind it.
These seem to come in roughly two variants:
- once you ask for what's not there, they will immediately error out
- once you ask for what's not there, or it will wrap back on itself and write in existing area, which breaks/corrupts something soon enough
Both will act broken, with only a difference in when and how it acts broken, with the why part being a technical detail.
There are some tools to detect fake flash.
You can e.g. read out what flash memory chips are in there and whether that adds up.
Most scammers don't go so far to fake this, but some do, so this isn't foolproof.
The more thorough check is much simpler but a somewhat slower:
actually write to all of it and see if it checks out - a write-and-verify test, see below.
Memory card health (and speed) tests
While memory cards, USB sticks, and SSDs all based on flash memory,
the memory cards and USB sticks usually lack smartness - wear leveling and health introspection (like SMART for platter and SSD).
So you should assume that they will fail.
Since there is no early warning, you should also assume they will fail all at once, without warning, and that you won't be able to read them out.
So never keep your only copy of something important on them.
Even if they fail in a sort of 'becoming read-only' way,
filesystems are not made to deal with write failure,
so you may need special tools, and/or a technical friend, for recovery.
Can you check?
Sort of.
You can do a non-destructively read-only test: read out the entire thing.
...ideally reading all blocks, not just the ones currently used by files (Details vary per OS. For windows's chkdsk the simplest may be the "scan for an attempt recovery of bad sectors" checkbox, but there are clearer ways, with better summaries)
The only real test of whether it's fully writable is to actually write to all of it, but
- that will actively wear it a little
- it's destructive of the data still on there.
- it only proves that it hasn't failed already, not that it won't do so soon
...but it can still be a halfway decent way to inspect a bowl of cards you've collected and know little about - to gauge
- their speed
- whether they haven't failed yet
- whether they are fake flash
Tools include:
- Linux: f3
- Windows: H2testw
These create files in free space (if empty, then almost all the SD card)
This also ends up telling you actual average write and read speed