Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Cloudflare Quick Tunnels(cloudflare.com ↗)
    114comments
  2. There's no point at which turning your brain off will work(danluu.com ↗)
    6comments
  3. Photon-Emission-Guided Laser Fault Injection Enables RP2350 Secure Debug(ledger.com ↗)
    2comments
  4. An Empirical Study of Harness Design for Coding Agents(arxiv.org ↗)
    36comments
  5. North Korean nuclear test sets off years of earthquakes(science.org ↗)
    67comments
  6. Show HN: Cactus Needle 3: 8-29MB automation models can match DeepSeek V4 Flash(cactuscompute.com ↗)
    15comments
  7. OpenJev(openjev.com ↗)
    202comments
  8. C++26: Trivial infinite loops are no longer undefined behaviour(sandordargo.com ↗)
    94comments
  9. Mathematicians Build Long-Awaited Graph Sandwich(quantamagazine.org ↗)
    5comments
  10. I vibed a proof of Conway's conjecture(overreacted.io ↗)
    98comments
  11. A heap overflow and SSO misconfiguration to compromise OpenAI internal repos(hacktron.ai ↗)
    179comments
  12. GrassLobster: AI Agentic Generation of Parametric Geometry Workflows(miro.vision ↗)
    3comments
  13. I don't like passkeys(hawksley.dev ↗)
    516comments
  14. BeanShell3 in Development(beanshell.github.io ↗)
    11comments
  15. Jemalloc 5.4.0(github.com/jemalloc ↗)
    73comments
  16. The Shadows Lurking in the Equations – Underwater Islands(gods.art ↗)
    9comments
  17. Cekura (YC F24) Is Hiring(ycombinator.com ↗)
    discuss
  18. NATS publishes preliminary report on technical incident of 8 September(nats.aero ↗)
    23comments
  19. Show HN: Microsoft Office running with Wine on Linux with no virtualization(github.com/tombert ↗)
    45comments
  20. The scourge of x86 emulation(fex-emu.com ↗)
    67comments
  21. Bonsai 2 27B: Near-Lossless Compression in a 9x Smaller Footprint(prismml.com ↗)
    176comments
  22. Warren Buffett Steps Down as Berkshire Chairman, Names Son to Replace Him(nytimes.com ↗)
    152comments
  23. US Treasuries Have Become Unappetizing for Foreign Central Banks and Governments(wolfstreet.com ↗)
    44comments
  24. Build Faster Feedback Loops Using Qualitative User Research(nseldeib.com ↗)
    1comments
  25. Qwen 3.8 Omni Flash(qwen.ai ↗)
    117comments
  26. Second Circuit Allows Government to Search Electronic Devices at the Border(knightcolumbia.org ↗)
    35comments
  27. Show HN: Scry, programmable internet search w/ congestion pricing(scry.io ↗)
    2comments
  28. How to Write with an LLM(sockpuppet.org ↗)
    192comments
  29. Pre-Greek: The lost language hidden within Ancient Greek(linguisticdiscovery.com ↗)
    61comments
  30. Microsoft exec called AI scraping 'the largest theft of labor in human history'(techcrunch.com ↗)
    625comments

Jemalloc 5.4.0

292 pointsby 13h agogithub.com
73 comments
11h agoHN ↗

Why is this on the HN front page? Is there something particularly noteworthy about this release?

11h agoHN ↗

They resumed development on jemalloc only recently, after years of no releases.

9h agoHN ↗

Development was never stopped for jemalloc. This is a common misconception. There just were not releases being tagged and packaged against the ongoing development.

11h agoHN ↗

I just checked whether it's the first release after Jason Evans stepped down as maintainer, but it isn't. That was the previous release, 5.3.1

10h agoHN ↗

jemalloc is something you should be aware of if you do software for a living

10h agoHN ↗

Why? Writing a memory allocator is quite simple, and I'd argue that _everyone_ should write one from scratch for any kind of high performance application. It's also trivial to outperform general purpose allocators that have to satisfy countless constraints. I've written numerous special purpose mallocs that are a) both provably (formally) safer than the standard armada and b) significantly faster (>10x throughput).

10h agoHN ↗

Your experience writing memory allocators is irrelevant. The point is that jemalloc is widely used and that’s why it makes sense to be aware of it.

10h agoHN ↗

I'd happily see performance, latency and stability of your allocators in massively multithreaded, long-living programs with workloads where hundreds or thousands of parallel threads continuously create and destroy short-lived small and medium objects.

Writing allocators for domain-specific access patterns is easy. Writing a general-purpose high performing, stable allocator with bounded P99 latency is hard.

Give your friend, Dunning–Kruger, some better pills to keep him from speaking through you.

9h agoHN ↗

You're correct, but his point is that you don't need to solve the generic problem. Solving the generic problem is very hard. Grug doesn't like solving hard problem. What does grug do? Solve five easy problems. Make an arena for the short-lived objects, reuse the objects, use generic multithreaded malloc for the rest. Grug happy.

9h agoHN ↗

Not everything needs to be general purpose. Allocation can be as easy as bumping a pointer, and it's hard to beat that.

7h agoHN ↗

where hundreds or thousands of parallel threads continuously create and destroy short-lived small and medium objects.

Should one even want a global, general purpose heap allocator for that? Seems like a crazy idea to even consider.

7h agoHN ↗

I guess the point was that before you consider using a different allocator you should rule out a custom one.

And that's rather hard, because a general purpose allocator makes all decisions based only on the requested size. This is a very simple interface and such a tool is worth having. But a custom allocator can both bake in a specific scenario and provide more nuanced interaction.

7h agoHN ↗

massively multithreaded, long-living programs with workloads where hundreds or thousands of parallel threads continuously create and destroy short-lived small and medium objects.

My first thought would be to use per thread pool allocators.

9h agoHN ↗

Writing an allocator is simple, you’re correct, but writing an allocator that doesn’t suck is not simple.

9h agoHN ↗

In the Before Times, the vast majority of software was written in garbage collected language where a working knowledge of the relative merits of C memory allocators is not useful or particularly relevant.

Why would the scads of people writing JavaScript, Java, python, go, rails, etc need to be aware of jemalloc?

9h agoHN ↗

TL;DR: Because the runtime of most GC:d languages uses malloc for its internal data structures.

I work for the runtime team of JPG @ Oracle. We use malloc in Hotspot, quite a lot actually! Providing your JVM with a good malloc can improve the performance of the runtime, both in terms of CPU and memory, by quite a bit.

I don't think you need the details, but it's good to be aware that some mallocs are better than others, and there are multiple of them. Being aware of jemalloc is a good way of being aware of the facts I just mentioned :-).

1h agoHN ↗

The vast majority of professional developers are not in a position where they can just swap out allocators willy-nilly. They take what they get, and write the code they're assigned to write on the platform the CTO or their product lead or whoever has decided upon.

1h agoHN ↗

Okay, well, I guess all I can say is that if you strive to be one of the developers who do get the chance to care about this stuff, then you should know this stuff :-).

8h agoHN ↗

...the vast majority of software was written in garbage collected language

and even then recently it costed (us) quite a few months to blame JVM and later the default glibc memory allocator for running out native (not java heap memory) - had to exclude all possible native libs (zlib, zstd via jna), direct buffers, sockets, thread stacks and so on. Changing the malloc to jemalloc solved the issue, even though initially it was done for its debugging capabilities.

It's just a great memory allocator.

7h agoHN ↗

I'm never sure if I should be upset or happy when I've been debugging a problem for long enough that I finally decide to switch something out in order to improve visibility and that immediately solves the problem for entirely unexpected reasons. Particularly all the times when I couldn't readily discern why.

8h agoHN ↗

Memory allocation behaviour has visible impact also for users of managed languages, and the behaviour of software for end users.

In our Python program, a bit of numpy processing of large pictures led to 100 GB not being returned to the OS by glibc's default allocator and the machine running out of memory shortly after. With jemalloc's reliable memory return settings, those problems disappear.

5h agoHN ↗

I'm in the same boat, I just switched to using it for Kavita, which only does some basic open Image -> Thumbnail to smaller size -> write to disk when importing new comics/books and on linux, memory could swell to 10GB and never get released. Switched to jemalloc and instantly memory stayed well below 1GB.

3h agoHN ↗

Generally yes, but the wording of "instantly" begs for the following pedantic remark:

This is controlled by jemalloc settings `dirty_decay_ms`, `muzzy_decay_ms`, and their interaction with `background_thread`.

`dirty_decay_ms` currently defaults to 10 seconds, so it's not that instant.

That is important e.g. for single-threaded programs that start other programs, such as my Python example: If it starts a subprocess before the 10 seconds elapse after `free()`, Python (and jemalloc) do not run, and get no chance to return memory to the OS.

In such cases, either enable `background_thread`, or set the `_decay_` values to `0` to ensure immediate return to the OS upon `free()`. (This costs some performance.)

See e.g. https://github.com/jemalloc/jemalloc/issues/2688

2h agoHN ↗

Okay but do you think the hordes of JavaScript developers at FANG can just change the browser’s allocator?

The number of programmers who are in positions to care about jemalloc vs other malloc is minuscule

5h agoHN ↗

Because unfortunately, the runtimes belonging to all or at least most of those languages perform a lot better with jemalloc than with the system default.

I wish that wasn't the case, but it is.

9h agoHN ↗

I upvoted it because I benefit from jemalloc in my stack (RoR) and I am tired of AI taking over HN front page. Let the hacker spirit be back!

8h agoHN ↗

Upvoted for the same reason. We would not be able to run our workloads without Jemalloc. Kudos to this awesome piece of software.

8h agoHN ↗

You are not alone - my first thought was 'oh, HN is trying to bring back the disappointed hackers'. All this AI hype over every little model update fart is so exhausting and boring …

8h agoHN ↗

because people like you are too busy whining about it to put up something more interesting

8h agoHN ↗

Why is this on the HN front page?

This question was not necessary. You know the answer, because people upvoted this.

6h agoHN ↗

I don’t want to dwell on drama, but it is perhaps worth mentioning that we reached a sad end for jemalloc in the hands of Facebook/Meta even though most of the people involved were acting in good faith.

Far from the only case. Trillion dollar companies having sudden interest in your open source project is not necessarily a long term benefit.

49m agoHN ↗

Post-ZIRP reality of corporate self-interest being re-established.

9h agoHN ↗

I always wondered, is it French? "Je m'alloc du memory"

9h agoHN ↗

Rather a tradition to call a malloc by the initials of the implementer: Jason Evans malloc (jemalloc), Poul-Henning Kamp malloc (phkmalloc), Doug Lea (dlmalloc).

P.S. I also wondered whether systemd had any cultural reference to Système D aka Système Débrouillard, but Pottering does not seem to engage in word play on other occasions, so probably not.

8h agoHN ↗

damn i always thought it was a french thing, this is blowing my mind

8h agoHN ↗

"Yes, it is written systemd, not system D or System D, or even SystemD. And it isn't system d either. Why? Because it's a system daemon, and under Unix/Linux those are in lower case, and get suffixed with a lower case d."

Source: https://brand.systemd.io/

3h agoHN ↗

you were right, check siblings of your comment.

7h agoHN ↗

It does

Systemd was launched in April 2010; it adopts various ideas from previous init systems and combines them with a uniform configuration and administration interface. Systemd operates as a background service (daemon) and controls important system configuration tasks including hardware initialisation and the starting of server processes. The developers thought that its name is suitably reminiscent of the French term "système D", an expression that relates to "thinking on your feet" and describes high-speed technical problem-solving abilities such as those displayed by TV action hero MacGyver.

https://web.archive.org/web/20121014173559/http://www.h-onli...

9h agoHN ↗

Thanks, now my brain will forever read it like that. I'm not even a little bit French.

7h agoHN ↗

Fun grammatical fact that I only learned after years of speaking French: when borrowing words from other languages, you usually (not always) take the gender of the equivalent word in French, so technically it would be “de la memory” :)

7h agoHN ↗

That's the rule the old geezers at the Academy insist on. But then you have idiotic situations where everyone is using "le" for e.g. the COVID virus, while Academicians cry about the D meaning "Disease", which is feminine, making it "la COVID" in their book. As for all languages, the most important rule is that usage prevails. And that's something we in France still have a hard time integrating into public discourse.

7h agoHN ↗

An interesting case is "WiFi", short for "wireless fidelity". "Fidélité sans fil" in French should be feminine, but every technical person says "le WiFi" (masculine) while many (most?) non-technical people intuitively say "la WiFi" (feminine).

7h agoHN ↗

If you keep your access point secure and in good working order, or if you can flash any firmware into OpenWRT... make sure to publicly credit your excellent "Wi-fu"

6h agoHN ↗

Better keep the wifi working, or your waifu could get angry.

9h agoHN ↗

Ok. Why both the homepage and its Github repo doesn't make a single mention of Jason Evans? I know he stepped down but surely it is at least worst mentioning it?

Is Meta still using it and developing it? If not who are the driving force behind it now? I just checked there wasn't a release since 2022 and then we have this now. Something changed?

Just wish we have a little bit of context. But it is also great it is continue being maintained. It makes a huge difference for Ruby on Rails Apps.

9h agoHN ↗

Just wish we have a little bit of context

See the comment of vocx2tx

8h agoHN ↗

does anyone familiar with the art have thoughts on why only tcmalloc switched from thread caches to cpu caches? would it make linux behavior diverge too much from other platforms?

8h agoHN ↗

I think tcmalloc gains on thread churn and oversubscription by going the cpu-cache route on Linux. on other platforms, I am not so sure but that can be offset by say a treiber-stack like setup for cross-thread frees/teardowns. So lesser code for Linux for similar fastpath design I guess.

1h agoHN ↗

on other platforms, I am not so sure

tcmalloc only works on Linux.

8h agoHN ↗

(Not an expert but ...) unless you pin threads to cores, which is not the default and somewhat awkward in Linux for user applications, having a per-thread cache doesn't really make sense as your thread could be moved to another core and then your cache will no longer be local to the physical cache.

6h agoHN ↗

i think we agree that per cpu caching seems superior. i’m looking for the other side of this. most allocators seem to have stuck with per thread.

5h agoHN ↗

If you use a thread-local data structure, your allocator can pretend that it is running on a single-core, single-task system.

If you use a CPU-local data structure, you must handle the case where, mid-way through a call to your allocator, the CPU runs a second thread that makes another call to your allocator (and that, too, can get interrupted by another thread that allocates memory, etc.)

That makes thread-local easier to implement and likely faster (it doesn’t require any memory barriers in the fast path)

Also, good schedulers try to avoid moving threads between CPUs. The better they manage to do that, the lower the cost of having per thread data structures (there likely still is a price, as there most of the time are more threads than CPUs on a system)

4h agoHN ↗

Setting aside whether or not you can pull off a lock free approach here we can be certain of a couple things. There will be at least some overhead that must be paid somewhere even if that's on a separate management thread. And there will be a lot of additional complexity because that's just how concurrency always is.

Meanwhile the better the scheduler performs the more competitive the thread local approach becomes.

12m agoHN ↗

https://docs.kernel.org/userspace-api/rseq.html

cost for interruption in an rseq critical section is that the PC gets overwritten to the rseq abort entry point before the task is rescheduled. no management thread necessary.

should be fairly minimal cost, especially assuming interruptions in the critical section are rare.

3h agoHN ↗

https://lwn.net/Articles/1033957/:

  rseq_cs

   The rseq_cs field is a pointer to a struct rseq_cs. Is is NULL when no
   rseq assembly block critical section is active for the registered
   thread. Setting it to point to a critical section descriptor (struct
   rseq_cs) marks the beginning of the critical section.

I’m not sure I fully understand that man page (it never seems to say callers have to clear that field at the end of a critical section, for example), but doesn’t that mean the caller has to guarantee setting rseq_cs happens_before any code in the critical section? That’s a memory barrier.

1h agoHN ↗

That is because you do not need to clear the field at the end of a critical section. It contains the contiguous instruction range where it fires so there is no problem with leaving it active forever unless you have another critical section where you want to use it.

No explicit memory barrier is required anywhere as the value is only read in supervisor mode and a privilege switch implicitly issues a LS-LS barrier on all major architectures. Even if you did not want to rely on that, you would only need a single S-LS barrier when you store the control structure the very first time.

1h agoHN ↗

Exactly. You want memory arenas that are hot in this CPU's caches. If your thread moves, its per-thread caches are now elsewhere. Original TCMalloc was developed in the days of 2-4 core servers. Current TCMalloc was an evolution in the context of 32+ core servers.

7h agoHN ↗

I switched to jemalloc on a sidekiq queue and memory dropped from 8gib to under 1gib

There’s a slow memory leak somewhere in my code but with jemalloc it no longer actually matters.

Thanks to jemalloc team for this!

2h agoHN ↗

This is the most funny thing I read today!

2h agoHN ↗

I use Jemalloc on a project because it has per-thread allocation counters. This lets me not only track what each thread is using, but also restrict workloads by enforcing a memory budget. Since my application is almost completely CPU-bound, I allocate one thread per core and then have some smart scheduling to route requests to the threads. I looked at tcmalloc and mimalloc, and neither had this feature at the time, nor did they seem to have any similar feature that could let me have per-thread heaps, which surprised me.

1h agoHN ↗

Nice to see jemalloc active again. The long-term health of the upstream project is probably just as important as the allocator improvements themselves.