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 1vP6BI-004Pvj-2h for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Nov 2025 21:39:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vP6BH-00DgQu-11 for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Nov 2025 21:39:07 +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 1vP6BH-00DgQl-04 for pgsql-hackers@lists.postgresql.org; Fri, 28 Nov 2025 21:39:07 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vP6BF-0020h1-06 for pgsql-hackers@postgresql.org; Fri, 28 Nov 2025 21:39:06 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-640bd9039fbso4593273a12.2 for ; Fri, 28 Nov 2025 13:39:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764365944; x=1764970744; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=VJD4hsuHMtGeeX+z0/mOFISyx8dPNtQ6B3ym7bscHtE=; b=MzRMy2XU2utlz6vTFlJKRDunyqr0bjTrfyxdtoQLnY5Mg7c/UMK88uu3/Y7FHSZ8VF HRNZ2wkWGqaDUKSy0Td/+0FcYqwWf22LyGUaUbG6eR44MVTwqux336/gEXftN4Jyf/dy LkVITKSyMY5zQ4UdppKk7qb2wXZRA48NP9F409ewdQlLg9b5FRlToAZVFfSyr2muIisW cxlbMcn22un73C7j/RpAa+nn0NVsqbawlcJC9m3wwRkbKnspnrptOY45tTebGeAVuVkT Roz5S/STMtYuZq/rEF2xEw4DxkygJj+M5h/0Upc+gZBNibwN8mwbj4cCqRVu+8MlTT8D WO1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764365944; x=1764970744; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=VJD4hsuHMtGeeX+z0/mOFISyx8dPNtQ6B3ym7bscHtE=; b=iRQiSNrZujZj4s7TeV4BhF+BUVMluFkP/4Wl/vontDI5JCvzIx+o6IisaAV/Pj161C Q8X2jSCTOSbKcsuBSCzYeJ50Zz6PBaF0PzJ54rqm6tMSsEE71m2IGP1RAG2VrOAwtu0U ej3FM6EqxN6HRWbDpdtfGPoEXT9phxoflEoEXJ1h7xoej1KKQJ3xrpb4fkYeHTps0mR0 6epXuE73cUa9XL6Tne1/6EwYShFZspYDVHhyz8A9R8g3mVnq5YPdFyGweCEXM/1uj0S3 qW6QpbeLFSg9PPPmMynQvUTiTuXB3MTRYP+x/4zQfrkVfVfagjj5iq0+TWBGJ0GchR9j HtFw== X-Gm-Message-State: AOJu0Yye8cnxS22YOBTQnt4hjZtUeidTTjZ63ynEoDZrLkQrTBHdrrQK +fv5yO+mvmHD8U8CPvaZ15sKWcav1RRrXH5B/vdbuqK68IZpAyzuE5Ss X-Gm-Gg: ASbGncsfIbIQX89SpKPjZgXrF64DyspR3ZZkjEcKbB3rMuEfDex47BKuYkJ73vv7XCy x7KrCNG5rgJ+EvHQg6hRJUbHhoCVjR5DfxUOVuv8VmqW0ZQMzAXRXNfINFXEtgc+KG+oYzTgfBk JCJe94lqc//LKkWUha5UO0fpdgn+M2NDuIZ7p4EEp2qYsDoPQFteegtARtVm1HOkwy3SpEqB5as XOk0x96oShvX1bFavY9287hCv6MmG1tDX+DAdzUPpzaOxkM09fXHUxU+mAwmmILDjJnScVyzUYZ aa4P7fu2wr8n+BlgRB7jQa1bRqg9PJrWsYjOeKEE3MbVdLiLU0rXLCgQ86hP/jtadznYRAzBpZ7 OK8ausTIpnM3VY++0YYFAUvmHyoYUGtm/CfSEzKf/gs87cEmLH9+6oen4xzXfus5oRyWVTy5MiS KC7q/PPMZPSv7bdjdgmgN5 X-Google-Smtp-Source: AGHT+IHsfsWvLopWMnbtS3TRlm/MkpXuC5oW4RXgCXLSbrJJUGD4WgU2GNDUyBL210InkVt3rUnmSA== X-Received: by 2002:a17:907:96a6:b0:b50:a389:7aa4 with SMTP id a640c23a62f3a-b7671547e0fmr3127578866b.13.1764365943963; Fri, 28 Nov 2025 13:39:03 -0800 (PST) Received: from [192.168.2.32] ([165.225.27.7]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b76f5a3a4ebsm535429866b.62.2025.11.28.13.39.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 28 Nov 2025 13:39:03 -0800 (PST) Message-ID: <0d14cdd2-eab6-40ab-beaf-60c56c16e375@gmail.com> Date: Fri, 28 Nov 2025 22:39:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Consistently use palloc_object() and palloc_array() To: Thomas Munro Cc: pgsql-hackers References: Content-Language: en-US From: David Geier In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Thomas! On 27.11.2025 03:53, Thomas Munro wrote: > On Thu, Nov 27, 2025 at 11:10 AM David Geier wrote: >> I've changed all code to use the "new" palloc_object(), palloc_array(), >> palloc0_object(), palloc0_array, repalloc_array() and repalloc0_array() >> macros. This makes the code more readable and more consistent. > > I wondered about this in the context of special alignment > requirements[1]. palloc() aligns to MAXALIGN, which we artificially > constrain for various reasons that we can't easily change (at least > not without splitting on-disk MAXALIGN from allocation MAXALIGN, and > if we do that we'll waste more memory). That's less than > alignof(max_align_t) on common systems, so then we have to do some > weird stuff to handle __int128 that doesn't fit too well into modern > thinking and also disables optimal codegen. > > This isn't a fully-baked thought, just a thought that occurred to me > while looking into that: If palloc_object(Int128AggState) were smart > enough to detect that alignof(T) > MAXALIGN and redirect to > palloc_aligned(sizeof(T), alignof(T), ...) at compile time, then > Int128AggState would naturally propagate the layout requirements of > its __int128 member, and we wouldn't need to do that weird stuff, and > it wouldn't be error-prone if usage of __int128 spreads to more > structs. That really only makes sense if we generalise > palloc_object() as a programming style and consider direct use of > palloc() to be a rarer low-level interface that triggers human > reviewers to think about alignment, I guess. I think you'd also want > a variant that can deal with structs ending in a flexible array > member, but that seems doable... palloc_flexible_object(T, > flexible_member, flexible_elements) or whatever. But I might also be > missing some parts of that puzzle, for example it wouldn't make sense > if __int128 is ever stored. > > [1] https://www.postgresql.org/message-id/CA%2BhUKGLQUivg-NC7dHdbRAPmG0Hapg1gGnygM5KgDfDM2a_TMg%40mail.gmail.com These are some interesting ideas but I would consider them for now as possible follow-up work, once this refactoring is merged. -- David Geier