Re: Fix rounding method used to compute huge pages

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Anthonin Bonnefoy <anthonin(dot)bonnefoy(at)datadoghq(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Fix rounding method used to compute huge pages
Date: 2026-01-23 16:49:16
Message-ID: aXOmjM69GVTbzhGE@nathan
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Committed.

On Fri, Jan 23, 2026 at 09:21:53AM +0100, Anthonin Bonnefoy wrote:
> From my understanding, 'add_size(hp_required, 1)' will never overflow
> since size_b was checked for overflow, and hp_size should always be >1
> (except if huge pages of 1 byte exist somewhere).

That's true, but for this sort of thing, I usually prefer to avoid relying
on those kinds of assumptions to reason about the correctness of the code.
The overflow check costs little, and IIUC this function is run exactly once
for the lifetime of the server.

> For consistency with CreateAnonymousSegment, using 'add_size(size_b,
> hp_size - (size_b % hp_size))' will also check that the final
> requested allocation doesn't overflow.

*shrug* I don't see a strong reason for consistency here. AFAICT you'd
have to be trying to allocate something like 18 exabytes on most systems
for there to be a problem, at which point there are probably bigger issues
to sort out.

Thanks for the patch!

--
nathan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2026-01-23 17:15:40 Re: Import Statistics in postgres_fdw before resorting to sampling.
Previous Message Joel Jacobson 2026-01-23 16:40:57 Time to add FIDO2 support?