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 1wACjw-002A9x-1G for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2026 20:09:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wACju-002EyQ-1s for pgsql-hackers@arkaria.postgresql.org; Tue, 07 Apr 2026 20:09:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wACjt-002EyH-1i for pgsql-hackers@lists.postgresql.org; Tue, 07 Apr 2026 20:09:34 +0000 Received: from fout-b5-smtp.messagingengine.com ([202.12.124.148]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wACjq-00000001Aqm-1EI2 for pgsql-hackers@postgresql.org; Tue, 07 Apr 2026 20:09:33 +0000 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfout.stl.internal (Postfix) with ESMTP id A6D2F1D000AC; Tue, 7 Apr 2026 16:09:26 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Tue, 07 Apr 2026 16:09:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1775592566; x=1775678966; bh=0oro/CIvqC tMp13eG0OhtggFZZfkhYKQ/hHkR8z6fes=; b=c3/zRnvzwPia6YcFt5oXRHeK6K d3+uJF+zNg2zUHqBP4yy6TU9pvHcI/IZVkLbXiyB9djvhDqIPQphCZjJ4L8Vc0J7 8Ce7qkxZ15v/E3SrfuDxhiR+gIvnDjjkxkkZ/a1UGwLhmBbWY7EqFq4LtHt//HdS qgfolbc6D44zcY+W6ZhlRjJWbPQtEy3GqZzzJdCn5h6K/gr9c5EZXo++V0PGfRDc eloyrDpQ0qEajG+PQMNzrMagUBDnfZzyt21KiSHc+PYSE/D896C1cqiTQM0Gmo1t yU1Ye6s9K/xqYaJ85FfMONzEVLyM4Iip5/rXNwFwglq5B63DiM487FBcuh4A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1775592566; x=1775678966; bh=0oro/CIvqCtMp13eG0OhtggFZZfkhYKQ/hH kR8z6fes=; b=RHL2k+WugQOUruT8DOhrHSuCw+pK073quV05fI/+896gyhEor7y PKoDGxk6TkJZHOuDXPrKOmq0OJihy0lFWarpXSDFyKviFoMsEmb2qQXT/UtvPFim ccM0/O/trQYW9x/RmqKPEbh3OZnwfdSA2MNu0tLwmJUQeYCKS7x9dXebwrOEcHEl KDDDQStSPqLELfYh7maY/d9Wb8cYouClq/bqyk1FePQ3K6HCB9KDStOzPUzDtAYt iwfhoIj3o8RabJOkLcQ1Qx8jcR3rHFSHBoXCGzHLwvwTBWitxBxZHicYCBt35Db7 K4ZknSc2AY8vaJKH7bye/13r2BQD/bmpV3Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddvudehkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpeffhffvvefukfhfgggtuggjsehttdfstddttddvnecuhfhrohhmpeetnhgurhgvshcu hfhrvghunhguuceorghnughrvghssegrnhgrrhgriigvlhdruggvqeenucggtffrrghtth gvrhhnpeetveeuuefhiedvheefhfetgfejvdfgieekueffgfejveejffetgeduvdejgeek keenucffohhmrghinhepmhhitghrohhsohhfthdrtghomhenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgiivghl rdguvgdpnhgspghrtghpthhtohepiedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoh eprghshhhuthhoshhhrdgsrghprghtrdhoshhssehgmhgrihhlrdgtohhmpdhrtghpthht ohepsghovghkvgifuhhrmhdophhoshhtghhrvghssehgmhgrihhlrdgtohhmpdhrtghpth htoheptghhrghtuhhrvhgvughiphgrlhgrkhduleduudesghhmrghilhdrtghomhdprhgt phhtthhopehrohgsvghrthhmhhgrrghssehgmhgrihhlrdgtohhmpdhrtghpthhtohephh hlihhnnhgrkhgrsehikhhirdhfihdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhs sehpohhsthhgrhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 7 Apr 2026 16:09:25 -0400 (EDT) Date: Tue, 7 Apr 2026 16:09:25 -0400 From: Andres Freund To: Heikki Linnakangas Cc: Ashutosh Bapat , Matthias van de Meent , Robert Haas , pgsql-hackers , chaturvedipalak1911@gmail.com Subject: Re: Better shared data structure management and resizable shared data structures Message-ID: References: <7d3ba240-9350-4dfc-bbe1-be6584aee236@iki.fi> <1c3a07a7-158d-4800-927c-2641c73277d8@iki.fi> <6d4383eb-4aaa-47ae-bda8-ee40dc60ad84@iki.fi> 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 Hi, On 2026-04-07 22:48:17 +0300, Heikki Linnakangas wrote: > > +/* > > + * ShmemResizeStruct() --- resize a resizable shared memory structure. > > + * > > + * The new size must be within [minimum_size, maximum_size]. If the structure > > + * is being shrunk, the memory pages that are no longer needed are freed. If > > + * the structure is being expanded, the memory pages that are needed for the > > + * new size are allocated. See EstimateAllocatedSize() for explanation of which > > + * pages are allocated for a resizable structure. > > + */ > > +void > > +ShmemResizeStruct(const char *name, Size new_size) > > This interface only allows shrinking and growing the allocated region at the > end, but the underlying mechanism is madvise(MADV_REMOVE) and > madvise(MADV_WRITE_POPULATE), which supports also "punching holes", i.e. > freeing memory in the middle of a region. Do we gain anything by restricting > ourselves to changing the size at the end? It seems to me that it could be > handy to punch holes for some use cases. Agreed. The hard part may be the "communication" with the user about how granular the punches can be. Because that will depend on things like huge_pages, huge_page_size and may depend on what alignment you happened to get. > What's the portability story? I understand that this is Linux-only at the > moment, but what platforms can we support in the future, and what's the > effort? I think BSD's have similar capabilities with plain mmap() and > MADV_FREE if I read the man pages right. At least linux' MADV_FREE is only for private mappings. It's not clear in at least freebsd's man page, but the described use case makes me suspect it may be similar there. > What about macOS and Windows? This doesn't necessarily need to be fully > portable, if some OS's don't have the capabilities we need, but would be > nice to know what's possible. Looks like windows has OfferVirtualMemory https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-offervirtualmemory but it's not clear to me if it actually does what we need when multiple processes are attached. I suspect it's going to be a lot easier once we're threaded... The reason I am ok with doing resizing this way before threading is because it's architecturally pretty similar to what you'd want to do once threaded, so it's not a huge dead end. But I'm doubtful we'll find facilities that allow this across processes in all operating systems... Greetings, Andres Freund