Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vjKLa-00D4ki-0M for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Jan 2026 16:49:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vjKLZ-000gCQ-0R for pgsql-hackers@arkaria.postgresql.org; Fri, 23 Jan 2026 16:49:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vjKLY-000gBw-2Y for pgsql-hackers@lists.postgresql.org; Fri, 23 Jan 2026 16:49:21 +0000 Received: from mail-oi1-x235.google.com ([2607:f8b0:4864:20::235]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vjKLW-001wM1-1G for pgsql-hackers@postgresql.org; Fri, 23 Jan 2026 16:49:20 +0000 Received: by mail-oi1-x235.google.com with SMTP id 5614622812f47-45c92df37fdso1158335b6e.3 for ; Fri, 23 Jan 2026 08:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769186958; x=1769791758; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=rD9NaJNacShHIKT/YP53UQCkvALOV2Jvu7VOHqDvJG4=; b=JlnuTugfbpnUbj875QzayXn4C9id4jS6BeKwGGWaXAnVWkh4N39hYX2M6iA6Nyd9Kn /oJisZq2uG6jsXhaSLcflUxJzePRuGNS+V+kLY8ZddQIIFnhBLUpBLDYovWLKxjciYfJ FL5qiAKOJYToFpauUh0N+7qAAV0VVAjweHw6WjEy9yooWp290dpFWe0OFY0rphbpYL93 LUPplqsbpUBth30yBaYJcv2esob0VDnhp33bz4FfmM/0RrMb6/zdkNbjjymatPGDivxp yVStfEOjsPHPte7CknOMCY0SmzAF9n/CLuE+VsF3O1/PR0bHn+3s4knge+/WYsq+1O/j RzSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769186958; x=1769791758; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rD9NaJNacShHIKT/YP53UQCkvALOV2Jvu7VOHqDvJG4=; b=M8LsOiCugUqLFZiqPxRWBWTlWXhC8QhwSVCBZcdcdR35PVGfE/96t4T1vs1NWEeFfz mIsKwjkobC63EYEScY8ZzP7KR1kRiu3By5RJcd5GrS8piREfB0srMXyyV3kcDYYrCir4 c1BDAr0zJoxCczWeXY8EnNVm62JLeVI/Vkcn++prRoL77CvX97Pa++Afg5axVMcTDPAw yA5n+XRlzv2ffluTFkFMutYrusk/bshVRdZ1C4Fp8xMSUPZ3mqvgxaD56o0tp/2vUHzc e5JQsoD2sRn6D48UaAyvjpZ+x1YdZqGQoYwnet45EOjVScleD/jTzusJinfipn4JxWpL RmmQ== X-Forwarded-Encrypted: i=1; AJvYcCVnmObuuAqD79hdAyxP8sug7xaOBja6L4Q8xbbDdsCrn8I9SAvIiwpI6qTNz1mAUYDb8+kuehLYSL2G4X9X@postgresql.org X-Gm-Message-State: AOJu0Yzb2mhH0qGw3bEL/neuf9+IHzNPH+bO1c7QVt5JYN8IBGsUkR58 Rd8W6Z4m7lKc/x0fDEVORQvg0kOtds0IycYB96IBPh39rak0gNXn0/NO X-Gm-Gg: AZuq6aIg3v6SCkZepW4TOKkePBvY04EulWU7owglWomLQHXR5b6tmPesIK69ly+Z177 aTIOiIhiv95cKJpbSBLRIMXptyqfmw69L5LUXKyDjY7WcyvVB3v4iSQZaf08jDR8gcxTDvdt09F sxskbvjSLsdLmhyYL0v7at/4TnZRKgey+6BchTDJYu1OeuHP1GZlfHRz7mGiSCgI6jDoJVXswoZ Ac2prSR3bvDVXHTwIKWdnsNKUPEFbWJgul8FLzl2Hwz6YMN01MIety0RXQ/acPFcBdKrE8FiFrL SbnTz0tmkU0wt0vGbmZ90yAvRqFxxt8Dd5WXC+9zIMDaaqCxGux4LaMqFpDXA6V060y1nb2Oa6y uj0d0rnLX0HP/x0w3++7hYFYjwGPSHeH1ZaJkd5pyL8G1RFCwAkLXlz1hBJu7JJ4QViiGYLvZd9 Lw2WiV9rEGDLJ3CPSKNysKkdr+ X-Received: by 2002:a05:6808:4f08:b0:450:d833:6bb9 with SMTP id 5614622812f47-45ebb896555mr757667b6e.60.1769186958492; Fri, 23 Jan 2026 08:49:18 -0800 (PST) Received: from nathan ([159.251.12.70]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-408afba74casm1784318fac.14.2026.01.23.08.49.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jan 2026 08:49:18 -0800 (PST) Date: Fri, 23 Jan 2026 10:49:16 -0600 From: Nathan Bossart To: Anthonin Bonnefoy Cc: Michael Paquier , PostgreSQL Hackers Subject: Re: Fix rounding method used to compute huge pages Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Committed. On Fri, Jan 23, 2026 at 09:21:53AM +0100, Anthonin Bonnefoy wrote: > 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). That's true, but for this sort of thing, I usually prefer to avoid relying on those kinds of assumptions to reason about the correctness of the code. The overflow check costs little, and IIUC this function is run exactly once for the lifetime of the server. > 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. *shrug* I don't see a strong reason for consistency here. AFAICT you'd have to be trying to allocate something like 18 exabytes on most systems for there to be a problem, at which point there are probably bigger issues to sort out. Thanks for the patch! -- nathan