10 ms·
An immutable operating system
- thinkpad20 13y agoI don't really know how feasible this is without pretty significant performance impact (esp. memory usage), but as a research project, it sounds fascinating. Go for it.
- augustl 13y agoMy thought exactly :)
- pmr_ 13y ago> don't really know how feasible this is And I suspect neither does the author. I looked at the previous project (OpenGL Renderer) which comes in at 250 lines of code and barely any functionality. The current project is has no code at all. I'm all for sharing ideas, but this is somewhat lacking. The design document touches on the memory model, but ignores all the other problems an OS has to solve (scheduling, networking, disk IO...).
- theseoafs 13y agoThe author is probably not even aware of those problems, and will hit a wall when he realizes his new OS has to deal with one of those issues -- and that's assuming he even gets far enough in his project to deal with scheduling or IO. Writing your first operating system is an especially challenging task even when you're not trying to revolutionize the traditional OS model. I don't suppose this project will actually go anywhere, though I'd be pleasantly surprised to be wrong.
- deleted 13y ago[deleted]
- jmpe 13y agoThe author could focus on an existing embedded RTOS and fork from there. Enough cherries to pick one.
- pmr_ 13y agoBut is he going to find one that follows his "all has to be immutable" approach? I somewhat doubt it. Do you know of any existing OS that works like what the author describes?
- jmpe 13y agoThe reason I posted the idea was to start with a system that is working and where you can forego the filesystem and other parts that are typically found on a full blown OS. It's not uncommon for an RTOS to dismiss the GC and leave it to the programmer. For example, there are discussions in the RTOS world to take a closer look at Rust (Google embedded Rust) which is why the terms "new OS", "GC" and "experimental" triggered my response to look over there for a starting point.
- augustl 13y agoThat is a very good idea. So far I've only been able to figure out EFI booting basics.. Which is the least interesting part. Do you have any concrete suggestions?
- scj 13y agoMy recommendation would be to modify an existing OS, like MINIX, to have two types of processes: mutable and immutable. That way some (not all) of the potential advantages can be tested without having to start from scratch.
- mtrimpe 13y agoI gave an un-conference talk at Clojure days Amsterdam called "Purely Functional OS" on this exact topic and we had an incredibly interesting discussion about the topic. The conclusion we kept coming back to is that it's technically not all that difficult to implement, but that to make it usable in the real world would mean that computers would have to get a lot more cautious about source vs. derived data. The main thing is that on the one hand it seems pretty feasible to store all meaningful data a user generates over the course of using a computer and building an immutable persistent OS on top of that. On the other hand though, when you think about doing this in the context of an actual computer as in use today you will very quickly run out of storage space. What is separating these two scenarios is that a lot of data is (deterministically) derived from source inputs, but in the current state of technology it's impossible to determine what is derived data which can be easily recomputed and what is essential data without which the current state could not be reached. I happened to just be reading this article on unikernels which coincidentally is something that would help get us a bit further along in that direction: http://queue.acm.org/detail.cfm?id=2566628 http://queue.acm.org/detail.cfm?id=2566628 P.S. When thinking about this one key concept is to realize that you could can do things like implement a 'torrent file system' where a file is just a torrent hash which can be requested and signal when (parts of it) become available.
- agumonkey 13y agoother sources about mirageos : http://www.infoq.com/presentations/mirage-os http://www.infoq.com/presentations/mirage-os http://decks.openmirage.org/qcon13#/ http://decks.openmirage.org/qcon13#/
- augustl 13y agoVery cool! "If you're the only one with an idea, it's probably a bad idea" :) Feel free to e-mail me, would be lovely to join forces.
- sehugg 13y agoin the current state of technology it's impossible to determine what is derived data that can be easily recomputed and what is essential data without which the current state could not be recomputable. Can you elaborate more on that statement? I see it as an expensive problem, but not impossible. If you have a completely deterministic VM/instruction set, you can recompute any function output from any set of inputs. If you have non-deterministic input (network, input devices, randomness, etc) you can store those inputs to replay at a later time. I don't know if it's always necessary to store non-derived data. Do you need to save all keystrokes? All mouse moves? All network packets? Probably not. If those network packets just result in displaying a graph on the screen, they can probably be thrown away. Maybe you can throw away the headers and just compute based on the packet data. Or maybe you can simply store the fact that a stream of data that matches a cryptographic hash was received. It depends on what function receives that non-derived data. So I think the difficulty would be designing a system that would isolate derived data and replayable/recomputable/refetchable data, and the processes that compute that data -- and do so with reasonable efficiency. I think this could be done at the process level rather than the instruction set level (though you would have to have a restricted instruction set -- i.e. limited floating-point).
- obblekk 13y agoI'm not sure how this would look very different from current pure functional languages. Think about programming in Haskell. Everything is immutable but you can compile down to machine level binaries. So at some point the programmer is presented with an abstract immutable model and under the hood some runtime does real pointer arithmetic and all. Even garbage collectors could be optimized already for knowing that the programmer has no knowledge of memory locations. If this kind of OS encourages hardware changes, that's one thing. But aside from performance, it probably won't look too different from current FP languages.
- thinkpad20 13y agoHe's not designing a language; he's designing an operating system.
- chongli 13y agoThe GHC RTS (used in most Haskell programs) is practically a mini-operating system already.
- eloff 13y agoAn operating system whose main goal is not performance is forever going to be a toy of professors. Linux is a mess compared to the beautiful code that would comprise this OS, but it's a mess that runs fast on real hardware and let's people get stuff done. That matters.
- jrockway 13y agoThat doesn't really matter if the idea is to experiment.
- stcredzero 13y agoAs I mentioned elsewhere, such an OS could have important performance benefits. GC could be made to be incremental at a fundamentally new level. In fact, incremental GC could be nothing more than a series of defrag copies that proceed at a rate just faster than new object creation. Such a system would rock for writing real-time systems.
- vinkelhake 13y agoImportant performance benefits compared to what? Systems that are very performance sensitive typically don't use garbage collectors to begin with. They instead rely on techniques to avoid generating much garbage in the first place.
- stcredzero 13y agoYou're making my point for me here. This kind of technology might make it possible to write even more performant soft real-time systems but still have the productivity benefits of GC.
- vinkelhake 13y agoI don't think I am. Trading performance for productivity is completely different discussion. It sounded like the claim here was that immutability in the OS (whatever that means) might result in a system with better performance. We have programming languages where everything is immutable (Haskell). This results in programming techniques that generate a lot of garbage. We have not seen that this results in programs with better performance than those that do not generate garbage to begin with. Why would it be different in an operating system?
- stcredzero 13y agoA garbage collector that knows that all values are immutable will be rather interesting, I think. Typically, a garbage collector will stop the world (i.e. halt execution) to do heap defragmentation of the old generation. When all values are immutable, though, you can defragment the heap by copying a value to another fragment and just swap the internal pointer to the value. This might actually have significant performance benefits. When everything is immutable, GC can also be inherently incremental. You just do your defrag copy faster than new object creation. Then you cam limit your stop-the-world to a small "catch-up" so your copy-from can become a copy-to. Incremental GC nirvana!
- Someone 13y ago"When all values are immutable, though, you can defragment the heap by copying a value to another fragment and just swap the internal pointer to the value." Wouldn't that turn shared objects into not-shared objects? Theoretically, that doesn't make a difference in a system without mutable data (assuming you leave out 'identity check', too), but in practice, it likely will blow up memory usage tremendously. Edit: I think the way around this is to replace the moved object with a "this object moved" object. The trick, then, will be to know when it is OK to discard that "this object moved" object. That probably is the case after a full heap scan.
- brandonbloom 13y agohttp://en.wikipedia.org/wiki/Cheney's_algorithm http://en.wikipedia.org/wiki/Cheney's_algorithm Is quite common in systems and uses "forwarding pointers".
- rurban 13y agoAgreed. The potion/QISH implementation of the two-finger cheney loop is extremely efficient even without register values (volatile), typically 3ms pause time on a mid-sized heap. Compare that to typical java or ruby pause times, starting from 25ms to typically 150-250ms. You need more memory though, as in most lisps it's using copying, i.e. compacting, not just simple mark&sweep. Incremental is doable, but you need to add GC state then, which is a bit tricky in threads. Actually libgc is pretty good.
- mostly_harmless 13y agoYou mention that one of the benefits would be that memory can be shared across processes without any defensive copying or protection semantics, but isn't the entire idea that immutable values are a special type of defensive copying and protection semantic? I imagine that this would be useful if doing many calculations on readonly values, but would take a performance hit for readwrite operations. I'm not one for purely functional programming, but this seems like an interesting concept. I'm interested to see where it goes
- augustl 13y agoInteresting definition of immutable values, and a valid one. My perspective is different. An immutable value has a value add more than that of avoiding defensive copying, such as structural sharing. When you add a key to an immutable map, the new map can point to the old. It has become more and more common to model systems with append-only as the only form of write (Event Store, Datomic), so readwrite can probably be avoided in some cases. And things like IP packets certainly makes sense to represent immutably - anything else is a bit of a lie :) But there is certainly a risk that the trafeoff of immutabulity becomes too costly for an OS.. Also, the system language will not be pure, like Haskell. Just immutable values, like Clojure :)
- hardwaresofton 13y agoJust curious have you started looking into some of the LISP machines of old? You might be able to get a head start by studying their structure (and of course their decisions): https://en.wikipedia.org/wiki/Lisp_machine https://en.wikipedia.org/wiki/Lisp_machine
- _delirium 13y agoThere are definitely interesting things there, but fwiw Lisp machines weren't based on immutable data structures. Common Lisp in general has an ethos of being multiparadigm and using imperative updates whenever convenient or performant. Functional constructs are probably used more than in C-like languages, but not exclusively, and are probably a minority approach in "production" Common Lisp. That's one place where Clojure differs quite a bit from CL; it sort of combines the "Schemey" preference for functional style, non-destructive functions, recursion, etc., with the CL ambition of a "batteries included" library and industrial-strength tooling. However if you look at the first-order similarity as not being immutable data structures, but instead the idea of an OS entirely built within a managed runtime, the Lisp Machines and Microsoft's Singularity OS (C#) are two interesting examples.
- augustl 13y agoOp here, thanks to both of you :) I would very much like to expand prior art to more than just Linux and Clojure.
- puredanger 13y agoMaybe consider Fressian for EDN-like bytecode format...
- augustl 13y agoAh, thanks. When I said EDN, I meant Fressian :)
- RivieraKid 13y agoI've always been baffled by Clojure's view on state. It seems like just a rename of the concepts present in most languages today. Ie atom is mutable variable and value is an immutable value. What's the novelty here?
- rplacd 13y agoThe sole fact that one has to reach over themselves and make a great deal to invoke it when thinking within Clojure's mechanics - they become neither cheap to mentally fiddle around with, nor actually implement within. (FWIW, though, Clojure's novelty to me was an STM system that I could get up and running without a night's worth of tweaking, and otherwise fall safely into a great deal of attention if something were to go hilariously wrong - most of the other solutions around "back then" seemed to regard themselves as research curios lagging behind in fit and finish.)
- cscheid 13y agoRelated, a purely functional package manager, Nix, and a Linux distribution based around it: http://nixos.org/nix/ http://nixos.org/nix/
- agumonkey 13y agoI see a number of projects sharing similar traits: - DVCS - btrfs,zfs - rethinkdb - persistent datastructures (cons cells, fp trees) - nix package management, virtualenv, containers - react/pedestal (pushing ux delta upgrades)
- cfallin 13y agoMutability/immutability goes pretty deep philosophically... all of those projects are basically built on persistent data structures, but persistent data structures can be seen as just one type of "making time explicit". In other words, with mutability, a variable (or data structure) takes different values at different times, while with immutability, you can still have time but you name each version through time explicitly. (Values vs. variables, etc.) Same concept exists in e.g. single static assignment (SSA) in compiler IR, or register renaming in high-performance processor design... pretty powerful concept.
- imsofuture 13y agoAs an aside: I'm pretty mind blown that I've never once considered immutability as "making time explicit". That's an extremely apt comparison.
- agumonkey 13y agoHow could I forgot SSA. The idea here is what about re-expressing things by pushing immutability at lower level as a common base.
- optymizer 13y agoThis idea reminds me of what Go is doing with their channels to solve concurrency issues: they're essentially sharing data by copying the data. Copying data is slow and that's why Go's channels aren't the fastest solution, but they're less complex than dealing with the traditional concurrency issues. I've written a toy kernel and I just can't imagine copying all process data because 1 little thing changed. However, there's no reason not to pursue this idea, as it may prove to be useful in certain cases. If real-time schedulers have their place, why wouldn't such an OS have its uses? I think Go (and other projects) have proved the concept works, so maybe it's time to see an OS? Best of luck to you and I hope to hear good news in the future!
- raganwald 13y agoIs it copying all process data? Or copying a reference to the process data and then performing copy-on-write when a process makes changes locally?
- masklinn 13y ago> they're essentially sharing data by copying the data. No. Go only copies the immediate values, if you send a pointer the pointee is shared for instance. Go's concurrency is shared-memory. Erlang copies (almost[0]) the data sent between processes, and has process-local heaps. [0] binaries above 64 bytes (IIRC) are refcounted and shared.
- augustl 13y agoThanks a lot :) I cannot imagine that the web will ever work on this OS.. How do you implement a mutable system (JavaScript) with an immutable core? So it's definitely not for everyone.
- sehugg 13y agoWhen you fork() a process you don't have to copy all process data either, thanks to copy-on-write semantics.
- billsix 13y agohow would a user interact with such a system?
- ams6110 13y agoSort of a sidebar: The term "atom" doesn't seem to have the same meaning in all languages. Atoms in Clojure are reference types, and they are mutable in a controlled way (they can be changed to refer to another immutable value). In Erlang, an "atom" doesn't refer an immutable value, it is the immutable value. An Erlang atom by definition cannot ever be any other value.
- bjackman 13y agoAwesome! You should have a look at Urbit: http://www.urbit.org/ http://www.urbit.org/
- melloclello 13y agoComplimentary Loper OS link, too: www.loper-os.org/?p=284
- DougMerritt 13y agoThere appears to be no "About" on that site. Who knows what on earth it is? On the left sidebar, the "documentation" link is to a video. No thanks, I'm look for a sentence of text. The next link down is a 404 error. The community link is for insiders...lots of comments about people leaving the building,whatever that means. Bottom of page, how to install. Why am I installing something when I don't know what it is? Sites that expect you to already know what they are about, and do not deign to give so much as a sentence of explanation, are extraordinarily frustrating.
- urbit 13y agoSorry our site sucks. We released accidentally and are more or less in "semi-stealth mode." You probably shouldn't be interested yet. Unless you like playing with semi-broken stuff. When it's not broken we'll let you know. Urbit is indeed a purely functional OS, not super dissimilar to the OP's project. And it works at least well enough to run a chat server on its own network (which generated all those logs with "leaves the building"). But we ship no code before its time and we probably shouldn't even have a site up. You'll enjoy the video though - it has good music, at least.
- DougMerritt 13y agoThat's fine -- but please add an "About" link that says what "urbit" is. That lack of explanation, that expectation of speaking to insiders, is unfortunately very common on web sites, not just yours. Please add the About explanation even if you decide to take the site offline. At least that way, it will already be ready, later, when the project is further along. I was just reading about the defunct House functional OS yesterday, coincidentally, so I'm interested in the general topic.
- procrastitron 13y agoI wrote an operating system in a purely functional dialect of Lisp; http://losak.sf.net http://losak.sf.net There are a few things I learned in the process that I think are relevant here: 1. Forget garbage collection in the sense of any variant of mark-and-sweep. For an operating system latency is more important than through put, so you really want real time memory management. If you use reference counting, then there is a lazy variant that gives you just that; no pauses due to reclaiming free memory. The downside with reference counting is that it doesn't work with cycles in heap-allocated memory, but if your data is all immutable then you can prevent cycles from being created in the first place. 2. Treat mutable memory as a form of I/O. Even if you just want to use memory mapped I/O, you will need some way to read and write to (some portion of) memory. Set aside a fixed block of memory (say, for instance, the first 10 MB), and only allow that memory to be read and written in an imperative fashion. Keep the managed heap completely separate from that mutable block, and don't allow any direct access to the managed memory. 3. You can actually perform preemptive multitasking entirely at compile time (or at program load time for apps not included when you build a binary for your OS). I've done this for both my OS and for Scheme (https://github.com/ojarjur/multischeme https://github.com/ojarjur/multischeme). It works extremely well and winds up being much faster than using the native primitives usually used for building multitasking support. For more details on exactly how to do it see the link to my Scheme implementation. 4. The biggest difficulty the author will hit, and the most likely cause for performance issues, will be in code generation. Since the proposal is for a new bytecode, the author will have to implement their own interpreter and/or JIT compiler for it, and writing an efficient one is an extremely large chunk of work. I've built an operating system and a programming language, and the language is by far the harder project. This is why I went from working on a new OS written in a new language to re-implementing my compile-time multitasking technique for Scheme; it allows me to take advantage of all of the hard work people have done to make compilers for that language which produce fast code.
- augustl 13y agoAuthor here. The language is the part I also dread the most, and is also the part that will be the least unique and the least interesting to "re-invent".. I'll look into finding an existing language that runs on bare metal and that has (or supports) immutable values.
- efnx 13y agoWhy make the system language a Lisp instead of a language that is by default immutable? I'd think Haskell is a shoe in for something like this and you'd have a head start with House: http://en.wikipedia.org/wiki/House_(operating_system) http://en.wikipedia.org/wiki/House_(operating_system)
- augustl 13y agoPersonally I'm more of a fan of immutability than purity, which is why I haven't considered haskell. As mentioned in the post, though, I'm not sure if the language should be static or dynamic or something else.. And I don't really want to invent my own language either. Food for thought :)
- codygman 13y agoPure functions would let many of your functions become immutable :) EDIT: Well... not really I guess. But idempotence has similar properties I think.
- thinkpad20 13y agoI don't know much about Clojure, but I understood that it is a lisp and default immutable... so wouldn't that work?
- DanBC 13y agoIs there a list of research / alternative operating systems anywhere? I don't know how an OS would qualify to get on the list other than not DOS, Windows, OSX (or any of the Apple OSs), Linux (especially not 'ubuntu with a different DE'), or the BSDs (i guess there are exceptions if they're on a toaster).
- FrozenCow 13y agoI was making a list of a few I knew, but it would be better to just check wikipedia: https://en.wikipedia.org/wiki/Comparison_of_operating_system_kernels https://en.wikipedia.org/wiki/Comparison_of_operating_system... Those are more serious kernels I think. There are also a ton of research-related kernels. I guess you can find a few for some programming languages.
- jonjacky 13y agoHere is information and links about some unusual operating systems, including several discussed above. https://github.com/jon-jacky/Piety/blob/master/doc/precursors.md https://github.com/jon-jacky/Piety/blob/master/doc/precursor...
- tekknolagi 13y agoSo how do you load this into a VM?
- augustl 13y agoThe makefile builds a virtualbox image. But it doesn't do anything interesting yet. I didn't submit to HN, the project is a long way away from being demoable and testable.
- timclassic 13y agoI haven't written any Clojure, but I have written a good bit of Erlang. My understanding of the Erlang Virtual Machine tells me that it solves a lot of the problems you describe regarding immutable data. For example, per-process garbage collection due to immutability, message passing via copying data, etc. I think you would be well-served to experiment with and learn some Erlang to help inform your design. In fact, Erlang often feels to me like an operating system due to the independence of processes (and the multitude of tools built on top of it, but that's not directly relevant here). I've often dreamt of an Erlang Machine like the Lisp Machines of the past. As an aside, Erlang's primary goal is fault-tolerance. It's other properties, such as immutable data, message passing, and functional properties were all design decisions made to achieve this goal. My point is that your OS could be very well suited to fault-tolerant systems.
- augustl 13y agoI'm an Erlang noob, but afail the model is pretty different. I'm imagining a shared-everything system, where immutable values are freely passed around with no copying. Erlang is more of a shared-nothing system. Also, Erlang requires multiple machines to shine, but an OS is more about managing one machine. I do think message passing have a bright future, though, and my OS will not work at all in a shared-nothing manycore system..
- timclassic 13y agoI see. You are correct, Erlang definitely falls on the shared-nothing side if you ignore some uses of ETS and ref-counted binaries (binaries above 64 bytes, I believe). I disagree with the statement "Erlang requires multiple machines to shine," but my motivations, and my definition of "shine," are likely different from yours. Erlang only requires >1 machines if you are creating a system with proper fault-tolerance. In my opinion, it has good SMP support and it performs well for general-purpose applications. You wouldn't use it to implement matrix multiplication, though :) Anyway, the gist of my post is that the lessons learned from writing Erlang programs might be useful in your work. Good luck! I look forward to hearing about your progress.
- ihnorton 13y agoBut garbage collected memory of immutable values and atoms, in hardware? Hardware transactional memory might help here. http://en.wikipedia.org/wiki/Transactional_memory#HWIMPLEMENTATION http://en.wikipedia.org/wiki/Transactional_memory#HWIMPLEMEN...
- iElectric2 13y agoWe already have a purely functional linux distro that is immutable and stateless, called NixOS
- ij2bun 13y ago'Clojure has transients, which basically means "inside this function, use a mutable value under the hood while building up the value, but make it immutable before it's returned"' is this essentially a ... closure?
- augustl 13y agoTransients in Clojure is an added feature to the built in immutable values. Essentialy, they are immutable. But Clojure does have mutable-ish versions you can use to build up a semi mutable transient, and when you're done, convert it into an immutable value before it's returned. The key is to make it fast. Mutable -> immutable is not an O(N) copy.
- tkirchner 13y agoI really doubt the practical usefulness of such an operation system other than pure fun and skill development (and maybe some tools that fall out at the end...). Isn't the main purpose of an OS to bridge between the applications and the hardware? The hardware is pretty accurately abstracted as sth. with a state and input/output streams. What is the purpose of abstracting the hardware as sth. without a state?
- tkirchner 13y agoI really doubt the practical usefulness of such an operation system other than pure fun and skill development (and maybe some tools that fall out at the end...). Isn't the main purpose of an OS to bridge between the applications and the hardware? The hardware is pretty accurately abstracted as sth. with a state and input/output streams. What is the advantage of abstracting the hardware as sth. without a state?
- tkirchner 13y agoI really doubt the practical usefulness of such an operation system other than pure fun and skill development (and maybe some tools that fall out at the end...). Isn't the main purpose of an OS to bridge between the applications and the hardware? The hardware is pretty accurately abstracted as sth. with a state and input/output streams. What is the purpose of abstracting the hardware as sth. without a state?
- unfamiliar 13y agoCan someone tell me where I can find a primer on immutable vs mutable, state etc? I have tried to piece together an understanding from wikipedia etc but I'm not really "getting" it.