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

From Nathan Bossart
Subject Re: Fix rounding method used to compute huge pages
Date
Msg-id aXKVfaTntXRn1V0m@nathan
Whole thread Raw
In response to Fix rounding method used to compute huge pages  (Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>)
Responses Re: Fix rounding method used to compute huge pages
List 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



pgsql-hackers by date:

Previous
From: Ilia Evdokimov
Date:
Subject: Re: Optional skipping of unchanged relations during ANALYZE?
Next
From: "Matheus Alcantara"
Date:
Subject: Re: [PATCH] llvmjit: always add the simplifycfg pass