32 ms·
Rust support in the Linux kernel
- perryizgr8 5y agoWhy not make a kernel in rust from scratch? That will be much more exciting and useful.
- steveklabnik 5y agoThere are people doing that as well. There are many, many people in the world, working on one project does not preclude others from working on other projects too.
- adenozine 5y agoIs there a GNU rust yet?
- ape4 5y agoI think Hacker News - or at least the many posts and positive comments about Rust here were a factor in this milestone.
- littlestymaar 5y agoLinus Torvalds and his friends are indeed well known for setting the project roadmap from things they read on HN…
- unixhero 5y agoOn a tangent, does Linus have a user here?
- smoldesu 5y agoIf he does, I'd be switching to BSD
- JCWasmx86 5y agoWe should add blockchain to the linux kernel ;D
- questiondev 5y agoturn every linux computer into a component of a supercomputer
- NextHendrix 5y agoWill be interesting to see how much compile times suffer once rust starts being used more heavily in the kernel. In my gentoo days I remember the compile time for firefox suddenly going up from 20 minutes to several hours which left a sour taste in my mouth with regards to rust. Has there been much improvement in compile times in the past ~2 years?
- Ericson2314 5y agoInsofar that it is a bunch of driver "leaves" for the forseable future, it should more embarrassing parallel.
- adgjlsfhk1 5y agoTLDR, yes https://blog.mozilla.org/nnethercote/2020/09/08/how-to-speed-up-the-rust-compiler-one-last-time/ https://blog.mozilla.org/nnethercote/2020/09/08/how-to-speed...
- swsieber 5y agoRoughly dropped by about 30% or more? Here's a dashboard that tracks times of certain benchmark tasks by compiler version: https://perf.rust-lang.org/dashboard.html https://perf.rust-lang.org/dashboard.html Additionally, I would expect that the kernel would mostly avoid things that drive up compile time - generics and macros. And as someone else mentioned, things should be able to be compiled in parallel. Also, some crates for firefox are absurdly huge in terms of compile times - they are definitely outliers (IIUC). (Edit: I was thinking of this issue in Servo, so not definitely firefox releated: https://github.com/servo/servo/issues/1799 https://github.com/servo/servo/issues/1799)
- oDot 5y agoIs Rust truly the first good candidate for Linux's second language? Why didn't older languages get this far?
- goalieca 5y agoWe have to rule out any language with a garbage collector. C++ adds about as much negative as positive to be worth while. That doesn’t leave many other options.
- sanxiyn 5y agoC++ would be a clear win on net. Anyone thinking otherwise, even if they are Linux developers, are wrong.
- loeg 5y agoIt’s fine to have opinions, but you’re stating them as if they’re fact. The Linux kernel maintainers disagree with you. They’re experienced engineers, and ultimately, they make the rules.
- sanxiyn 5y agoC++ is the industry standard, C is a retrocomputing language. Everyone is using C++, except for legacy codebases and some recalcitrant FOSS maintainers. Of course Linux is maintained by Linux maintainers, I am just pointing out they are against industry consensus.
- adgjlsfhk1 5y agoThe industry isn't typically writing kernels.
- sanxiyn 5y agoWell, Google is writing a new kernel (for Fuchsia), and it is written in C++.
- newaccount2021 5y agoThis will end the moment Linus has to review a giant kernel patch and realizes he has no idea what he is reading. As awful as C is, there is real value in keeping kernel development limited to one language. If people really want a Rust kernel, try Redox
- PoignardAzur 5y agoRust really isn't that hard to read. The syntax is pretty close to C, and there are very few invisible rules. You need to learn language concepts like '?', derives, traits, dyn traits, etc, but they're all fairly straightforward. Rust's big barrier to entry is learning to write code that passes the borrow checker, but that's not a concern when doing code reviews.
- khuey 5y ago> Rust's big barrier to entry is learning to write code that passes the borrow checker, but that's not a concern when doing code reviews. Rust code is actually easier to review in that regard because (unless the code contains unsafe blocks) the reviewer can skip thinking about most aspects of memory management.
- panick21_ 5y agoTime moves on, its of value to be conservative with new languages but it also dogmatic to say it should always only be one. Yes having one has value, but having more then one also can have value. Rust has reached a level of acceptance and adds huge value that it is worth it for the future.
- nicoburns 5y agoWhat makes you think Linus won't learn Rust? I believe he's said that accepting Rust into the kernel will involve key maintainers learning Rust, and that so far they seem cautiously open to that.
- newaccount2021 5y agohe may think he knows Rust until he gets his first whiff of real Rust line noise. to be certain, line noise in C is probably something he sees every day as well, but he also has decades of experience to help him filter it it seems inevitable that the same counterarguments he used to decline C++ will eventually be trotted out again. it is disappointing to see kernel devs be taken in by the Rust Hype
- fxtentacle 5y agoIt's only Linux-next. "This does not mean we will make it into mainline, of course, but it is a nice step to make things as smooth as possible." https://www.phoronix.com/scan.php?page=news_item&px=Rust-Hits-Linux-Next https://www.phoronix.com/scan.php?page=news_item&px=Rust-Hit...
- fbanon 5y agoTime to fork I guess.
- howdydoo 5y agoAm I out of touch? No, it's the linux maintainers who are wrong.
- fbanon 5y agoMost Linux maintainers don't want Rust.
- drexlspivey 5y agoGood luck with that
- sophacles 5y agoWhy?
- infogulch 5y agoOh neat, they mention that godbolt now has (preliminary?) support for: * Compiling via rustc, mrustc, gccrs, rustccggcc * Outputting MIR, macro expansion stages https://godbolt.org/z/5767rMa33 https://godbolt.org/z/5767rMa33
- Bayart 5y ago> rustccggcc Now that's just taking the piss.
- deleted 5y ago[deleted]
- dkm2 5y agoand also HIR in the very near future (next refresh of the live site): https://github.com/compiler-explorer/compiler-explorer/pull/3147 https://github.com/compiler-explorer/compiler-explorer/pull/... If you have any idea of feature, don't hesitate to open an issue ! :D
- zozbot234 5y agoToo bad that only x86-64 output is supported out of the box. There's no real reason for this, other targets work just fine but you need to place e.g. `--target=riscv64gc-unknown-linux-gnu` or even `--target=wasm32-wasi` in the compiler options input. C/C++ doesn't have this issue, it's specific to Rust.
- dkm2 5y agohttps://github.com/compiler-explorer/compiler-explorer/issues/3165 https://github.com/compiler-explorer/compiler-explorer/issue... :)
- Tobu 5y agoIf anyone had trouble parsing rustccggcc, it's rustc-cg-gcc, ie https://github.com/rust-lang/rustc_codegen_gcc https://github.com/rust-lang/rustc_codegen_gcc
- ahurmazda 5y agoA very helpful summary from r/rust on the same topic [1] >A few notes for people who haven't been tracking the Rust-in-kernel situation. Drivers especially have been targeted for a few reasons. First, drivers are isolated, with abstractions that don't require interaction with the rest of the system. Second, Linux is available on more systems than the Rust compiler has been ported to. Because drivers are inherently system-dependent, it is not an issue to introduce a dependency on rustc on compatible systems. Third, bugs tend to arise more in drivers than other parts of the codebase, so Rust can do the most good starting there. [1] https://www.reddit.com/r/rust/comments/rb50yn/comment/hnmshsw https://www.reddit.com/r/rust/comments/rb50yn/comment/hnmshs...
- Waterluvian 5y agoSeems like a brilliant fit for introducing Rust to Linux kernel.
- vlovich123 5y ago> The GCC backend for the Rust compiler (through `libgccjit`, although used for ahead-of-time compilation) was merged into upstream Rust: https://github.com/rust-lang/rustc_codegen_gcc https://github.com/rust-lang/rustc_codegen_gcc If the backend keeps progressing, we hope to soon be able to start experimenting with compiling the Rust side of the kernel with GCC! This means that using it for the core parts may be feasible sooner rather than later, no? Developing those abstractions may not be a priority of course, but it might be allowable at least from a platform support perspective.
- kibwen 5y agoEven once Rust has first-class support for GCC as a backend, I suspect that supporting the long tail of more obscure platforms will be an ongoing process. And for exceptionally weird platforms (e.g. where a byte isn't 8 bits) Rust may never bother to contort itself enough to support those, although perhaps Linux also doesn't support such platforms?
- JoshTriplett 5y ago
- corbet 5y agoKernel Maintainers Summit discussion on merging Rust support (September): https://lwn.net/Articles/870555/ https://lwn.net/Articles/870555/
- jancsika 5y ago> That should be in a .h file somewhere. Remember, don't put #ifdef in .c files please. Why?
- coldpie 5y agoRead the replies :) https://lkml.org/lkml/2021/12/6/1683 https://lkml.org/lkml/2021/12/6/1683
- vlovich123 5y agoThat's a confusing conversation that I still don't understand. 1. "Don't put ifdef" 2. "Why?" 3. "Put this other ifdef"???
- coldpie 5y agoIt keeps the code flow, which lives in the C file, easier to read. You can assume the function does the appropriate thing for the given configure situation without having to keep track of all the compile-time conditionals as you scan the implementation.
- jensarv 5y agoYeah the other ifdef goes in the header file
- jfindley 5y agoThey aren't saying "don't use ifdef", they're saying "put the ifdef in the header instead, because it makes the implementation easier to read"
- Aissen 5y agoFor those that prefer, lore link: https://lore.kernel.org/lkml/20211206140313.5653-1-ojeda@kernel.org/ https://lore.kernel.org/lkml/20211206140313.5653-1-ojeda@ker... (it's maintained by kernel.org and is more official that lkml.org, which helped us a lot before we had an official solution)
- charcircuit 5y agoIs there a more modern interface like Github / gitlab / gitea? The one you linked doesn't support the markdown in the post and it's hard to see the changes since it's in like 20 different emails?s.
- lelouch11 5y agoI usually use the "nested" view: https://lore.kernel.org/lkml/20211206140313.5653-1-ojeda@kernel.org/t/#u https://lore.kernel.org/lkml/20211206140313.5653-1-ojeda@ker...
- gpm 5y agoIn this case, yes. Though it doesn't include replies (since this is just the staging ground the rust-for-linux devs are using) https://github.com/Rust-for-Linux/linux/tree/rust-next https://github.com/Rust-for-Linux/linux/tree/rust-next
- wheelerof4te 5y agoIf they stick to core and basic Rust features, then I can see this project succeeding. Types more advanced than Vec<T> should be avoided IMHO. Rust is a beautiful language when you can contain it's complexity to a minimum. Them it reads like safe C, just like it should.
- nybble41 5y ago"Types more advanced than Vec<T>" are inevitable. You need them to write safe abstractions for the rest of the kernel to use. Simplicity is a virtue, of course, but not to the point of limiting Rust to the equivalent of "safe C".
- wheelerof4te 5y agoThere was an opportunity to make Rust more like "safer C". Sadly, it's creators wanted a better C++ instead. Naturally, they have fallen into the same trap C++ did; they failed to make the language easy to read and write by introducing too much complexity.
- nybble41 5y ago> There was an opportunity to make Rust more like "safer C". Sadly, it's creators wanted a better C++ instead. Fortunately for us. Though calling it "better C++" is underselling Rust by quite a bit IMHO.
- kensai 5y agoThis is huge!
- questiondev 5y agothis would actually be a game charger to rust. considering the increase in the use for linux throughout the years
- dang 5y agoPast related threads: So You Want to Rust the Linux Kernel? - https://news.ycombinator.com/item?id=28826246 https://news.ycombinator.com/item?id=28826246 - Oct 2021 (324 comments) Rust for Linux redux - https://news.ycombinator.com/item?id=27939498 https://news.ycombinator.com/item?id=27939498 - July 2021 (204 comments) Linux Rust Support - https://news.ycombinator.com/item?id=27746130 https://news.ycombinator.com/item?id=27746130 - July 2021 (433 comments) Linus Torvalds on Rust support in kernel - https://news.ycombinator.com/item?id=26831841 https://news.ycombinator.com/item?id=26831841 - April 2021 (290 comments) An RFC that adds support for Rust to the Linux kernel - https://news.ycombinator.com/item?id=26812047 https://news.ycombinator.com/item?id=26812047 - April 2021 (261 comments) Linus Torvalds on where Rust will fit into Linux - https://news.ycombinator.com/item?id=26556459 https://news.ycombinator.com/item?id=26556459 - March 2021 (119 comments) Supporting Linux kernel development in Rust - https://news.ycombinator.com/item?id=24334731 https://news.ycombinator.com/item?id=24334731 - Aug 2020 (354 comments) Linux kernel in-tree Rust support - https://news.ycombinator.com/item?id=23800201 https://news.ycombinator.com/item?id=23800201 - July 2020 (491 comments)
- _josh_tree_232 5y agoThis introduces unecesseary complexity for very small, if any gains. People realize the cost of complexity only when it's too late. Also, evangelism is never right. I wish the Rust folks would be more sensible.
- nixpulvis 5y agoAnyone know what they are referring to by "... and simplified pointer wrappers"? I'd also be very interested to hear a Rust for Linux perspective on the current state of async Rust. I've been avoiding diving into it for years now, but I'm always looking to be convinced I should.
- shmerl 5y agoLooking forward to amdgpu modules in Rust.
- tialaramex 5y agoThis post lists ISRG (Internet Security Research Group) and Google as to be thanked in particular for financial support. I'm sure everybody reading HN knows who Google are, but ISRG are the not-for-profit behind Let's Encrypt among other things: https://www.abetterinternet.org/about/ https://www.abetterinternet.org/about/
- ThinkBeat 5y agoI wish they would start creating a new kernel from scratch in Rust. It is needed and will be more cohesive and take more advantage of the new language than stuffing it into Linux. There will be a lot to learn from it though. It will test the interop and cohabitation of Rust and C. Lessons learned will be unbelievably valuable for other efforts to mix and match them.
- funklute 5y ago> It is needed Why is it needed?
- ThinkBeat 5y agoI refuse to believe that WindowsNT, NextStep/macos, Linux/UNIX/BSD is all we can hope for in an operating system. WindowsNT is by far the most modern. Linux is a not terribly good copy of an operating system made to run on a PDP11. WindowsNT owes quite a bit of internal architecture from Vax. Just like there is constant experimentation and development of new programming languages there should be constant experimentation and development of new operating systems. Limits, metaphors, hardware, has changed to an extreme degree, there is no reason to stick with that made sense decades ago. :) Where is the Tesla Operating System, (well in something a bit new and fresh with some good ideas and a lot of problems)
- funklute 5y agoCould you give an example or two of something concrete that you don't think is sufficiently addressed by today's operating systems? In my day job I do data engineering, and I'm a long-time linux user. Multimedia stuff aside, I think it's been 8 years since last time I felt limited by the operating system. Granted, I don't do anything particularly low-level. But as a high-level "consumer", I experience the main issues with today's operating systems not to be technical capabilities, but rather user friendliness, flexibility, and standardised APIs. But I'm curious what the issues are from a lower-level point of view!
- jeofken 5y agoWould a transpiler written in GCC compatible C, compiling Rust to C, solve this issue forever?
- steelframe 5y ago> Would a transpiler written in GCC compatible C, compiling Rust to C, solve this issue forever? Solve what issue? If you're talking about the problem of, "Linux is available on more systems than the Rust compiler has been ported to," then I'm gonna say "no," because many (if not all) of the core issues that make Rust difficult to support well on various architectures (and hence why said support isn't in official Rust today) would also have to be solved by any so-called "Rust-to-C transpiler."
- jeofken 5y agoA transpiler would throw the types away before generating C code. It does not need to implement traits or any other rust features. Alternatively, LLVM byte code to C compiler would do the job, as rustc emits LLVM byte code afaik
- nullc 5y agoWill Rust in Linux be like my experience with rust in Firefox? In 2021 I've had 145 rust-panic involving firefox crashes.
- happy_path 5y agoIt seems learning Rust is a must. What would you say is the best resource for learning Rust if I'm only experienced in interpreted languages?
- marco_craveiro 5y agoI'd like to put forward a controversial opinion, if I may: I do not think adding Rust to the Linux kernel is a good idea; and I suspect this project will struggle as soon as the financial backing is removed. First, a bit of background: I am mainly a C++ and C# user space developer, so presumably despised by all camps involved. Secondly, I have no experience of kernel development whatsoever. Thus, take my comments with a large grain of salt. My argument is as follows. Every decision you make on a software project is akin to an intersection on sets of programmers. When you choose C, you take a small slice on all possible programmers; when you choose kernel development, you take a slice on the set of competent C programmers, and so on. The intersection of programmers that are competent in Rust _and_ in C _and_ in kernel development - including the interaction between the two languages, at a very low-level (because kernel-space is special) - must be astonishingly small. And herein lies an important problem. Let us posit that the kernel does gain a significant amount of code in Rust; the interaction between these two languages (read: friction) will become significant. Either the Rust people will break things for the C people, or the C people will break things for the Rust people. Those who like C but not Rust - presumably a large subset of the Linux C programmers, else one would assume they would be developing a kernel in Rust - will become alienated. Similarly, those who like Rust will be forced to spend a lot of time doing non-rusty things just to get Rust to work, and they too will not enjoy the experience. Finally, many of the sweeping code clean-ups the kernel experiences periodically will apply differently to Rust, if they apply at all - meaning it will be a second class citizen, barring some major investment to compensate for this. In the end, I do not think the problems will come from the languages involved per se but due to the complex technical and especially social interactions that this will create. It is, however, an extremely interesting project technically and I suspect that Rust (and maybe even the kernel) will benefit from it, though not necessarily in ways one would expect. As far as research goes, it is pretty cool.