Re: Fix rounding method used to compute huge pages
Nathan Bossart <nathandbossart@gmail.com>
From: Nathan Bossart <nathandbossart@gmail.com>
To: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2026-01-22T21:24:13Z
Lists: pgsql-hackers
On Thu, Jan 22, 2026 at 05:42:44PM +0100, Anthonin Bonnefoy wrote: > When computing the dynamic value of shared_memory_size_in_huge_pages, > (1+size_b/hp_size) is currently used. This works when size_b is not > divisible by hp_size. However, it will yield an additional huge page > when size_b is divisible by hp_size. Oops, it looks like this is my fault. I doubt this causes any practical problems, but we might as well fix it. + 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); > 0002: This patch uses add_size in CreateAnonymousSegment when the > allocation size is rounded up, to check for possible overflow. Seems reasonable. -- nathan
Commits
-
Fix some rounding code for shared memory.
- 8eef2df1898c 19 (unreleased) landed