LWN: Comments on "The kernel radar: folios, multi-generational LRU, and Rust" https://lwn.net/Articles/881675/ This is a special feed containing comments posted to the individual LWN article titled "The kernel radar: folios, multi-generational LRU, and Rust". en-us Wed, 17 Sep 2025 09:42:24 +0000 Wed, 17 Sep 2025 09:42:24 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/886709/ https://lwn.net/Articles/886709/ jd <div class="FormattedComment"> There are a variety of approaches to out-of-memory issues in different languages, and there has been quite an interesting on-and-off debate in computing about fault-intolerant languages (which can be useful because a program isn&#x27;t trying to limp on with an uncertain state).<br> <p> In a microkernel, where you might very well want a module to crash cleanly and get restarted, a fault-intolerant language would seem to make a lot of sense. Rust might well be ideal for writing modules in the L4 world. I&#x27;m not sure how it makes sense in Linux, although if the primary kernel developers say it does then there&#x27;s an excellent chance it does even if I can&#x27;t see it.<br> <p> There are other languages that might have value (or even more value) in the kernel, but they&#x27;re either hopelessly obscure or too difficult to find a 64-bit compiler for, and I seriously doubt there would be interest in yet another language until Rust succeeds/fails, the reasons are known and there are people who might credibly actually use such a provision.<br> </div> Thu, 03 Mar 2022 18:19:41 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/883908/ https://lwn.net/Articles/883908/ HelloWorld <div class="FormattedComment"> <font class="QuotedText">&gt; 2. In C++, std::bad_alloc is thrown, which is like the managed case except that stack unwinding will cause destructors to run (in the managed case, finalizers *might* run, but there is no guarantee of when they get called). If any of those destructors tries to allocate any memory, for any reason, it might cause a second std::bad_alloc to get thrown, and if a destructor throws an exception while another exception is already pending, the runtime gives up and calls std::terminate. Therefore, if you want to handle fallible allocations, every destructor in your entire program must be in on the joke.</font><br> <p> Well, most destructors don&#x27;t require allocation but do free up some memory. This means that when a bad_alloc is thrown, there&#x27;s a pretty good chance that by the time you reach a destructor that allocates, some memory has already been freed by a destructor that ran before, and so your allocation may very well succeed. There are cases where it&#x27;s better to try to recover from an allocation failure and sometimes fail than to not try at all.<br> <p> Also, you might be able to allocate whatever memory you need to run the destructor in the constructor, thus avoiding the need to allocate in the destructor. <br> </div> Sun, 06 Feb 2022 03:02:18 +0000 Rust https://lwn.net/Articles/882769/ https://lwn.net/Articles/882769/ iq-0 <div class="FormattedComment"> What do you mean with object metadata? Rust doesn&#x27;t have RTTI if that&#x27;s what you mean. Aside from DWARF information it only has vtables for trait objects that are used in the code (bare minimum, those things are basically structs with function pointers like one would use in C for this same problem). If you&#x27;re referring to the name mangling (the loooong type signatures) those have more to do with the way Rust solves diamond dependency conflicts and the liberal usage of templated types.<br> </div> Wed, 26 Jan 2022 18:37:18 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882506/ https://lwn.net/Articles/882506/ atnot <div class="FormattedComment"> Oh, I hadn&#x27;t considered that you could mutate a lists through another one...<br> <p> I don&#x27;t immediately see any reason why it shouldn&#x27;t be possible. Rust&#x27;s weak references have similar semantics albeit still require reference counting because it can&#x27;t just go and remove the remaining references like with a list. I don&#x27;t think it&#x27;s natively supported by the intrusive-collections crate mentioned above though. But you should be able to express it with a safe interface.<br> <p> Evidently there doesn&#x27;t seem to be a lot of demand for something like that from existing rust users though. intrusive-collections is already not exactly widely used. I&#x27;ve personally never found a reason to use it despite looking for excuses, there&#x27;s just too many specialized high quality data structure libraries to justify it. Maybe some day.<br> </div> Tue, 25 Jan 2022 09:42:04 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882496/ https://lwn.net/Articles/882496/ artem <div class="FormattedComment"> <font class="QuotedText">&gt; Once you put things into multiple collections you need some way of knowing whether you should free items when removing them. </font><br> <p> <font class="QuotedText">&gt; If you don&#x27;t know whether it&#x27;s the last reference, you need some kind of reference count </font><br> <p> With multiple intrusive lists, you can declare some of them owning and some of them non-owning.<br> <p> When a thing is not on any of the owning lists, it&#x27;s removed from the rest and dropped.<br> <p> No reference counting necessary.<br> <p> How would one do that in Rust?<br> <p> <p> </div> Tue, 25 Jan 2022 04:15:06 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882240/ https://lwn.net/Articles/882240/ farnz <p>As a side note, the Rust team are working on providing a decent API for fallible allocations. The raw <a href="https://doc.rust-lang.org/std/alloc/trait.Allocator.html"><tt>Allocator</tt> trait</a> that's going to be the interface between allocators and the rest of the language only has fallible functions that may allocate. The only function in that API that must succeed is <tt>free</tt>. <p>Then, there's effort ongoing to <a href="https://rust-lang.github.io/rfcs/2116-alloc-me-maybe.html">support fallible allocation in container APIs</a>, with its own <a href="https://github.com/rust-lang/rust/issues/48043">tracking issue</a>. <p>There's a lot of effort going in to making this a supportable API for the long term; the key "odd" decision Rust seems to be making here is that instead of requiring every operation that could allocate to cope with the risk of allocation failure, there will be a mechanism (<tt>try_reserve</tt> on collections, for example) that guarantees that you can do a certain number of operations without allocating, and that mechanism can fail. It's then up to the users of the APIs to ensure that memory is either reserved up-front, or to take the risk of surprise allocation failure. <p>And this matches the underlying observation you've made; it's incredibly hard to handle allocation failure if it can happen at any time, and thus the entire application needs to either be bug-free in handling the rare error case (allocation failure), which in C++ means that everything has to meet the strong exception safety guarantee, or you need to confine allocation failures to a few places where you have hardened your code. Sun, 23 Jan 2022 10:07:17 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882237/ https://lwn.net/Articles/882237/ NYKevin <div class="FormattedComment"> Well, let&#x27;s compare to the (userspace) alternatives:<br> <p> 1. In a managed language, like Java, you get some sort of &quot;out of memory&quot; exception. Handling these exceptions safely is complicated and error-prone, and the official documentation will often encourage the programmer to just &quot;let it crash&quot; instead of trying to deal with the problem gracefully. In most cases, these languages will try to reclaim previously allocated memory with the garbage collector before throwing these exceptions.<br> 2. In C++, std::bad_alloc is thrown, which is like the managed case except that stack unwinding will cause destructors to run (in the managed case, finalizers *might* run, but there is no guarantee of when they get called). If any of those destructors tries to allocate any memory, for any reason, it might cause a second std::bad_alloc to get thrown, and if a destructor throws an exception while another exception is already pending, the runtime gives up and calls std::terminate. Therefore, if you want to handle fallible allocations, every destructor in your entire program must be in on the joke.<br> 3. In C, malloc returns a null pointer. If you forget to check for it, undefined behavior occurs (but in practice, you probably just segfault most of the time). If you remembered to check for it, you can handle it in whatever way you like, but in most cases you either return an error to your caller, or call longjmp(3) on a pre-allocated jmp_buf to go back to the main event loop or some other top-level scope that can reasonably figure out what to do next.<br> 4. Regardless of language, it&#x27;s possible for the OS to lie to you and give you memory which doesn&#x27;t actually exist, then kill you when you try to use it. Linux actually does this,* and I believe it&#x27;s common in other modern OSes as well. Where this functionality is enabled, any program can crash upon the system running out of memory, and there&#x27;s nothing the programmer can reasonably do about it.<br> <p> Sure, discount (1) all you like, but the practical reality is that running out of memory is really hard to handle safely when you&#x27;re running in userspace, regardless of whether you&#x27;re a high-level language or a low-level language.<br> <p> * The OOM killer is more complicated than what I have described here.<br> </div> Sun, 23 Jan 2022 03:01:52 +0000 Rust https://lwn.net/Articles/882226/ https://lwn.net/Articles/882226/ tialaramex <div class="FormattedComment"> What I&#x27;m getting at is that your fork can literally rip out the code that does floating point math. Rust&#x27;s actual standard library won&#x27;t do that, but it will probably some day take that cfg() parameter to turn off floating point math or agree some other way forward. Meanwhile Rust for Linux gets a library it can ship in Linux.<br> <p> It&#x27;s future proofed in that the assumption is some day Rust will have a way to disable or sidestep this, and at that point Rust for Linux can just ship the normal core library (in this respect).<br> <p> The fact Rust&#x27;s standard library relies on Rust&#x27;s nightly features is orthogonal, this configuration parameter isn&#x27;t relying on yet-to-stabilise feature, it&#x27;s just that the code in core wants to do floating point maths, and Linux doesn&#x27;t want that to be a possibility. In that specific case just ripping out the offending code is an effective solution, you could do it once for each Linux release and while somewhat tiresome it&#x27;s not unmanageable.<br> </div> Sat, 22 Jan 2022 21:32:42 +0000 Rust https://lwn.net/Articles/882175/ https://lwn.net/Articles/882175/ plugwash <div class="FormattedComment"> &quot;However, ultimately you _could_ do this surgery by hand and in effect &quot;fork&quot; the core library, especially if you knew a real fix was coming later.&quot;<br> <p> The rust standard library uses and will probably always use features that will not be part of stable rust. So forking the standard library doesn&#x27;t really help you with future-proofing your code.<br> </div> Sat, 22 Jan 2022 01:02:16 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882144/ https://lwn.net/Articles/882144/ atnot <div class="FormattedComment"> I&#x27;m not sure that&#x27;s really much less ergonomic than C? You still have the same issue there. Once you put things into multiple collections you need some way of knowing whether you should free items when removing them. That&#x27;s true regardless of whether the compiler notices it.<br> <p> If you don&#x27;t know whether it&#x27;s the last reference, you need some kind of reference count and if you do you&#x27;ll need to prove it, either to yourself or preferably some program. It&#x27;s not much different.<br> </div> Fri, 21 Jan 2022 20:45:01 +0000 Rust https://lwn.net/Articles/882138/ https://lwn.net/Articles/882138/ ballombe <div class="FormattedComment"> Is there an usable subset of rust without object metadata ?<br> </div> Fri, 21 Jan 2022 19:25:29 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882131/ https://lwn.net/Articles/882131/ pbonzini <div class="FormattedComment"> Sure, I only said it doesn&#x27;t support them &quot;very well&quot;. If you check <a href="https://docs.rs/intrusive-collections/0.9.3/intrusive_collections/#links-and-adapters">https://docs.rs/intrusive-collections/0.9.3/intrusive_col...</a>, having the same object in many lists (which is a major advantage of intrusive collections) requires reference counting.<br> <p> This is enough of a disadvantage that the same crate includes an unsafe primitive to avoid this (<a href="https://docs.rs/intrusive-collections/0.9.3/intrusive_collections/#safety">https://docs.rs/intrusive-collections/0.9.3/intrusive_col...</a>).<br> </div> Fri, 21 Jan 2022 18:10:57 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882123/ https://lwn.net/Articles/882123/ atnot <div class="FormattedComment"> It&#x27;s not really accurate that the language wasn&#x27;t built with the Idea in mind. Just like C, Rust does not depend on any kind of allocator, fallible or not. All of the difficulties here are just from the desire to reuse a userspace library (alloc) in the kernel. They certainly could have just written their own allocator api, list types, etc. just like the kernel does, but since the standard library developers were willing to support their use case it was just more convenient to share.<br> </div> Fri, 21 Jan 2022 18:03:47 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882126/ https://lwn.net/Articles/882126/ walters <div class="FormattedComment"> The article phrased this poorly. The Rust *language* is independent of the default standard library. Plenty of use cases (including Rust-for-Linux) use &quot;no-std&quot; which fully supports writing code with fallible allocations. Plenty more at e.g. <a href="https://doc.rust-lang.org/stable/embedded-book/intro/no-std.html">https://doc.rust-lang.org/stable/embedded-book/intro/no-s...</a><br> </div> Fri, 21 Jan 2022 17:43:55 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882125/ https://lwn.net/Articles/882125/ walters <div class="FormattedComment"> There is <a href="https://crates.io/crates/intrusive-collections">https://crates.io/crates/intrusive-collections</a> for example.<br> </div> Fri, 21 Jan 2022 17:41:02 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882069/ https://lwn.net/Articles/882069/ ejr <div class="FormattedComment"> Modula-3 tried really, really hard to come up with generalizable semantics to apply when allocation fails. I don&#x27;t believe they ever did.<br> </div> Fri, 21 Jan 2022 14:22:31 +0000 Rust https://lwn.net/Articles/882068/ https://lwn.net/Articles/882068/ ejr <div class="FormattedComment"> Ah, I thought GAT was a misspelling of GADT. And traits sound more like type classes... So essentially this is another version of ML module signatures / Haskell type classes. I&#x27;m guessing it looks more friendly to folks coming from C/C++.<br> <p> Stability is pre-standardization like C/C++ attributes, or would be if there were multiple compilers out there. (gcc was on its way at some point, right?) Many mostly-single-vendor languages have stable v. implementation gizmos. At least this term is fairly well shared.<br> <p> Rust isn&#x27;t useful in my daily life (heavily shared memory structures being changed rapidly), so I haven&#x27;t really poked at it. <br> </div> Fri, 21 Jan 2022 14:21:09 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882062/ https://lwn.net/Articles/882062/ pbonzini I'll add that Rust in general does not support intrusive data structures very well, because it is not very much friend with data that can be reached in different ways. You would have to wrap it with a reference count (<a href="https://doc.rust-lang.org/std/rc/struct.Rc.html"><tt>Rc</tt></a> or <a href="https://doc.rust-lang.org/std/sync/struct.Arc.html"><tt>Arc</tt></a>) and with either run-time borrow checking or a mutex (respectively <a href="https://doc.rust-lang.org/std/cell/struct.RefCell.html"><tt>RefCell</tt></a> and <a href="https://doc.rust-lang.org/std/sync/struct.Mutex.html"><tt>Mutex</tt></a>). Fri, 21 Jan 2022 12:45:37 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882061/ https://lwn.net/Articles/882061/ ldearquer <div class="FormattedComment"> I see, thanks for clarifying :)<br> </div> Fri, 21 Jan 2022 12:36:21 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882059/ https://lwn.net/Articles/882059/ eru <blockquote><i>The Rust language wasn't built with the idea that code might need to continue when a memory allocation fails; instead, the normal result is an immediate crash. </i></blockquote> <p> A surprising feature in a language that has been touted as a C replacement for low-level programming. Of course, when you are out of memory, there typically are no good options, but a language for low-level programming must allow the programmer to decide what happens next. Fri, 21 Jan 2022 12:30:35 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882057/ https://lwn.net/Articles/882057/ pbonzini <div class="FormattedComment"> Usually Linux uses intrusive linked lists. They allow the same node to be part of multiple data structures, so you find the node in a different data structure (for example an array or hash table) and juggle the pointers in the node to move it to the end of the LRU list.<br> </div> Fri, 21 Jan 2022 12:11:14 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882049/ https://lwn.net/Articles/882049/ ldearquer <div class="FormattedComment"> For the linked list, wouldn&#x27;t it require O(n) finding the node? Then place it on the highest index O(1)? So you would have O(n) (+ O(1)) vs 2·O(log n)<br> </div> Fri, 21 Jan 2022 09:00:28 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882046/ https://lwn.net/Articles/882046/ Cyberax <div class="FormattedComment"> You can use heaps, not full B-trees. That actually would be interesting to measure, it&#x27;s quite possible that not having to chase the pointers might speed them up.<br> </div> Fri, 21 Jan 2022 04:40:02 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882042/ https://lwn.net/Articles/882042/ willy <div class="FormattedComment"> Ok, I&#x27;ll bite ... How do you efficiently implement an LRU with a B-tree? Every time you access an element (let&#x27;s say an inode) in the inode cache, you remove it from wherever it currently is in the B-tree and move it to the highest unused index. That&#x27;s two O(log n) operations, versus a linked list, which is two O(1) operations.<br> </div> Fri, 21 Jan 2022 03:07:10 +0000 Rust https://lwn.net/Articles/882040/ https://lwn.net/Articles/882040/ tialaramex <div class="FormattedComment"> I am happy within reason to define terms, and it&#x27;s likely others could help too, but of course I need to know what you didn&#x27;t understand.<br> <p> For example maybe with ML in your background Generic Associated Types are obvious, or maybe not, with GATs Rust can express the idea that some trait can have associated types which are generic. So e.g. today an Iterator has an associated type saying which Item type it iterates over, but that associated type has to be specific, like this is an Iterator over Strings, there are some traits people would like to write where you&#x27;d want to express that the associated type has some generic properties but not tie down the specifics. Evidently the Rust for Linux have some use for this feature.<br> <p> But equally maybe you don&#x27;t know what Rust&#x27;s traits are. Traits are similar to the &quot;interfaces&quot; feature in many object oriented languages, in that they express some capability or property common to multiple types. A trait must be explicitly implemented for any particular type, either with the definition of the type itself, or with the definition of the trait, and each such implementation stands alone. So you can be sure that if SomeTrait is implemented for ThisThing, either the author of ThisThing intended that, or the author of SomeTrait or perhaps both, as a result traits have Semantics - there is no risk of their being a mere accident of syntax as with say C++ Concepts.<br> <p> Maybe you know about Rust stability, or maybe not, in Rust there&#x27;s a concept of &quot;unstable&quot; features. These features exist, and they work in whatever build of Rust you have, but tomorrow there might be a new Rust version and they&#x27;re altered, or renamed, or gone. In contrast all the stable features of Rust are promised to still work into the indefinite future, none have been removed since 1.0 in 2015. You have to specifically opt in to having unstable features, and to each specific unstable feature you want. Today Rust for Linux needs several such features. Internally Rust uses some unstable features, but without opting in you can&#x27;t and probably most people shouldn&#x27;t, thus it is desirable for Rust for Linux to rely as much as possible on stable features only.<br> <p> </div> Fri, 21 Jan 2022 00:57:43 +0000 Rust https://lwn.net/Articles/882037/ https://lwn.net/Articles/882037/ ejr <div class="FormattedComment"> I am trying to parse both your message as well as the one to which you are responding.<br> <p> And I&#x27;m a FORTRAN (yes, all caps, including WATFIV) / APL / C person. With a background in more formal language systems like ML.<br> <p> Please define your terminology, It appears as if yet another terminology is a major hurdle for acceptance.<br> <p> </div> Thu, 20 Jan 2022 23:43:36 +0000 Rust https://lwn.net/Articles/882032/ https://lwn.net/Articles/882032/ tialaramex <div class="FormattedComment"> The stability list isn&#x27;t TOO bad once you consider it standing back a few paces.<br> <p> I count 17 items, 4 are cfg() parameters, to switch off features from the allocator and, in one case, the core Rust library†. That latter is worth a moment&#x27;s thought: Rust says you can format floating point numbers. Linux, of course, would very much rather you didn&#x27;t use floating point numbers at all. So, Rust-for-Linux wants to tell the core library that we aren&#x27;t going to be formatting any floating point numbers, blow up code that tries to do that, that&#x27;s not valid Linux code. However, ultimately you _could_ do this surgery by hand and in effect &quot;fork&quot; the core library, especially if you knew a real fix was coming later.<br> <p> 2 more are -Z compiler flags. Rust&#x27;s compiler has flags marked as not being stable with a Z prefix. It&#x27;s not as though the kernel has never taken a dependency on compiler specific flags before, but clearly having a stable flag is better because it&#x27;s a social contract not to move this particular feature unexpectedly.<br> <p> Some of the others have community momentum behind them because they&#x27;re things most Rust users want, GATs and more const are in that category. If Rust for Linux didn&#x27;t engage with the main Rust community at all for 12 months, those things have traction and will make progress anyway. On the other hand, there are few applications outside the kernel for some of the compiler internals stabilization that Rust for Linux wants, if they never did this I for example, writing userspace code, would never ever notice.<br> <p> It overall certainly means I don&#x27;t expect to be running a Linux kernel with Rust in it in 2022 on my PC. But it also doesn&#x27;t feel insurmountable, I could imagine reading an LWN piece before the end of the year about the &quot;one big piece&quot; missing, I just can&#x27;t guess which piece that will be.<br> <p> † Rust has a core library, which is at the heart of the standard library but must exist anyway. A few things in here are literally mandatory to Rust, e.g. the Drop trait must exist, it needn&#x27;t be called Drop, but if there isn&#x27;t one that&#x27;s not Rust any more, the i32 type must exist, I don&#x27;t even think you&#x27;re allowed to call it something else, just too bad you must implement 32-bit signed integers - however a whole lot more are just useful, and not actually needed by Rust itself even if ordinary developers would be sad not to have them.<br> </div> Thu, 20 Jan 2022 23:29:49 +0000 The kernel radar: folios, multi-generational LRU, and Rust https://lwn.net/Articles/882024/ https://lwn.net/Articles/882024/ developer122 <div class="FormattedComment"> Yeah, as I&#x27;ve heard Brian Cantrill say during a twitter space podcast thing, Rust and it&#x27;s compiletime ownership-checks really doesn&#x27;t work well with the concept of linked lists. After all &quot;if you have b-trees, why would you use anything else?&quot; And Rust&#x27;s ownership checking makes (generically implemented) b-trees easy where as in C or other languages they tend to end up being a horrible buggy mess.<br> </div> Thu, 20 Jan 2022 22:49:28 +0000