r/computerscience • u/0boy0girl • 16h ago
Help how do computers access more data then their processors have physical address space
ive been googling and can't figure this out
so like Disks, Drives, ect,
for example, 32 bit x86 systems don't even have enough address space to read 1 miniCD. Which can take up too, if I did my math right, 44 bits worth of addresses,
but I know they, in fact did, same with hard drives.
I know older systems (Like early Nintendo consoles) used bank switching, is it a similar concept?
9
Upvotes
20
u/dariusbiggs 14h ago
just because you only have a 32 bit CPU doesn't mean you can't work on 64 bit numbers, just split the big thing into the upper and lower parts and do the math on those.
Which then gives you the concepts of pagination or blocks/sectors. Page 0 (we start at 0) gets the first 232 bits of data, page 1 gets the next 232, etc. Or with blocks you can say, this thing is divided into blocks of 4096 bits (212), and we can have 232 of them. That gives us those 44bits. Increase the size of the blocks and you can store more at the expense of reading more data in latger chunks.
There are a myriad of ways to solve that problem, it's not a complicated one.
In the low level Assembly language for example you have CPU registers called AH, and AL, (8 bits each) which make up the high bits, and low bits respectively of AX (16 bits), which represents the lower half of EAX (32 bits), which is the lower half of RAX (64 bits).
That is one way the systems evolved from 8 to 16 to 32 to 64 bits.
18
u/tcpukl 16h ago
It's just loading different days into ram off disk as it's needed. You can't see it all at once. Your Kindle doesn't load the entire book into ram. It's as you open pages.
5
u/four_reeds 15h ago
The processors have a catch system (actually, usually more than two layers of cache) into which instructions are data are read. You are correct that it is rare that entire programs can fit in the cache(s) so the first chunk gets read in and operations begin. Eventually, most of the stuff in the cache is read or operated on and a new stuff gets loaded in and processing resumes.
That is s is an oversimplification. A lot of things are happening in modern processors sometimes in sequence, sometimes in parallel. Then there are other layers of complexity when you think about process scheduling, preemption and resuming.
1
u/khedoros 14h ago
"Primary storage" is storage directly accessible by the CPU. That's often data like firmware ROM, the main system memory, memory-mapped hardware registers, etc. That's all the stuff that has to have a place in the computer's memory map, and it's the category where bank-switching can be useful (like for the systems in the 80s with a 16-bit address space, but ROMs that could need more bits to address).
"Secondary storage" isn't directly accessible to the CPU; the addresses of a block device like a hard drive or optical drive aren't mapped into the CPU's address space. In a PC, a drive controller's registers are exposed to the CPU via either port-mapped or memory-mapped I/O, and there's a protocol for sending commands to the drive controller to read/write chunks of data from specific blocks on the storage device itself and get them into CPU-accessible memory. There are different generations of interface protocols, and different protocols used for different device types, so exact details vary.
3
u/somewhereAtC 14h ago
Working with limited memory has been a research topic since computers began. You might find the writings of Knuth interesting, where he describes algorithms to sort dozens of megabytes of data using 3 or 4 tape drives, on a CPU having only a few kilobytes RAM.
3
u/jmtd CS BSc 2001-04, PhD 2017- 14h ago
32 bits is enough to address 4GiB. For larger, look up PAE
1
u/TheologyFan 15h ago
Drives are already slow, no reason why you can’t use 2 32 addresses to select where you want to read from
1
u/zeekar 14h ago
Processor address lines only matter for accessing RAM, which is a relatively small amount of memory that only remembers stuff while the computer is turned on. The actual code that is running at any time has to live in RAM, but other than that it's up to the program what to keep there. When computers need data from the outside world, they fetch it a little at a time and copy it into RAM, which is the only place they can do anything with it.
Modern computers have other processors besides the CPU just for input/output, so the CPU doesn't even have to do the copying part. It just issues a request that says something like "Hey, I need this sector from the disk drive", and then the disk controller copies the data from that sector into a buffer in RAM.
1
u/claytonkb 14h ago
I'm going to over-simplify a bit, but here's the basic answer to your questions...
x86 is a von Neumann architecture: it consists of CPU, memory and I/O. Memory refers to the high-speed memory, such as DDR5 memory (also, RAM or DRAM). There are other memories on your motherboard besides the main memory, but we'll keep it simple here. The hard-disk or any other similar device, is called storage or mass-storage.
While both memory and storage do essentially the same thing (storing data), there are three important differences: 1) RAM is volatile (the stored bytes disappear when the RAM chips lose power) whereas a hard-disk / flash-USB / etc. is not, and 2) RAM is fast while the hard-drive is very slow (hundreds or thousands of times worse latency, and many times lower bandwidth) and 3) RAM is not nearly as dense as a mass-storage device (1TB of RAM takes up a lot of physical space, whereas a 10TB hard-drive is much smaller and denser).
The CPU accesses RAM directly -- the motherboard design ensures that there is a minimum-latency, high-bandwidth connection between CPU and RAM in order to utilize the RAM to its maximum. Storage devices, however, are not accessed directly by the CPU. Instead, the CPU issues I/O requests to the chipset. The I/O request is something like, "Please read X bytes of data from the bus device with bus-address Y according to instructions Z." The chipset is essentially the bus master of the main bus of the motherboard (along with a bunch of other roles it performs). Note: on SoC, the chipset is electrically integrated, but still logically separate. The CPU sends an I/O packet to the chipset which routes the packet to the correct device on the main bus, in this case, a hard-disk.
The hard-disk expects to receive command packets with a certain format, and the OS or installed drivers know how to format those packets. Once a command packet is sent to the hard-drive, its onboard controller processes the packet and responds accordingly. If the packet is a read-command, the controller will read the appropriate section of the disk and reply to the chipset with the requested data from the disk. If it is a write-command, the controller will receive the data from the chipset and write it to disk.
PS: This is a very generic description of a generic computing architecture, I am not giving a spec-accurate description of x86-based PC architecture which would take us down a bunch of historical rabbit trails...
1
u/rupertavery64 14h ago edited 14h ago
In the case of disk storage, data isn't accessed through the address bus. The drive is an I/O device that is located at a memory address, but the data is accessed using commands and through logical block addressing.
So the device controller finds the data and sends it over in chunks. For SSDs it would probably look like bank switching. For hard disks, the LBA is translated into cylinders heads and sectors.
1
u/Distinct-Question-16 11h ago
The most primitive example is a drives that is accessed with IO port using packets containing typically the linear block address, then controller fetches the data from the drive and returns it using an IO port. These NES cartridges memories (rom and ram) connect directly to the cpu address space, so the cpu access them directly as if was memory (so called mem-mapped). Some computers and consoles have also software controlled switches to control this mapping.
Devices can have IO and Mem spaces (possibly defined by the convention of the interface) for instance they can be just mem-mapped, but these small spaces holes holds typically registers, buffers for control and data.
1
u/fcddev 10h ago
A very straightforward example is the PS1, which had like 4 or 8 megabytes of RAM while you could store up to 700MB on CDs.
If you’re thinking: well, it’s easy, you don’t have to load every file at once in RAM: congratulations! You solve the problem at a large scale. Weird media bits aside, a CD can be treated as one big file, but we make it multiple files by including a directory of data at the start and loading just the parts you need for any given task at a time.
File formats engineered to be probably larger than the amount of memory you have on a system are organized to be loadable bit by bit.
This obviously limits what you can do with that file, and at the end of the day not all formats are designed to be loaded in parts. There are programs and files that don’t work on 32-bit machines, for instance.
1
u/Temporary-Story-9957 10h ago
a regular CD was something like 650MB so a miniCD certainly didn't need a 44bit address. Disk drives don't have byte addressing, on old systems you used something called CHS addressing but then LBA got introduced. You'd ask the drive for a "block" and that was 512 bytes and grew larger for later drives.
edit: Forgot to say blocks exist.
1
u/Resistor1 9h ago
You are the computer reading a book. You can turn to and read any page, but then not the others.
1
u/person1873 9h ago
The limitation of address space only matters until you can talk to a separate device controller.
Once you have a controller for the device you're trying to access information from; then the CPU no longer has to think about address space, since it can send a request as data to the controller chip at it's mapped address (within your 32 bit address space).
The controller will have some memory of it's own for assembling and decoding requests, and will then collect the requested data and serve it back to the CPU on the data bus.
It will usually do this a single bus width at a time.
Given how rapidly even rudimentary CPU's can transfer data, this very mechanical and sequential process can feel incredibly fluid to the end user. particularly if the controller uses a semaphore architecture such that the CPU doesn't have block on the fetch instruction to the controller, and can wait for the controller to tell the CPU it's ready.
1
u/granadesnhorseshoes 6h ago
Everyone's giving super detailed answers about architecture and caches, which is true enough, but may give a misleading or incomplete picture based on one fundamental assumption; That the process needs to use storage addresses at all.
The processor never actually "addresses" storage devices itself at all. It just sees a bunch of bytes of data Its told to sent to a bus controller. The bus controller reads the bytes and figures out which attached device it's supposed to send it to and sends it to the storage controller. The storage controller is the only bit of hardware that actually has to deal with the address as an actual address(not always, but close enough for this purpose.) It's just regular data to the cpu that it can send/receive in whatever sized chunks it can support.
On modern hardware the cpu doesn't even have to see or touch most of that kind of data. it can see a bunch of data bound for a specific bus and literally divert those bytes to go directly to that bus without involving itself at all. It has much better things to do than shovel your data to the bus controller 32 or 64 bits at a time. See also; Direct Memory Access.
I still remember the MASSIVE performance increase when DMA became a standard thing and the CPU didn't have to do the shoveling itself. It was about as big a jump in performance as the jump from HDD to Solid-state today.
1
u/BCReason 3h ago
I think you’re confusing RAM with storage. RAM is the memory where the computer stores applications and data it’s currently using. You can’t have more RAM than you have physical address space. 2^32=4,294,967,296 bytes of memory which would be the maximum for a 32 bit system.
As required the computer will read data and applications from storage into RAM and write data not being used back to storage. Therefore you can have much more data than you can have addressing for.
1
u/Immediate-Panda2359 3h ago
Isn't this the whole point of having an MMU (Memory Management Unit)?
1
u/cthulhu944 3h ago
How do you eat an elephant? One bite at a time.
The address space is just limits what gets put into RAM. You don't load the entire disk into RAM, you only load the part you are working on. Addressing space on a disk is different than addressing ram. The computer specifies what part of the disk to read (track, sector, block) and an io controller goes to the disk and reads that off the disk and puts it in a chunk of RAM.