Re: Fix rounding method used to compute huge pages
Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
From: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Nathan Bossart <nathandbossart@gmail.com>, PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2026-01-23T08:21:53Z
Lists: 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.
Commits
-
Fix some rounding code for shared memory.
- 8eef2df1898c 19 (unreleased) landed