Re: Fix rounding method used to compute huge pages - Mailing list pgsql-hackers

From Anthonin Bonnefoy
Subject Re: Fix rounding method used to compute huge pages
Date
Msg-id CAO6_Xqp8NVAeNuDgWaMW_+AKHSQTC4nARbJVW23DkXT6KGh81Q@mail.gmail.com
Whole thread Raw
In response to Re: Fix rounding method used to compute huge pages  (Michael Paquier <michael@paquier.xyz>)
Responses Re: Fix rounding method used to compute huge pages
List pgsql-hackers
On Thu, Jan 22, 2026 at 10:24 PM Nathan Bossart
<nathandbossart@gmail.com> wrote:
> Oops, it looks like this is my fault.  I doubt this causes any practical
> problems, but we might as well fix it.

Yeah, the chance of this being a problem is pretty low.

> +               if (size_b % hp_size != 0)
> +                       size_b = add_size(size_b, hp_size - (size_b % hp_size));
> +               hp_required = size_b / hp_size;
>
> I think we could simplify this a tad:
>
>         hp_required = size_b / hp_size;
>         if (size_b % hp_size != 0)
>                 hp_required = add_size(hp_required, 1);

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).

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.



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: warning: dereferencing type-punned pointer
Next
From: Nikhil Kumar Veldanda
Date:
Subject: Re: Some tests for TOAST, STORAGE MAIN/EXTENDED