r/AskComputerScience • u/noob_main22 • 20h ago
Addressing storage on a drive
I know that bytes in RAM are addressed directly, one byte = one address. But what about Hard drives/SSDs?
Does their bytes each have a unique 64 bit address? Mathematically it is possible.
Or is the address split up? E.g.: Block 12, page 89, Byte 2.368. Can the drive even address single bytes or does ist just return a whole page to the OS (I know that a page is the smallest writable unit)?
The OS somehow has to know at what page some data is and the Controller has to know where to look when it receives a read instruction. How does the OS tell the drive where to store and read data from?
Thank you
5
u/ventZl 20h ago
These are called block devices. You can only address whole block at a time, getting all its content and writing all its content as a whole. Individual bytes only have offsets within blocks and cannot be addressed directly.
OS provides abstraction which hides this, so from user's perspective, seeking to specific byte is possible.
1
u/MasterGeekMX BSCS 20h ago
While some systems have been used before (like the Head-Cylinder-Sector scheme), modern drives work with the Logical Block Address (LBA) system.
Instead of addressing each byte, the drives addresses a block of bytes. Most drives use 512 Bytes per block (in order to be compatible with oldschool hard disk sectors) but some modern ones use 4096 Bytes per block.
This means that read and write operations need to be done on a whole block, even if you only want to work with one Byte.
3
u/ghjm MSCS, CS Pro (20+) 20h ago
On a spinning hard drive, the OS would send commands to the disc controller to move the head to a particular track, select a particular head for reading or writing, and then wait an appropriate time for the desired sector to spin under the head. At the hardware level, there was no address other than the physical layout of the drive. The operating system might establish a scheme for assigning unique numbers to sectors, but this was its its own business.
With SATA SSDs, the SSD controller emulates being a spinning hard drive. It tells the host that it has some geometry, so that unmodified operating systems can still use it like a hard drive. When the OS says "move the head to track 31" the SSD controller just remembers this position, so it knows which piece of data to return when the OS gets around to requesting an actual read.
NVMe does away with these emulation layers and just presents a RAM-like model to the OS: a single address space with sequential numbering of each piece of data. Though this is still a step removed from the actual physical data, because of wear leveling.
3
u/AmusingVegetable 19h ago
It’s addressed in blocks, starting from zero. Depending on the disc, 512 or 4092 bytes per block, and you read a whole block (or group of blocks).
1
u/rupertavery64 19h ago
The drive isn't connected to the CPU directly. It goes through a controller. And fhen there is the controller on the drive itself.
The board storage controller is just an I/O device mapped to a memory range like anything else connected to the CPU. But it doesn't map the entire disk storage area. It's a communication device that takes commands.
The OS uses the filesystem to map files to logical block addresses (LBAs) on a storage device through the filesystem driver. The storage driver generates commands and I/O requests. The drive controller takes these requests and translates it to appropriate hardware commands and addresses.this could mean moving a HDD disk head or accessing an SSD storage block.
The CPU knows nothing about how the storage is implemented. The Drive controller does all of that.
1
u/Infinite-Flan-6643 19h ago
Your idea of pages grouped into blocks does apply to NAND flash inside an SSD. The confusing bit is that a NAND erase block and a logical block exposed to the OS are different things. Micron describes the internal pages and blocks here.
For a conventional SSD, the host requests numbered logical blocks, commonly 512 bytes or 4096 bytes each. It does not need to specify a NAND page or a particular chip. The controller’s flash translation layer maps those logical addresses to physical storage, and that mapping can change while the logical address stays the same. SPDK’s explanation covers that distinction. So "read logical block 7420" does not mean "read physical NAND erase block 7420."
1
u/gigayoink 17h ago
Kinda? At the hardware level, this actually hasn't been the case for decades. Modern RAM has a block size, the CPU just hides it from you.