Its worth reading this follow-up LKML post by Andres Freund (who works on Postgres): <a href="https://lore.kernel.org/lkml/yr3inlzesdb45n6i6lpbimwr7b25kqkn37qzlvvzgad5hfd7ut@xv4cihno76wu/" rel="nofollow">https://lore.kernel.org/lkml/yr3inlzesdb45n6i6lpbimwr7b25kqk...</a>
>If this somehow does end up being a reproducible performance issue (I still
suspect something more complicated is going on), I don't see how userspace
could be expected to mitigate a substantial perf regression in 7.0 that can
only be mitigated by a default-off non-trivial functionality also introduced
in 7.0.
.. which confirms all of my stereotypes. Looks like the AWS engineer who reported it used a m8g.24xlarge instance with 384 GB of RAM, but somehow didn't know or care to enable huge pages. And once enabling them, the performance regression disappears.
Note that it's just not a single post, and there's additional further information in following the full thread. :)
> Maybe we should, but requiring the use of a new low level facility that was introduced in the 7.0 kernel, to address a regression that exists only in 7.0+, seems not great.<p>Completely right. This sounds like a communication failure. Maybe Linux maintainers should pick a few applications that have "priority support" and problems with these applications are also problems with Linux itself. Breaking Postgres is a serious regression.<p>Reminds me of a situation where Fedora couldn't be updated if you had Wine installed and one side of the argument was "user applications are user problem" while the other was "it's Wine, like come on".
Funny how "use hugepages" is right there on the table and 99% of users ignore it.
AIUI in that thread they're saying "0.51x" the perf on a 96-core arm64 machine and they're also saying they cannot reproduce it on a 96-core amd64 machine.<p>So it's not going to affect everybody both running PostgreSQL <i>and</i> upgrading to the latest kernel. Conditions seems to be: arm64, shitloads of core, kernel 7.0, current version of PostgreSQL.<p>That is not going to be 100% of the installed PostgreSQL DBs out there in the wild when 7.0 lands in a few weeks.
It's a huge issue of ARM based systems, that hardly anyone uses or tests things on them (in production).<p>Yes, Macs going ARM has been a huge boon, but I've also seen crazy regressions on AWS Graviton (compared to how its supposed to perform), on .NET (and node as well), which frankly I have no expertise or time digging into.<p>Which was the main reason we ultimately cancelled our migration.<p>I'm sure this is the same reason why its important to AWS.
Macs are actually part of pain point with ARM64 Linux, because the Linux arm set er tend to use 64 kB pages while Mac supports only 4 and 16, and it causes non trivial bugs at times (funnily enough, I first encountered that in a database company...)
It was later reproduced on the same machine without huge pages enabled. PICNIC?
Yes, I did reproduce it (to a much smaller degree, but it's just a 48c/96t machine). But it's an absurd workload in an insane configuration. Not using huge pages hurts way more than the regression due to PREEMPT_LAZY does.<p>With what we know so far, I expect that there are just about no real world workloads that aren't already completely falling over that will be affected.
So perhaps this is a regression specifically in the arm64 code, or said differently maybe it’s a performance bug that has been there for a long time but covered up by the scheduler part that was removed?
The following messages concluded that using huge pages mitigates the regression, while not using huge pages reproduces it.
Could be either of those, or something else entirely. Or even measurement error.
Turns out the amd machine had huge tables enabled and after disabling those the regression was there on and too. So arm vs amd was a red herring.<p>Of course not a nice regression but you should not run PostgreSQL on large servers without huge pages enabled so thud regression will only hurt people who have a bad configuration. That said I think these bad configurations are common out there, especially in containerized environments where the one running PostgreSQL may not have the ability to enable huge pages.
Yes, I had a good laugh at that. It might technically be a regression, but not one that most people will see in practice. Pretty weird that someone at Amazon is bothering to run those tests without hugepages.
Still that huge a regression that affects multiple platforms doesn't sound too neat, did they narrow down the root cause?
For production Postgres, i would assume it’s close to almost no effect?<p>If someone is running postgres in a serious backend environment, i doubt they are using Ubuntu or even touching 7.x for months (or years). It’ll be some flavor of Debian or Red Hat still on 6.x (maybe even 5?). Those same users won’t touch 7.x until there has been months of testing by distros.
Ubuntu is used in many serious backend environments. Heroku runs tens of thousands (if not more) instances of Ubuntu on its fleet. Or at least it did through the teens and early 2020s.<p><a href="https://devcenter.heroku.com/articles/stack" rel="nofollow">https://devcenter.heroku.com/articles/stack</a>
A customer of mine is running on Ubuntu 22.04 and the plan is to upgrade to 26.04 in Q1 2027. We'll have to add performance regression to the plan.
I feel like using spinlocks in user space at all without kernel support like rseq is just asking for weird performance degradations.
I really dislike the use of spinlocks in postgres (and have been replacing a lot of uses over time), but it's not always easy to replace them from a performance angle.<p>On x86 a spinlock release doesn't need a memory barrier (unless you do insane things) / lock prefix, but a futex based lock does (because you otherwise may not realize you need to futex wake). Turns out that that increase in memory barriers causes regressions that are nontrivial to avoid.<p>Another difficulty is that most of the remaining spinlocks are just a single bit in a 8 larger byte atomic. Futexes still don't support anything but 4 bytes (we could probably get away with using it on a part of the 8 byte atomic with some reordering) and unfortunately postgres still supports platforms with no 8 byte atomics (which I think is supremely silly), and the support for a fallback implementation makes it harder to use futexes.<p>The spinlock triggering the contention in the report was just stupid and we only recently got around to removing it, because it isn't used during normal operation.<p>Edit: forgot to add that the spinlock contention is not measurable on much more extreme workloads when using huge pages. A 100GB buffer pool with 4KB pages doesn't make much sense.
> I feel like using spinlocks in user space at all without kernel support like rseq is just asking for weird performance degradations.<p>Yeah, exactly. "Doctor, help, somebody replaced my wooden hammer with a metal one, and now I can't hit myself in the face with it as many times."<p>If you use spinlocks in userspace, you're gonna have a bad time.
PostgreSQL is old and had to support kernels which did not support spinlocks. But, yes, maybe PostgreSQL should stop doing so now that kernels do.
Nobody sensible runs the latest kernel; nobody running PG in production should be afraid of setting a non-default at either boot time or as a sysctl. So this will, most likely, be another step in building a PG database server (turn off pre-emption if your kernel is 7.0 or later and PG is pre-whatever-version).<p>At worst it might become a permanent part of building a PG server and a FAQ... but if it affects one thing this badly, it will affect others.
> Nobody sensible runs the latest kernel<p>From the article: "Linux 7.0 stable is due out in about two weeks. This is also the kernel version powering Ubuntu 26.04 LTS to be released later in April."<p>Unfortunately, lots of people will be running it in less than a month. At the moment, it'll take a kernel patch (not a sysctl) to undo this-- hopefully something changes.
Not nobody but not everybody upgrades to the newest distros immediately. That's the advantage of LTS. I've even found that a lot of programs have poorer support on 24.04 than 22.04 due to security changes, so I'm fine sticking with 22.04 as my main dev system.
> ... not everybody upgrades to the newest distros immediately.<p>While that's true, for new deployments the story is often "deploy on the latest release of things available at the time".<p>So, there will probably be a substantial deployment of new projects / testing projects using the Linux 7.0 kernel along with the latest available software packages in a few weeks.
This seems to be brushing off a major performance regression just because you personally don’t upgrade for 4 years. I don’t think that’s common at all.
<a href="https://fr.archive.ubuntu.com/stats/stats_of_day-16.html?version=last#:~:text=April%2030%2C%202006,data%20are%20excluded%20from%20statistics)%20:" rel="nofollow">https://fr.archive.ubuntu.com/stats/stats_of_day-16.html?ver...</a> no need to think, data backs it up
Someone said "its fine nobody uses this" and someone else gave the world's biggest slam dunk of "Ubuntu in 1 month" and your reply is that "not everyone does it". How far from the point can you be!<p>In the Linux world this is the worst possible scenario, distro with the largest adoption, LTS.
22.04 is still potentially more prevalent than 24.04 according to <a href="https://fr.archive.ubuntu.com/stats/stats_of_day-16.html?version=last#:~:text=April%2030%2C%202006,data%20are%20excluded%20from%20statistics)%20:" rel="nofollow">https://fr.archive.ubuntu.com/stats/stats_of_day-16.html?ver...</a> . 26.04 will take some time before it's largely adopted.
Not trying to downplay the importance of this, but the LTS versions aren't until the first point release, so 26.04.1 (typically six months or so after the release).
That's the advantage of LTS? 24.04 is the LTS, not the one you use, 22.04.
22.04 is also an LTS release, supported for another year still.<p><a href="https://ubuntu.com/about/release-cycle" rel="nofollow">https://ubuntu.com/about/release-cycle</a><p>We're just now looking at moving production machines to 24.04.
All even number .04 releases are LTS in Ubuntu
Not necessarily;<p>```
$ grep PREEMPT_DYNAMIC /boot/config-$(uname -r)
CONFIG_PREEMPT_DYNAMIC=y
CONFIG_HAVE_PREEMPT_DYNAMIC=y
CONFIG_HAVE_PREEMPT_DYNAMIC_CALL=y
```<p>if your kernel has CONFIG_PREEMPT_DYNAMIC then you can go back to the pre 7.0 default by adding preempt=none to your grub config. I haven't seen any plans by Ubuntu to drop CONFIG_PREEMPT_DYNAMIC from the default kernel config.
I think most people on enterprise-y systems wait for (at least) 26.04.1, the window is 3 years (when on 24.04, which is supported until ~2029-04-30, it's 1 year when on 22.04) starting now, hardly anyone switches immediately.
Depends on your shop.<p>As someone with a heavy QA/Dev Opps background I don't think we have enough details.<p>Is it only ARM64 ? How many ARM64 PG DBs are running 96 cores?<p>However...<p>This is the most popular database in the world. Odds are this will effect a bunch of other lesser known applications.
Please follow the complete thread: <a href="https://lore.kernel.org/lkml/xxbnmxqhx4ntc4ztztllbhnral2adogseot2bzu4g5eutxtgza@dzchaqremz32/" rel="nofollow">https://lore.kernel.org/lkml/xxbnmxqhx4ntc4ztztllbhnral2adog...</a><p>> [...] used huge_pages=on - as that is the only sane thing to do with 10s to 100s of GB of shared memory [...] if I <i>disable</i> huge pages, I actually can reproduce the contention [...]
We need some sensible people running the latest and greatest or we won't catch things like this.
That may be the case, but it’s still not a great situation to be in and one has to wonder: if PostgreSQL is affected, what else is?
That's the big thing - PSQL will be tested, noticed, and fixed (and likely have a version that handles 7.0 by the time it's in common use).<p>But other software <i>won't</i> and may not even be noticed, except as a (I hate using the term) enshittification.<p>Better to introduce the "correct way" in 7.0 but not regress the old (translate the "correct" into the old if necessary) - and then in 8.0 or some future release implement the regression.
Exactly, this is how it’s usually done. As the developer on the mailing list mentions, implementing a new low level construct in 7.0 and a performance regression that requires said new low level construct to mitigate is not great. You need a grace period in which both old and new approach is fast.
If you're running in a docker container you share the host kernel. You might not have a choice.
The option to set PREEMPT_NONE was removed for basically all platforms.
[dead]
[dead]
Background on PREEMPT_LAZY:<p><a href="https://lwn.net/Articles/994322/" rel="nofollow">https://lwn.net/Articles/994322/</a>
Anyone check to see if Jia Tan has submitted any kernel patches lately?
I'm struggling a bit with why we need all these fancy dynamic preemption modes. Is this about hyperscalars shoving more VMs per physical machine? What does a person trying to host a software solution <i>gain</i> from this kernel change?<p>If a user wants to spin in an infinite loop all day every day, I don't see the problem with that. Even if the spinning will provably never do any useful work.
This makes me feel better about the 10% performance regression I just measured between FreeBSD 14 and FreeBSD 15.0.
Once again phoronix shoot out an article without further researching nor letting the mail thread in question cool down.
The follow up mails make clear that the issue is more or less a non-issue since the benchmark is wrong.
The following up mails conclude that the regression happens only when huge pages are not used.<p>While using huge pages whenever possible is the right solution and this should be enough for PostgreSQL, perhaps there are applications that cannot use huge pages and which are affected by the regression.<p>So I do not think that it is right to just ignore what happened.
It's not a good look to break userspace applications without a deprecation period where both old and new solutions exist, allowing for a transition period.
Once upon a time, Linus would shout and yell about how the kernel should never "break" userspace (and I see in some places, some arguments of "It's not broken, it's just a performance regression" - personally I'd argue a 50% hit to performance of a pre-eminent database engine is ... quite the regression).<p>Now, the kernel engineer who introduced the brand new mechanism (introduced in Linux 7.0) for handling pre-emption says the "fix" is for Postgres to start using this new mechanism (I think the sister comment below links to what one of the Postgres engineers thinks of that, and I'm inclined mostly to agree).
Freund seems to suggest that hugepages is the right way to run a system under this sort of load - which is the fix.<p>> Hah. I had reflexively used huge_pages=on - as that is the only sane thing to do with 10s to 100s of GB of shared memory and thus part of all my benchmarking infrastructure - during the benchmark runs mentioned above.<p>> Turns out, if I <i>disable</i> huge pages, I actually can reproduce the contention that Salvatore reported (didn't see whether it's a regression for me though). Not anywhere close to the same degree, because the bottleneck for me is the writes.<p>But, they can speak for themselves here [0].<p>[0] <a href="https://news.ycombinator.com/item?id=47646332">https://news.ycombinator.com/item?id=47646332</a>
Entertaining perspective - I thought that the whole "it's not an outage it's a (horizontal or vertical) degradation" thing was exclusive to web services, but thinking about it, I guess it does apply even in cases like this.
It wouldn’t be the first time one of the other maintainers ran afoul of “Linus’s law“.<p>He may simply be waiting until more is known on exactly what’s causing it.
> I'd argue a 50% hit to performance [...] is ... quite the regression<p>Indeed! Especially if said regression happens to impact anything trade/market related...
Well, the reason he'd yell about it is that someone did it. If no one ever did it, he'd never yell and we'd never have the rule. So one can only imagine that this is one of those things where someone has to keep holding the line rather than one of those things where you set some rule and it self-holds.<p>Doubtless someone will have to do the yelling.
This was my immediate thought - kernel doesn’t break software, or at least it didn’t used to.
Can someone explain to me what's the problem? I have very little knowledge of Linux kernel, but I'm curious. I've tried reading a little, but it's jargon over jargon.
I'm not familiar with the jargon either, but based on some reading it comes down to how the latest kernel treats process preempts.<p>Postgres uses spinlocks to hold shared memory for very critical processes. Spinlocks are an infinite loop with no sleep to attempt to hold a lock, thus "spinning". Previous kernels allowed spinlocking processes to run with PREEMPT_NONE. This flag tells the kernel to let the locking process complete their work before doing anything. Now the latest kernel removed this functionality and is interrupting spinlocking processes. So if a process that is holding a lock gets interrupted, all other postgres spinlocks processes that need the same lock spin in place for way longer times, leading to performance degradation.
From what I understand in the follow up: postgres uses shared memory for buffers. This shared memory is read by a new connection while locked.<p>In postgres, connections are handled with a process fork, not a new thread. If such a fork first reads memory, even if it already exists, that causes a minor page fault, which goes back to the kernel so it can update memory mapping tables.<p>The operation under lock is only a few instructions, but if it takes longer than expected, then that causes lock contention. Regression in the kernel handling minor faults?<p>The whole thing is then made worse because it's a spinlock, causing all waiting processes to contend over the cpus which adds to kernel processing.<p>Mitigated by using huge pages, which dramatically reduces the number of mapping entries and faults. I reckon that it could also be mitigated in postgres by pre-faulting all shared memory early?
<a href="https://lkml.org/lkml/2012/12/23/75" rel="nofollow">https://lkml.org/lkml/2012/12/23/75</a>
Not sure why people have to upgrade to the newest major kernel version as soon as it is released.
It's the performance team's job to test these things. Doesn't mean they're going to deploy it immediately.<p>Someone should be testing these things and reporting regressions
If nobody tests and reports these things when the version is released the regression would not be fixed when people start using it in production.
Don't make excuses.
[dead]
Perhaps in due time we will see workload specific forks of Linux maintained by a team of agents