MotorOS: a Rust-first operating system for x64 VMs
github.com
github.com
> What does "Rust-first" mean here? It means not only that both the (micro) kernel and the drivers are implemented in Rust, but also that Rust is the first (and only, at the moment) language that userspace programs can be written in.
> Although technically one can reverse-engineer the Rust-based ABI and the provided Rust toolchain to write apps for Motor OS in e.g. C, that is some work. But standard Rust programs (using standard Rust library, without FFI) will just compile and run - see e.g. https://github.com/moturus/motor-os/tree/main/src/bin/httpd.
> This Rust-first approach is rather unique, as e.g. Redox uses relibc and C-based kernel ABI as the glue...
https://old.reddit.com/r/rust/comments/190znk5/mot%C5%ABrus_...
I’m never not going to welcome a hobby OS, especially in an interesting language (still have fond memories of House). By all means, go for it. Just... it’s important to be aware of the prior art here.
This is the way to go on platforms that favour shipping binaries instead of source code.
Outside Linux/BSD, stable ABI across OS versions is a concern, hence why Apple, Google and Microsoft platforms all offer ways to keep this going.
Shouldn't be much effort to make it compatible with Crablang, no?
/s
I see two main concerns raised here:
(a) long-term viability and support (b) compilers, binary compatibility, etc.
While the first concern is definitely valid, and without a community this project will not succeed, I do believe that potential benefits of Motor OS (or a similarly focused/structured project) will eventually result in a widely used new operating system. There are major problems with Linux inside VMs (and sometimes outside), and the Linux devs are not focused on this enough to clean things up anytime soon. I work on Linux Kernel at my day job, I know.
Re: compiler instability, binary compatibility, etc.: I'm sorry, I don't understand what is the issue here. The latest Linux kernel can be compiled with different GCC or LLVM toolchains on x86_64, and the result will happily run old binaries compiled years ago with who knows what. repr(C) structs in rust are stable... So why so many concerns here?
Again, thank you all for your comments and questions - I'm happy to answer more (at least until my day job kicks in).
Or is all the slowness in the host preparing the resources? (as in QEMU and KVM?)
So, it depends on the hardware, though you are unlikely to need more than 1 second on anything other than truly degenerate hardware assuming you are initializing devices in parallel.
That said, hardware passthrough/VFIO is likely out of the current realistic scope for this project. VM boot times can be optimized if you never look for hardware to initialize in the first place. Though they are still likely initializing a network interface of some sort.
“MicroVM” seems to be a term used when as much as possible is stripped from a VM, such as with https://github.com/firecracker-microvm/firecracker
As Niko Matsakis puts it, async/await is Rust in hard mode, you don't need that when having to also worry about everything writing an OS from scratch entails.
I’m not sure if these are blocking issues or not, thus my question.
If you are targeting a posix syscall interface, a lot of that doesn't really require async to pull off. You need to switch threads whenever an operation is blocked rather than run unrelated work on that thread. I suppose you can still model that with async, but it certainly doesn't feel as helpful.
File I/O will move to this model later (the current file I/O code is quite old and mostly a placeholder).
Very cool. Thanks for pointing this out.
The real question is, how useful is a non-C-compatible, non-Linux-compatible, VM-only OS. Maybe a little bit, for microservices?
"Software designed to control the hardware of a specific data-processing system in order to allow users and application programs to make use of it."
The question is how much Operating System is a software that delegates all "control the hardware" parts to the layer below.
I know there are wider definitions of OS, but my point is this is not going to replace Linux.
Without question projects like MotorOS are sill useful. Besides practical applications it's a nice idea. Just recently I wrote in another thread that I would love to have a glimpse into an alternative universe, where Pascal had won over C and everything was Pascal-based. The idea to have everything Rust-based is even more exciting.
I'm going to assume without looking at this project that observability and operability would be worse than it already is though, so I'm not in a hurry to move. Anyway, GCP means cost of compute is a rounding error compared to cost of bandwidth, so I have no reason to find the edge of efficiency.
My take on this question would be the ease of use for application developers. This ease of use consists of plenty of somewhat ready-to-use libraries that cover plenty of use-cases, huge community that both produces documentation and will answer questions should you have any, multiple hardware vendor support, and of course, licensing.
It's possible to compete with Linux in very special, very narrow use-cases, but trying to win against Linux on every front would require an insane amount of effort by a very large group of people.
Sure, you can do that and it will work exactly until the next change in the driver interface, which is not very long.
So you end up in maintenance hell and will still constantly be behind the curve, because Linux gets all the updates first. You will be less secure too, because you'll get the security patches later.
That being said, someone in a similar thread from a few days ago said one of the BSDs does that. Maybe it's not that bad.
AFAICT this could run on top of Xen, VMWare, or the hypervisor which runs Win 10/11.
Nintendo is using a custom OS but with a huge chunk of user space borrowed from FreeBSD. Sony on the other hand just went and forked FreeBSD outright.
You might also want to look into what OS are being used for server environments. A lot more BSD there than you might have initially guessed.
Same applies to clang/LLVM port to the Playstation, regarding everything that would expose console implementation details without an NDA.
So saying corps that use BSD code never give anything back because of license is not true. And an awful lot don't do any more or even hide their use of gpl licensed code anyway.
GPL works similarly to a patent pool: every participant sees that openly contributing to the pool is more profitable than being a renegade, as long as everyone else plays by the rules, too. MIT/BSD, while as open as possible, can easily promote a trade-secret type of environment, where any enhancements are never heard of, except under an NDA, and perish if their creators go under or lose interest.
unless it's a steamDeck, ofc. No love for consoles, though.
Also: the SteamDeck is by any reasonable standard a console. It just happens to run a windowed environment out of the box. Don't be that guy. If you want to pump Valve, focus instead on their contributions to the Wine project.
Are you saying that Arch gets its userspace and drivers from FreeBSD?
Any sources on this, and on what parts were borrowed specifically?
I was under the impression that Nintendo did away with most of the Unix layers we know and love and went all-in on custom code and APIs, is that not the case?
Having some BSD userland binaries doesn't make your OS a BSD. Otherwise Windows is just a fork of curl.
Docker and NixOS exist because of userspace problems with package management and serverless exists because businesses want to pay for compute on demand.
Yeah, this seems like it's more directly competing with those than Linux. I'd want to see those addressed in the "Why?" -- that is, why MotorOs instead of Docker, etc.?
It basically says it already:
> Motūrus OS is a microkernel-based operating system
By and large, microkernel and containers solve the same problem. Except, I wouldn't call containers a "solution", more like a workaround. Not in the sense that containers by themselves are a workaround, but the way they are used is a workaround for the same problem.
The way containers are used today, especially in the context of Kubernetes, is to finely slice the available physical resources. The orchestration allows to manage which part of the application gets what slice of the resource, thus attempting to cut down on waste that's typically generated in the world where resources are managed through VMs. Where the typical problem is that a single VM will require too many resources because of the bloated OS it needs to run and because it's hard to create VMs with very limited resources, since OSes usually come as a package deal.
So, containers "solve" the problem by giving up VM optimization -- instead it's usually beneficial to create very beefy VMs, on top of which then a new virtualization layer is created with containers. This minimized the VM waste, but doesn't get rid of it entirely, and, of course, creates a lot of complications with all the indirection resulting from two-tiered virtualization.
Microkernel is the opposite of this "solution" -- it's the attempt to make OSes more modular, and as such less demanding of resources. Ideally, in the world if microkernels you don't need containers (at least not for the thing they are usually used today): your VMs can slice the resources in the way at least as efficient as containers do (or, hopefully, even better).
So... to predict the next possible question: why containers are so popular and micorkernels aren't: it's because the later is harder on the applications (even when applications don't actually need something, they often use it because it's available in a full-blown OS, applications aren't usually written with resource scarcity in mind). Secondly, containers, essentially, exist on top of somewhat uniform, somewhat stable interface of Linux kernel. Micorkernel VMs would expose users to the zoo of ideas hardware vendors put into their products, making portability difficult. Finally, for all its flaws, Kubernetes is a big system with many (even if not so great) solutions for many problems. So, programmers who fear technology feel like it gives them a safety net and will allow them to program from a more comfortable position of modifying YAML files, copying the most upvoted answers from StackOverflow. There won't be such an easy cake in microkernel world.
> the kernel is very small and does not block, so does not need to be preemptible
I don't believe you and I don't even need to look at the code to know this is false.
// The scheduler.
//
// As the kernel supports wait/wake/swap, and no blocking in the kernel
// other than wait, any kind of more sophisticated scheduling policy
// can be implemented in the userspace (in theory; maybe tweaks are needed
// to make things perform well in practive).
//
// So the default scheduler here is rather simple, but should work
// for a lot of use cases.
//
// Priorities: see enum Priority
// Cpu affinity: a single CPU hint
// Sched groups: none: everything within a priority is round robin, so
// a process with many threads will negatively affect a process with few threads.
//
// This should be OK for most situations: if there is a need for isolation,
// just use another VM.
That's elaboration enough I think?That said, I would be thrilled to build this and other alt OSes and their userlands with Nix / Nixpkgs :).
Linux is not complex but there are some design issues with C ABI and glibc stability and symlinks.
I agree the goal posts make much of this complexity inevitable, but the solution is to stop trying to intersect everyone's objectives into a much narrower and daunting goal.
The big galaxy-brained goal should be:
1. Make more of Linux Rust.
2. Leverage Rust's superior expressive power to switch from a "configuration" mindset (Linux's current gazillion options on single giant code base) to a "composition mindset": we want to use types to combine various subsystems in various flavors.
3. Something like this and Linux proper can share lots of library code / subsystems. We can blur the line between "separate kernels" and "separate 'distrobutions' mixing and matching stand-alone Linux components".
I think this is the only sustainable way to reign in the accidental complexity.
But would be nice to backup your claims regarding performance with actual numbers.
Where do you see any unsupported claims re: performance?