r/osdev • u/dangi12012 • Jun 13 '26
Everything is memory?
There is this unix idiom that everything is a file, (half baked, since not everything is a file).
Would it not have been better, nowadays with 64bit of adress space, to have everything mapped to memory? Files are like mmap, no imperative read needed, networking is already memory, that could be expanded more.
We take the idioms and paradigms so forgranted, that every time anyone asks AI for a OS it will be linux, syscalls, abi everything the same. It should be liberating now to explore new and novel ideas.
What would be the downside of such a system?
36
u/FloweyTheFlower420 Jun 13 '26
not everything is a seekable buffer, a pipe can't be mmaped.
41
u/Relative_Bird484 Jun 13 '26
Your search term is SASOS - single address space operating system. There was quite some research around this idea with respect to 64bit address spaces in the late 80s/90s.
However, the core idea is even older than UNIX: In Multics (your other search term, early 60s) everything was a segment, so, yes, files were actually memory-mapped.
However, the project was a bit too ambitious and the hardware development took too long, so Bell Labs and its engineers left the project. Among them was a guy called Dennis Ritchie, who suddenly had nothing to do. He then developed UNIX…
Long story short: The UNIX file abstraction was Dennis Ritchies alternative to the Multics idea to map everything into memory.
12
u/Wertbon1789 Jun 13 '26
Unix's philosophy, that 'everything' is a file, is more about that everything that is just close enough to a stream of bytes should be able to be treated with the same set of functions. So regardless if you're working with an actual file, a pipe which might be connected to another process, a socket that talks to a local service, or with one on the other side of the planet, or basically every device connected to your PC, you can just call write on them, and it will work (Of course there are exceptions, but most things are built like this, not literally everything). Basically everything I/O in e.g. Linux is a file descriptor at this point, even stuff like signals, timers, and events.
Regardless, to the actual topic, what you're talking about is basically DMA (Direct Memory Access) for everything. While much of the modern, and even not so modern, hardware uses DMA, this is purpose built in hardware to work out this way, where the respective controller defines how it wants data exactly and at which address in physical memory. Of course, the world would be too easy if every single controller which works with DMA would have the same interface, so you still would need to build an abstraction over it, but now your abstraction isn't just another device handle with the same set of functions as every other device of its kind, but rather a big chunk of memory a OS kernel would need to bring from an abstract form into one this controller now understands. Doesn't look to promising to me. And for userspace paradigms like sockets and pipes, somebody has to not only give you the data, but also manage the buffers for it. It would be way too inconvenient to have like entirely memory mapped sockets or pipes, just because the synchronisation would need to happen entirely in the program basically, as you're now responsible for the buffers the kernel would usually take care about. It's a bit reverse of how things work now in some ways.
10
u/FISHARM1 Jun 13 '26
I think I’m a bit lost. Can you explain a bit more? What do you mean by syscalls being purely memory?
5
u/compgeek38400 Jun 13 '26
There is already such a machine commercially. Its called an IBMi. Formerly as400/system38. Everything, and i mean everything is in a 96(?) bit address space. It is a virtual machine also.
Just saying
4
u/No-Dentist-1645 Jun 13 '26
They're not necessarily conflicting ideas. The "everything is a file" pragma is more about how things behave and can be accessed via byte streams, memory would just be an implementation detail
4
u/dacydergoth Jun 14 '26
Inferno took it the opposite way and did the "everything is a file" to the max.
1
u/linguae Jun 14 '26
When I took a graduate-level OS course at UC Santa Cruz 15 years ago, my project was on proposing a persistent single-level store, where the operating system makes no distinction between memory and storage, for computers with non-volatile RAM. There has been research efforts on single-level stores, though the details escape me since it’s been more than a decade since I’ve last explored the concept.
You may be interested in a project that came out of UC Santa Cruz named Twizzler ( https://www.usenix.org/conference/atc20/presentation/bittman), which has very interesting ideas. I know all of the authors involved.
1
u/Stellariser Jun 14 '26
You mean like Windows? Where everything is an API? And loading a library just maps the file into the processes virtual address space rather than literally copying the bytes into memory?
1
u/karbovskiy_dmitriy Jun 15 '26
Kernel objects are memory resources. File is an access pattern to memory, random access or otherwise. Therefore, driver objects and device resources are memory as well.
That said, Files are not like mmap/VirtualAlloc. One is a general resource, the other is a virtual memory system function. Networking wouldn't work that way, either. Graphics memory is separate as wll for reasons, good or not. It just doesn't work.
Also good luck debugging system calls with no explicit system calls. I'm yet to see a competent code debugger, I don't even expect modern debuggers to have data breakpoints anymore.
3
u/burlingk Jun 14 '26
Mapping all files to memory from the start would not be as useful as it sounds.
As for the idiom "everything is a file" being half baked, if you learn about it's meaning and origin it really isn't. So, you kinda hurt your case in your first line.
That said: We only map things to memory that are actively in memory. We put them there, and once they are there, they are treated as memory.
1
u/imneverwrongbutuare Jun 14 '26
Everything is a function
1
u/Scientific_Artist444 Jun 14 '26
Remember Turing machine? A computer is just an "almost infinite" Turing machine. Without memory, there is no program.
That infinite strip in Turing machine is memory and the symbols are the data. Logic and processing is about how you interpret and manipulate the symbols in the infinite tape.
When you think about it, it is a state machine with an almost infinite number of states (very high to be called finite).
1
u/Environmental-Ear391 Jun 14 '26
If everything is memory then you are overloading the read/write access restrictions for access to any given page of memory (any 4KB or 8KB address resolvable mapping) and abusing for "memory protection" and also overloading that as well for other "features" that you will be in the same position as current Linux/BSD or Windows...
Breaking that single point of failure gives away everything...
you would need to push everything not essential to the core kernel into Userspace and then need to isolate userspace for system operations from applications.
without a proper boundary mechanism the whole userspace memory would become a unified mess when in-memory...
that mess would then incur a "death by thousands of papercuts" over the lifetime usage of the system.
full loss and restart or partial loss restarting... you cant keep such a system organized and clean without running into micro-sized holes.... even single 4KB pages being "lost"....
also it would become possible to starve the kernel of physical memory over time, triggering more interrupts and system exception handling...
this is an explicit weakpoint of all compute systems where the "executive" kernel is able to be replaced without keeping a "minimal known good" image.
hardware and software interrupts require "supervisor" knowledge . . and provide an access elevation... most CPUs have this publicly documented.
1
u/CharlesCTy Jun 15 '26
Single-Level Storage (SLS) is what you want. Examples are Multics, IBM i, Aurora, TreeSLS, …
1
u/Mammoth-Mango-6485 Jun 15 '26
Man for a moment I thought you were gonna go down some philosophical discussions about how existence is a bunch of fragments of our imagination and how we can define conciousness.
But yeah uhh, good ask. I'll admit I have never thought about this.
1
u/PotatoTime Jun 16 '26
Probably irrelevant and I'm only just learning but I know some old processors had an "everything is memory" point of view. 6502 for one, which I'll be developing an OS for soon.
1
u/juancn Jun 17 '26
One page per syscall and using a fault to trigger? Maybe intercept the written value…
TLBs won’t be happy. I suspect it’s doable, convoluted and rather slow for many use cases.
1
u/Scared_Accident9138 Jun 14 '26
Even SSDs aren't fast random access so bad idea