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 1vqrtO-0027vP-22 for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Feb 2026 12:03:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vqrtN-00EDg9-1E for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Feb 2026 12:03:26 +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 1vqrtN-00EDg1-00 for pgsql-hackers@lists.postgresql.org; Fri, 13 Feb 2026 12:03:25 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vqrtK-00000000ROg-1zAD for pgsql-hackers@postgresql.org; Fri, 13 Feb 2026 12:03:24 +0000 Received: from [10.0.2.15] (unknown [130.41.208.2]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4fC9mK3rR5z49PsK; Fri, 13 Feb 2026 14:03:13 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1770984194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fQxQpaK3Ze1I2zICwxYUvqKnv2XuDOcEKZQkzKPvxtQ=; b=Vl39OfZYHhbeWH6htt1C90FNZfyWPQvtQocSJRW8kk0gYenUYF/9B7AYz8EV183UTKzDKL RTCZqDhpU1HbrCJd3C1Eg39YcGqE/jdRfMt5mg9BRQbhnvGFJVo6gVA8xGUudgEzmpWwa3 SXKpPSws7diSiULFy7BG1zefr1uOzNGlgmCPatdkuvqv2Ci8raCyMwimQ+/I+jW9jTFAXl gtrraz3f6Gf56UBq7Hda9F4s18wa1YAwVLb4AhMvBvRUJqYM0DsVfLvz2R6ePKIS2erM6X h5VlEgmOGGTgtC/oMkfXKTZdv/nO1wzpaPCko5eQE76iB1rAOsmYkBWHGnmxkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1770984194; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fQxQpaK3Ze1I2zICwxYUvqKnv2XuDOcEKZQkzKPvxtQ=; b=H/ewoz9fv0GpjW3DJ08V6hnxBLMU/03W35nioefQkgLmsE+mDIgokDtUXGV5mdMAkTb6+q 6WAZA9z/Z0D8MDpQDi4qoWUvjmbgd60OJfTZ/k0jYHfZnS6A6j+cEBOCPqKymss7hAYQ2B 4+0koFfqyl5J16QeVaSFgIfKYwt1eManDhHOWI2JMsBlSpREWjKCS5pF/e82MThPl2UCAE MBI/iZ/t+07L0Otzy0FoypzsIASqtxz88A+hF24DIPd6VxKcBOyStTHnPyV0AQLFeodSMl g8wG3LrFfxW4qHZLTLTqdQ1cUfzRwSvcWiWakjFuhH6do4dXszLiGT1PYqZu7g== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; a=rsa-sha256; d=iki.fi; s=lahtoruutu; cv=none; t=1770984194; b=iJCywJnRlYMsGOP0aiAZtXpD3gg0yBslebB4mNUEkeQbz9zZEb5hRRdNfQFwyahZGCG7aF oO82NhRs5eCS5bNOlsnLtqchB53r7IMzgDjFgZe/D7Bz2670zfYvWTIAhr0hUT7XS6X9gq F/UC+zrTbTfacwT/iAXIsj29hff6zWK39Rvz7gSTVQgX3tfqY33CO+z5alIIopfv2AzD/y BA2FivmlJKdRJMBTuexkzf50k3nSRaF+NeIwL91Blg+ozDiHgXpvgF+sDaSV0NdOMfdjxT FTRrOD0AsLJiGkoJKbZbtRAL3vYmAB25dHigw39g6UDboXYMfBbUpKvA7UVF7g== Message-ID: <5a37c2e3-619d-4816-84d7-0b27e3e6797f@iki.fi> Date: Fri, 13 Feb 2026 14:03:12 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Better shared data structure management and resizable shared data structures To: Ashutosh Bapat , pgsql-hackers , Andres Freund Cc: chaturvedipalak1911@gmail.com References: Content-Language: en-US From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 13/02/2026 13:47, Ashutosh Bapat wrote: > `man madvise` has this > MADV_REMOVE (since Linux 2.6.16) > Free up a given range of pages and its associated > backing store. This is equivalent to punching a > hole in the corresponding byte range of the backing > store (see fallocate(2)). Subsequent accesses > in the specified address range will see bytes containing zero. > > The specified address range must be mapped shared > and writable. This flag cannot be applied to > locked pages, Huge TLB pages, or VM_PFNMAP pages. > > In the initial implementation, only tmpfs(5) was > supported MADV_REMOVE; but since Linux 3.5, any > filesystem which supports the fallocate(2) > FALLOC_FL_PUNCH_HOLE mode also supports MADV_REMOVE. > Hugetlbfs fails with the error EINVAL and other > filesystems fail with the error EOPNOTSUPP. > > It says the flag can not be applied to Huge TLB pages. We won't be > able to make resizable shared memory structures allocated with huge > pages. That seems like a serious restriction. Per https://man7.org/linux/man-pages/man2/madvise.2.html: MADV_REMOVE (since Linux 2.6.16) ... Support for the Huge TLB filesystem was added in Linux v4.3. > I may be misunderstanding something, but it seems like this is useful > to free already allocated memory, not necessarily allocate more > memory. I don't understand how a user would start with a larger > reserved address space with only small portions of that space being > backed by memory. Hmm, I guess you'll need to use MAP_NORESERVE in the first mmap() call. to reserve address space for the maximum size, and then madvise(MADV_POPULATE_WRITE) using the initial size. Later, madvise(MADV_REMOVE) to shrink, and madvise(MADV_POPULATE_WRITE) to grow again. - Heikki