293 points · by majke · 8y ago · 217 comments
MsgSend is a more useful primitive than a file. It's a subroutine call across processes, a better fit to anything that isn't stream I/O. In most OSs, you want a subroutine call, but the OS gives you an I/O operation. Linux has to stand on its head for operations such as getting all the properties of a pluggable device, because returning a variable length array of fixed-format records as an atomic operation isn't a Linux primitive.
Microkernels have a bad reputation because interprocess communication in Mach was botched. Mach was built on BSD. To do this right, you have to design CPU scheduling and message passing together, and they need to be tightly coupled. The key to interprocess communication is arranging the normal path for a message pass to throw control from one process to another without a trip through the scheduler. Get that wrong and your microkernel will be sluggish.
Are they symmetrical philosophies? As a layman, this appears to mirror the financial debate between everything being stocks (“the quantum of an economy is a dollar of assets!”) and everything being flows (“the quantum is a transaction!”), or physics’ particle-versus-wave formulations.
Thanks for opening me up to this issue.
- GenodeOS is reportedly used in production by some commercial clients, though mostly undisclosed IIRC; it is a higher-level layer (~OS) compatible with numerous microkernels
- Fuchsia OS - in dev; it's a recent development by Google; as much as Google is officially silent about it (I understand they're not sure how the experiment will work out for them), observers assume it's most probably hoped to be used as a successor to Android
- Redox OS - in dev; no concrete news of mainstream usage plans I know of, but has some mindshare among developers
- Minix 3 - used in production; infamously by Intel in their IME
- There is a per-thread IPC zone of 0x100 bytes. When doing IPC, the request is serialized and put into this. If bigger data than 0x100 bytes is necessary, pointers are passed around, and the Kernel maps it into the process servicing the call. - svcSendSyncRequest is used to call an IPC. It is a synchronous API that will block until the process servicing the call replies to it. - svcReplyAndReceive is used to receive an IPC request and reply to a request, and then wait until a new one is received. The syscalls are "merged" into a single one to avoid the syscall overhead: Almost all svcReply will be followed by an svcReceive, so merging them into a single call makes a lot of sense.
You can find more information about the SVCs at [1] and the IPC layout at [2].
[0] Preempting the "I thought the switch used BSD": wikipedia was wrong, the OS is completely custom, and the kernel is tailor-made. [1] http://switchbrew.org/index.php?title=SVC [2] http://switchbrew.org/index.php?title=IPC_Marshalling
It's a low level RPC mechanism, it does reschedule to the new process immediately without a trip through the scheduler when it's used, it has similar blocking semantics, etc.
It's also worth following the "bus1" work for linux which may end up being quite similar as well.
xnu is a hybrid of Mach and FreeBSD. To be super-concrete, it has both sets of syscalls, with Mach syscalls as negative integers, and BSD syscalls as positive integers. A given running executable has a dual existence as both a BSD pid_t and a Mach task_t. At one point it was even possible to have a Mach task without a pid.
Most executed syscalls are BSD: read, write, select, getpid, etc. However Mach still plays a role in the VM system (`vm_copy`, etc.) and crucially via the IPC workhorse `mach_msg`.
It's hard to overstate the importance of mach_msg. It underlies the great macOS IPC primitives: xpc, notify(3), etc. Linux looks anemic by comparison with its limited pipes, creaky SysV sendmsg(), and DBus (hope you never have to use it). But it also appears that Apple is preparing to drop Mach: mach_msg / MIG is buried, xpc is conspicuously designed to be separable from Mach, etc.
Why? What benefits do they have to drop it ?
https://softwareengineering.stackexchange.com/questions/4659...
>"I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages (so messaging came at the very beginning -- it took a while to see how to do messaging in a programming language efficiently enough to be useful)." -Alan Kay
NeFS -- aka NFS 3.0 -- used a PostScript interpreter as the file system API.
Plan 9 had a different view IIRC, something like everything has a protocol.
There's a common trait among many objects: you can read a sequence of bytes from it. Disk files, sockets, various input devices, random number generators, etc. There's another common trait, writing a stream of bytes. Another, even more common pair of traits, is "opening" and then "closing" something.
All of them can be described using interfaces / traits to clearly communicate which sets of operations are applicable to which objects.
This e.g. can be neatly used to describe the "many things are a file" idea:
File passwords_file = Filesystem.make("/etc/passwd");
Readable password_readable = passwords_file.openRead(); // Could be openWrite().
Process zcat_process = Processes.make("zcat /tmp/something.gz");
Readable zcat_stdout = zcat_process.stdout.openRead(); // Can only be openRead().
ClientSocket sock = Network.makeClientSocket(host, port, options); // Unlike a file.
Readable sock_readable = sock.openRead();
for (Readable r in [password_readable, zcat_stdout, sock_redable]) {
byte b = r.read(); // Read one byte from each, no matter what it is.
}
But this would require a very different language, way more powerful than C (but also not C++ please). Unlike in 1969, now we have languages like that, e.g. Rust and ATS-lang. Likely we need another 10-15 years for a viable, somehow widely used OS kernel written in such a language to emerge.Rust has this built-in (lifetimes and move / borrow semantics); I suppose C++ can model this, too.
Windows does just that with their PowerShell. Here’s an example that copies a file remotely on the server:
Invoke-Command -ComputerName SERVER -credential USERNAME
-ScriptBlock { Copy-Item -Path C:\Temp\1.txt -Destination C:\Temp\2.txt }
Copy-Item cmdlet doesn’t require arguments to be files, it can copy some other objects too, registry keys, installed certificates, etc.Since traits / interfaces can't have their methods overridden, you don't need the dynamic dispatch, per-instance VMT, and such; you can have fixed offsets in a method table per class, both in userland and in kernel. (Some of the indirect calls can probably be made direct if the class is exactly known at compile time.)
> In Windows, you have 15 different versions of "read()" with sockets and files and pipes all having strange special cases and special system calls.
That's not correct. ReadFile can be used for all kinds of objects, including sockets: https://docs.microsoft.com/en-us/windows/desktop/api/fileapi... Yes, it behaves differently depending on the type of the object, but so does read(2) (E.g., you'll never get SIGCHLD when reading from a file, for example.)
In any case, he's very rash to call out Windows when Linux has its share of special-purpose syscalls that do the "same" thing (e.g.: send, sendv, sendmsg, sendfile, sendmmsg, …) with myriads of options to alter their behavior.
It also means that POSIX doesn't constrict you -- it gives you the tools to build rocksdb, sqlite, etc and have them be performant.
https://sqlite.org/howtocorrupt.html
It's a bad sign if you have to repair the shortcomings of a lower layer in your application.
Of course, disk drive protocols also constrict you, relative to having direct control of firmware and visibility over raw flash devices, drive head position, etc. For example, it would be neat if you could send block A and block B to the disk at the same time, only to have the disk compute the checksum of block A and put it at offset k of block B before writing block B.
POSIX I/O is like C. It's super powerful. It's everywhere. It's not going away. But it has sharp edges. And we can sacrifice a little efficiency on the small scale to grab huge gains in other areas like productivity and reliability.
Also relevant is Glenn Lockwood's excellent article on What's bad about POSIX I/O: https://www.nextplatform.com/2017/09/11/whats-bad-posix-io/
The resource fork was a beautiful idea; structured data built into the filesystem itself, and I wonder what the computing world would have looked like if it was used by the dominant operating system of the Internet instead of a sideshow.
Or operating on directories instead of files, like MacOSX bundles (like .app and .rtfd)?
They’ve both got their place IMHO and vive-la-difference :)
http://www.acontinuouslean.com/2013/04/05/a-better-way-to-sc...
You won't get Crysis running out of it.
"But what would you _do_ with them? What would be the advantage as compared to the current situation?"
Here is one answer (2008):
"This paper presents PipesFS, an I/O architecture for Linux 2.6 that increases I/O throughput and adds support for heterogeneous parallel processors by (1) collapsing many I/O interfaces onto one: the Unix pipeline, (2) increasing pipe efficiency and (3) exploiting pipeline modularity to spread computation across all available processors. PipesFS extends the pipeline model to kernel I/O and communicates with applications through a Linux virtual filesystem (VFS), where directory nodes represent operations and pipe nodes export live kernel data. Users can thus interact with kernel I/O through existing calls like mkdir, tools like grep, most languages and even shell scripts. To support performance critical tasks, PipesFS improves pipe throughput through copy, context switch and cache miss avoidance. To integrate heterogeneous processors (e.g., the Cell) it transparently moves operations to the most efficient type of core"
Sounds pretty good to me!
https://research.vu.nl/en/publications/pipesfs-fast-linux-io...
This results in systems being built ontop of narrow file-as-everything service, providing a wider interface to real data(events,sockets,pipes,messages,async IO).
Of course, people don't like it and build libraries to bypass it(and even the kernel layer itself https://blog.cloudflare.com/kernel-bypass/ ) just because the interface is inherently limited and inflexible.
Not as fun as a kernel module, though :-)
On Linux? You `open()` a directory, and `getdents()` takes that file descriptor as input.
There are a few (redundant/duplicated with minor feature differences in triplicate, 'cause it's Linux) file-ish abstractions over parts of those concepts, but those abstractions are neither the only, recommended, or most widely used means of accessing those functionalities.
I believe that Windows' HANDLE is closer to the correct abstraction.
* Closing the handle: Release any kernel resources associated with the the handle
* Comparing to other handles
* Duplicating, e.g. duplicating a handle to be used by another process. This allow a process to create a less privileged process and only pass handles with certain privileges to the process.
* Get/set handle flags, e-g- flag which indicates whether the handle will be inherited by child processes.
For each object type a number of object type specific operations can be used in addition to the above, e.g. file read/write for files or send/receive for sockets.
Regardless of whether a handle is for a file, a socket, window, mutex or something else, the generic functions such as close will always work.
Aside from waiting, I'd say passing/referring to the objects being operated on is also a commonality. Passing a FD to a child process, for example, or giving it (the object, be that a file/pipe/socket/timer/process/etc.) a name in the FS s.t. other things can refer to them by name. (I personally wish though that fork()/exec() had forced you to specify exactly the set of objects (files/etc.) for the child to avoid the entire multithreading/close-on-exec/atomic flag setting hell that exists today.)
I don't know that read/write are actually abstract at the level of a "file descriptor" though. Eventfds and timerfds both support them, but it feels forced. Pipes are one-way, so one of read/write don't make sense, and seek on pipe doesn't either. I think some file descriptors (child classes of a generic "object"/FD/HANDLE, such as files) support read/write, but not necessarily all FDs support read/write/seek.
from proc(5) :
/proc/[pid]/mem This file can be used to access the pages of a process's memory through open(2), read(2), and lseek(2)
Of course the abstraction maps varying degrees of well, but it also simplifies the hell out of the lion's share of the ways we interact with computers, and serves as a foundation for the rest.
https://en.wikipedia.org/wiki/Direct_Rendering_Manager#Rende...
Really it feels more like 'what is the hierarchical structure of my namespace' because once you nail that down, the file semantics become clearer. if its async io under the class of io its open("/io/async/my-thing", ...)
So its one of those yes.. but its so hard to nail it down moments.
> If you can read on it, it's a file.
Um, no. If you can SEEK on it, it's a file. If you can't, it's a socket or a pipe.
> In UNIX, a file descriptor is pretty much anything. You could say that sockets aren't remotely file-like, and you'd be right. What's your point?
The fact that you can't seek on a socket is irrelevant to the thread, which is about accessing files, not navigating them.
Sure, but that doesn't mean he doesn't occasionally make a mistake.
> In that message, he's talking about...
Yes, I know. But the larger context is Linus debunking (correctly) the unix philosophy that "everything is a file". Linus is correct: it is not the case, never has been the case, nor should it be the case, that everything is a file. But then he undermines his own argument with the (mistaken) claim that "if you can read it, it's a file." No. There's a salient difference between files one the one hand, and pipes and sockets on the other, and it has nothing to do with whether or not they have names. A named pipe is still a pipe, not a file. "Files" in /dev are not files, neither are "files" in /proc, despite the fact that they have names.
It's a detail, but an important one in the larger context IMHO.
Yes, the wording around "file" is a bit ambiguous, because Unix has a major design philosophy that said you can treat non files as files as get a lot of mileage, but didn't call those things "fauxles" or something instead.
It matched Plan 9 (which is really Unix V9) really well …
ioctl(sock_fd, SIOCSIFADDR, &ifreq_pointer);
is a thing, although it targets a socket on the interface, not the interface itself.Generally I think there's some cases where they try to push too much through limited interfaces, e.g. ptrace feels like "ok, we have an API already, lets push this unrelated functionality through it too so we don't have to design and add a new one"
If we're cheating by using file descriptors instead of files, then you could go all the way and used AF_NETLINK sockets, they allow you even to set routing or firewall. That's kind of not the point.
Aren't netlink sockets files, and used for setting IP addresses?
Kill? Possibly kill -9?
The same can be said for files in '/dev/input'. Why are mouse and touchpad input exposed as files?
In the email you quote, Linus gives two reasons why futex and sockets should not be files:
> there's absolutely no point in opening /dev/futex from a shell script or similar, because you don't get anything from it.
> Perhaps because you cannot enumerate sockets and pipes?
It stands to reason that the converse of those _are_ reasons to make things a file:
I can open /dev/input/$X and get something from it. The normal thing to do is open a file under /dev/input/ and read data from it. No, we don't usually do that directly, because libinput does it for us; but that's what it's doing. As an exception, if code deals with joysticks, it seems to me that it's common to open /dev/input/js$X yourself.
I can list the entries in /dev/input/ and enumerate the input devices attached to the system.
That's because only messages in which he is yelling at someone get posted here. AFAIK, most messages he posts are neutral, but these are boring, so they don't get posted here. I just scrolled through LKML and found a random example of his normal tone (https://www.spinics.net/lists/kernel/msg2852881.html):
"So none of the patches looked scary to me, but then, neither did earlier versions.
It's the testing that worries me most. Pretty much no developers run 32-bit any more, and I'd be most worried about the odd interactions that might be hw-specific. Some crazy EFI mapping setup or the similar odd case that simply requires a particular configuration or setup.
But I guess those issues will never be found until we just spring this all on the unsuspecting public.
Linus"
You're quiet right that Mr. Torvalds is not in some permanent state of rage and does not respond inappropriately to all, maybe even most, messages on the lkml. But the fact remains that he and thus his project have a serious problem with hostility. I could understand flipping out on someone who was paid to do a job and didn't even try, someone who was deliberately introducing bugs, etc. But a simple disagreement between highly intelligent and dedicated FOSS developers never calls for this sophomoric behavior.
Example https://www.phoronix.com/scan.php?page=news_item&px=mty1mza
Glass door estimates Kay is presumably paid 80-160k for this work and people have somewhat a right to be angry if code like this is pushed.
Almost all organizations are highly dysfunctional...and in my experience particularly the ones that are intolerant of passionate discussion.
This kind of out of context discussion that gives rise to comments like yours seems far worse than anything he has said.
How many CEOs have managed companies out in the open for 15 years plus without ever losing their cool? There is no way to know as there is no transparency.
However, your attitude is kind of what Linus intends to instill in those easily deterred by such behavior. He's not interested in your contributions if you're going to be a thin-skinned child about the development process and ongoing maintenance. Your contributions won't be perfect, and he's not interested in having to waste time beating around the bush in telling you so.
"... and a black star for being stupid"
Think about it this way: A dictator has to be extremely assertive because if he said "No, I don't want that in Linux" with no basis, he'd eventually lose his dictatorship power as people would form their own "unions" to try to change things, making several directionless forks of Linux. If he instead said, "This is a completely idiotic approach and anyone that thinks it's okay is braindead," nobody would question it and most people would just take his word for it. Most heated debates have an equal number of supporters for each side, and it takes someone with a strong voice to remind them that one decision must be chosen regardless.
Lying about things and people is a bad way to force people to accept decisions. Calling someone or something stupid isn't a technical argument, it's a poorly worded conclusion.
Just a hypothesis; I've never met either one and never been a BDFL either.
I can't speak to how Linus's personality has changed over time, but for a 27 year old software project, I'd say it hasn't impacted sustainability.
God help you if you'd ever grown up working on farm equipment.
Some of the other comments here have mentioned, but it bears repeating: this is not the "normal" Linus. He doesn't rant 100% of the time, but when he does, you had better pay attention because it must be something very important.
Most people are never forced to deal with enough people, to regularly be forced into extended contact with this particular kind of person. The kind of person who is forced to deal with enough people that they are likely to inevitably, eventually have to work with such people, is what we usually refer to as "a politician." But that's not quite accurate.
See, elected politicians learn to hide their distaste for such people, and that's how we get our sense of what it means to "act like a politician." But founders, kings, and other such benevolent-dictator-for-life are still politicians—they have to hold court taking the full spectrum of opinions from the brilliant to the idiotic—but they don't usually bother to hide this distaste.
We have no equivalent word for someone forced to do what a politician does, but without the same incentives to put on a face and pretend they aren't hating some parts of their job.
At the end of the day, most of the angry rants are about high level or influential people breaking kernel mantras. Don't break them, especially when you should know better. I'm impressed by his level of self control honestly, when I imagine the constant stream of horse shit he probably has to deal with on the daily.