Re: Fix rounding method used to compute huge pages

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

On Thu, Jan 22, 2026 at 10:24 PM Nathan Bossart
<nathandbossart(at)gmail(dot)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.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nikhil Kumar Veldanda 2026-01-23 08:25:33 Re: Some tests for TOAST, STORAGE MAIN/EXTENDED
Previous Message Peter Eisentraut 2026-01-23 08:20:29 Re: warning: dereferencing type-punned pointer