NobleExpress | 1 year ago | on: Beginner's guide to the Shenandoah garbage collector
NobleExpress's comments
NobleExpress | 1 year ago | on: Deep Bug
NobleExpress | 1 year ago | on: Deep Bug
NobleExpress | 1 year ago | on: Deep Bug
Another debugging technique we use for heisenbugs is to see if `rr` [1] can reproduce it. If it can then that's great as it allows you to go back in time to debug what may have caused the bug. But `rr` is often not great for concurrency bugs since it emulates a single-core machine. Though debugging a VM is generally a nightmare. What we desperately need is a debugger that can debug both the VM and the language running on top of it. Usually it's one or the other.
> In general I’d argue you haven’t fixed a bug unless you understand why it happened and why your fix worked, which makes this frustrating, since every indication is that the bug exists within proprietary code that is out of my reach.
Were you using Oracle GraalVM? GraalVM community edition is open source, so maybe it's worth checking if it is reproducible in that.
NobleExpress | 1 year ago | on: Wayland breaks your bad software
I would highly recommend reading through some of these blog posts who expound upon the problems of Wayland more eloquently than I can [2,3,4].
[1]: https://en.wikipedia.org/wiki/Waterbed_theory
[2]: https://dudemanguy.github.io/blog/posts/2022-06-10-wayland-x...
[3]: https://pointieststick.com/2023/09/17/so-lets-talk-about-thi...
[4]: https://utcc.utoronto.ca/~cks/space/blog/unix/WaylandTechnic...
NobleExpress | 1 year ago | on: Bump Allocation: Up or Down?
Also realloc'ing the most recently allocated object is not a common operation, at least in my experience building memory management systems.
NobleExpress | 1 year ago | on: Bump Allocation: Up or Down?
NobleExpress | 2 years ago | on: The Garbage Collection Handbook, 2nd Edition
I personally don't know too much about userfaultfd and how it works internally, but my best guess is that it bypasses heavyweight kernel data-structures and lets the user application handle the page fault. It is obviously better than simply using mprotect, but it is not immediately clear why it would be better than a read barrier (other than code size considerations, which honestly doesn't sound like much of a big deal as the code handling userfaultfd also needs to be brought into the instruction cache).
I did find this kernel doc about userfaultfd [1] which might be interesting to read if you're interested (it also does mention that userfaultfd doesn't lock some internal kernel data-structures which gives it a better performance than simply using mprotect, but the implementation details are a bit sparse).
[1]: https://docs.kernel.org/admin-guide/mm/userfaultfd.html
NobleExpress | 2 years ago | on: The Garbage Collection Handbook, 2nd Edition
NobleExpress | 2 years ago | on: The Garbage Collection Handbook, 2nd Edition
Right. You bump allocate faster, however. RC is an additional operation to the allocation request. Given naive RC can't move objects, it necessarily needs a free-list allocator. Free-list allocators can allocate pretty fast (for the most common object sizes), but can't reach the speeds of bump allocators. Furthermore, bump allocators have better locality of reference than free-list allocators.
Also I've never questioned you can't do non-atomic increments/decrements efficiently. They are exceptionally fast. However you are still converting every pointer read operation into a pointer write operation. The rule of thumb is that there are generally 10x more pointer read operations in a program than pointer write operations. This is why read barriers are also considered more costly than write barriers.
> I did actually provide proof by the way. Apple’s phones use half the RAM as Android and are at least as equally fast even if you discount better HW.
I don't really agree with this statement. There are way too many unknown/unaccounted variables. It could be better hardware, maybe Android has a terrible architecture, and could just be as you said that Swift RC is genuinely better than ART GC or it can be whatever. Point is that it's not a scientific comparison. We don't know if the benefits in iOS come from RC. And we wont be able to know unless we have two systems where all parameters are the exact same _except_ one is using RC and another is using tracing GC, with both systems ran on the same hardware and on the same set of benchmarks.
> That’s only kind of true. Good allocators seem to mitigate this problem quite effectively
Yes. Note that mimalloc literally has a concept of "deferred frees" effectively emulating GC as otherwise freeing an object can result in an unbounded recursive free call (for example, dropping a large linked list).
> I’m just saying that good memory management (made fairly easy in Rust) is always going to outperform tracing GC the same way optimized assembly will outperform the compiler.
Sure. The perfect memory manager is omniscient and knows exactly when an object is not required and will free it. But unfortunately we don't have perfect memory managers yet. So yes I agree in principle, but we have to be pragmatic.
> And I can’t belabor this point enough - languages with RC use it rarely as shared ownership is rarely needed and you can typically minimize where you use it.
I feel like that entirely depends on the problem domain? I don't know where you're getting the "shared ownership is rarely needed" from? Maybe this is true for your problem domain but may not be for others. And if it's true for yours, then great! You can use RC and optimize your programs that way.
> A tracing garbage collector still needs to do atomic reads of data structures which potentially requires cross cpu shoot downs.
Sure. GC metadata needs to be accessed and updated atomically. 100% agree with you. The order of magnitude of those operations is likely much less than what you would get with naive RC though.
> as Swift and ObjC demonstrate, it’s generally good enough without any serious performance implications (throughput or otherwise).
In one of my comments about Swift in this thread, the two papers I linked see up to 80% of the benchmark execution time being dominated by ARC operations! I will note that the papers are around 6-7 years old so the situation might have drastically changed since then, but I haven't personally found many new/contemporary evaluations of Swift RC.
NobleExpress | 2 years ago | on: The Garbage Collection Handbook, 2nd Edition
Comparing naive RC to tracing GC is non-trivial. In order to have a fair comparison, you'd have to implement naive RC and tracing GC in the same system and then compare them across a set of benchmarks. I personally have never come across a great performance study which compared naive RC to tracing GC.
NobleExpress | 2 years ago | on: The Garbage Collection Handbook, 2nd Edition
NobleExpress | 2 years ago | on: The Garbage Collection Handbook, 2nd Edition
NobleExpress | 2 years ago | on: The Garbage Collection Handbook, 2nd Edition
EDIT: The post you're responding to is referring to the simple standard implementation of RC.
NobleExpress | 2 years ago | on: The Garbage Collection Handbook, 2nd Edition
Do you have any links which might explain what kind of eliding Swift is doing?
EDIT: The major RC optimizations I have seen which elide references are deferral and coalescing and I'm fairly certain that Swift is doing neither.
[1]: https://dl.acm.org/doi/abs/10.1145/3170472.3133843
[2]: https://doi.org/10.1145/3243176.3243195
[3]: https://github.com/apple/swift/blob/main/docs/ARCOptimizatio...
NobleExpress | 2 years ago | on: The Garbage Collection Handbook, 2nd Edition
NobleExpress | 2 years ago | on: The Garbage Collection Handbook, 2nd Edition
Using page faults (and/or page protection) to perform compaction instead of barriers is a pretty old technique (see the 1988 paper by Appel, Ellis, and Li [1]; see also the Compressor by Kermany and Petrank [2]). But handling page faults were very expensive (at least on Linux) until the addition of userfaultfd recently.
[1]: https://dl.acm.org/doi/10.1145/960116.53992 [2]: https://dl.acm.org/doi/10.1145/1133255.1134023
NobleExpress | 2 years ago | on: Systems Benchmarking Crimes
There is a bunch of overlap with what Gernot talks about, but I think it's more general, and certainly useful to have a checklist!
NobleExpress | 2 years ago | on: Erlang/OTP: Garbage Collector
NobleExpress | 3 years ago | on: JDK 20 G1/Parallel/Serial GC Changes
Also supporting interior pointers is not too cumbersome even with a "Java-style GC" (whatever that exactly means). It requires an additional bit per smallest aligned object size to denote if an object is allocated or not. If you need to check if a pointer is an interior pointer to an object, you walk back in the bitmap and find the last object with a bit set to 1 (i.e. find the allocated object which was right before the pointer you have), get the size of that object and check that the pointer you have is within the range of the start and end of the object.
EDIT: The big issue you would face with directly porting a Java GC into other languages is the weak reference processing semantics. Each language has their own subtle differences which would make it a pain.
GenZGC is supported on OpenJDK 21 onwards [1].
[1]: https://inside.java/2023/11/28/gen-zgc-explainer/