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 1wAJvI-002Ghx-05 for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 03:49:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wAJvG-004WM5-1b for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 03:49:46 +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 1wAJvG-004WLw-0a for pgsql-hackers@lists.postgresql.org; Wed, 08 Apr 2026 03:49:46 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wAJvE-00000001EWw-2eKa for pgsql-hackers@postgresql.org; Wed, 08 Apr 2026 03:49:46 +0000 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-43cfb723698so4945012f8f.3 for ; Tue, 07 Apr 2026 20:49:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775620183; cv=none; d=google.com; s=arc-20240605; b=Mo5TZNKf9k7l2e4LZ9NuwCeEIfy4t4BoF2XgjrPg/XimRu13cjtcCDlmzcTSXf4EM4 SoBhrMdy/Zrpg1s0+hJXc77Jo64ZbNBaK4mnrK4/7VGmYAIYDCNEltoJihz/wB6ggORQ CeqCwfe2pKmW6uEd1tNpvulYb/d+7rTXlucyktFeeZHGkVDlmusou0mRaWgFRk43ktvh L5zo6n4vUucjMPk982oLWINJXkU/6xVYvP4e7jyhpEqxthNJ75veSxY41ChgoAnqsA5Z VemRvpPgc87jEUI/RHq0acj14CSnxkQ1Xhrqx1b9S53b4RU9K2ut25wu3KQyP5vwfhIN Fpxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=/QnI9obndESOLAFK8E2aSdC0e+TkkSJ68ihOEEpJ40s=; fh=iRQFbGEfvkTWXQHkuFgLSDT5JioHL4bKmpSICYtjxFg=; b=iio8RSuc1JEgBb4HZBGaZUcesx5DaQqnc7wZ+Vp5SCc1Lxm+Zf1dpYaDE9pZbIXiSU AswA0SijO92NM338hb+6mfOOs1iekGNg6HFeNbRQLNGiXlRnLZTPgx7N9o1xNb00hpwe 8WTBQHpIFpv1RMoRyYsu5Lc520QZXetm9F9lIh68MAA70CsJRa7Ynf4+x39Vazw7Oool 2WguEL+Pz97SrSOHjjrq8EyJIfbPgmY+ybNeE+sRPoGJuX0pcg0ZVTYtHByd9l4OEyQX 8Iqn921M3mg+vsv8P4Lm9MudRwiCgNJRpcdCcKfGPEcfAXjehdqes04tAafQpCAMogqM UN7w==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775620183; x=1776224983; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=/QnI9obndESOLAFK8E2aSdC0e+TkkSJ68ihOEEpJ40s=; b=dYbV5/4Z6sYjQPYKpO/akC6kcBFzj7y7xsn3ph379yCHT4f1KDKjt3KrgJPvTe+3AM yLrPYtEi+VLM5DbJ6C/04f7AynRvZoYdoByjglx+TS71otjnLPOtN6Sa7ouOYy5s2vYp YPq7J32leF/DlkGrfOnR7GzLC5cyjLxDjy3uQc0XU5f0HmDCNh7G8o6L8cJtD5MVyN7E I1MKXojJvh41QNv9SePqIxU3uxcjb/ZhEuHufrWhCqkMUDVb9C9dkKp2qv8p5D0MNMty TodZnQuStxbRbjxyX8egTweoQw8WaXa3JEzXwaHy2yu0REHnSaLIVEHeXSaK5+1/1tv7 JNVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775620183; x=1776224983; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=/QnI9obndESOLAFK8E2aSdC0e+TkkSJ68ihOEEpJ40s=; b=DBKdJw5fEI/eXyjt/0J1RbNoRrb1H3DpEZLgjFOtgunM17a5H/dRJRb8D0/CX8hyOJ fFMX1i2rgdX3WJBV6B81nvdBU7Ojm21T/I894jW3WcNqNeySf5hhG14J213ozVafZImd Z4iYUpaYRgfW60xHYDmHHs45PLwBofRGwBoxDx1z1X62+MQAdfCzKUFKwtcmyON3XAsK OKI+UGxGbTd6yvvLDTEz7SVGsUDr49pzpt+7JubD++7APLKp8w1IunN5GRO+75S6ktes 04nnOCJox7MwybJuVU7BvOKt1s4I216HVePOirbGFCKTkUEt1diWx7TNkL/QsGzlFa5d Ka2w== X-Forwarded-Encrypted: i=1; AJvYcCVIkSYa4tYrFyaXntDDU2Jp/8FxXk2IYRWB6wQhEKT5T5MKopmoo5bo1+Ugnh+vdtdJVf/x2zZCTQdZyBtb@postgresql.org X-Gm-Message-State: AOJu0Yxh1ejZKMj0RanZE/+smJHES4ohiG/4UTG0tKGUClIN6t0+gk1L JCDh8USBzFKT/HgxlGG+5JSk2D/6+J3a4A9AEVl83v7AeO4MgZLDi1D2nsylSh3XAuBvBLZtwmI PGjCljnZLiYdEp6doMD7APFu+EFdZ30M= X-Gm-Gg: AeBDievawrLUlKWEQ5QewGIL42CX56eKTZ/l2jf8uGxmUao8k1h9rn8pg6ZLlnluzmf YDS2/smgLXvQtCtAUGGMHySI6PM50CbEfOgEQgillhwM+Nq2SGkCkSugq+Y7rrduxunCLCfeQqi 7yHWdUlOnUlDoaSsVhUhurGvOXvva8CvWtco1x9tiumvTd75DNgJYm+YmQK3UIW/AqenVTvKfLc lnXo6kZoXllT/xkHr20402Mqd9L26ksSteD7hxIlysE134XryrQMp17zrAuxvsUKXVFtFwxJoHc cOWtbpyGraaMV4XFzFSlP03DXK1qoqKuKLepCJjKiXxo/JsFGkmrng== X-Received: by 2002:a05:6000:2c04:b0:43c:fd18:a317 with SMTP id ffacd0b85a97d-43d292d484dmr28453322f8f.38.1775620182869; Tue, 07 Apr 2026 20:49:42 -0700 (PDT) MIME-Version: 1.0 References: <791c3f18-f4de-4d84-ac6b-c7ccc074dd38@iki.fi> <9d919bd9-94dd-4bda-8ccf-ebced4178c53@iki.fi> <7d3ba240-9350-4dfc-bbe1-be6584aee236@iki.fi> <1c3a07a7-158d-4800-927c-2641c73277d8@iki.fi> <6d4383eb-4aaa-47ae-bda8-ee40dc60ad84@iki.fi> In-Reply-To: From: Ashutosh Bapat Date: Wed, 8 Apr 2026 09:19:26 +0530 X-Gm-Features: AQROBzDBQVmMDby3yY0nsPYDpSbt8I8fxdDly-vvsj2OL2S-NpUa-WxjRUlRC1Y Message-ID: Subject: Re: Better shared data structure management and resizable shared data structures To: Matthias van de Meent Cc: Heikki Linnakangas , Robert Haas , Andres Freund , pgsql-hackers , chaturvedipalak1911@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Apr 8, 2026 at 1:08=E2=80=AFAM Matthias van de Meent wrote: > > On Tue, 7 Apr 2026 at 16:47, Ashutosh Bapat > wrote: > > > > On Tue, Apr 7, 2026 at 3:36=E2=80=AFPM Ashutosh Bapat > > wrote: > > > > > > On Mon, Apr 6, 2026 at 7:23=E2=80=AFPM Ashutosh Bapat > > > wrote: > > > > > > > > I have kept these two patches separate from the main patch so that = I > > > > can remove them if others feel they are not worth including in the > > > > feature. > > > > > > Here are patches rebased on the latest HEAD. No conflicts just rebase= . > > > > > > Here are differences from the previous patchset. > > > > > > o. There are two patches in this patchset now. a. 0001 which supports > > > resizable shared memory and is equivalent to 0001 + 0002 + 0004 + 000= 5 > > > from the previous patchset. b. 0002 which is 0006 from the previous > > > patchset and adds support for protecting resizable shared memory > > > structures. 0003, which added diagnostics to investigate CFBot > > > failure, from the previous patchset is not required anymore since all > > > tests pass with CFBot. > > > > > > o. I have merged 0002 into 0001 from the previous patchset since with > > > that patch all platforms are green on CFBot. The resizable shared > > > memory test now uses /proc/self/smaps instead of /proc/self/status to > > > find the amount of memory allocated in the main shared memory segment > > > of PostgreSQL. > > > > > > o. Merged 0004, which supported minimum_size, into 0001. Minimum_size > > > would be useful to protect against accidental shrinkage of the > > > resizable structures. It will help additional support for minimum > > > sizes of GUCs like shared_buffers. It also makes it easy and intuitiv= e > > > to distinguish between fixed-size and resizable structures, and will > > > be useful to find the minimum size of the shared memory segment. > > I was thinking more along the lines of attached (incremental) patch > 0003 for min/max sizing. I'd say it has a slightly more natural API, > but YMMV. > Thanks for the proposal. There are some advantages and disadvantages of that approach. Let me explain. minimum_size =3D 0 seems more straightforward to me compared to the introduction of SHMEM_RESIZE_TO_ZERO - a value other than 0 to mean 0. That's confusing. The thought to modify the options in place did cross my mind and I started going that route. But soon realized that a. option is a caller structure which is not designed to scribble upon, b. it is saved as a request and used later. By scribbling upon it, we lose the intent of the original request, thus the saved request may be susceptible to a different interpretation in future. I would like to avoid scribbling as much as possible. The code after scribbling doesn't look materially improved than earlier. I like the error handling refactoring, but need to pay close attention to the details. I tried something similar that didn't work in all the cases. I will try your changes in the next version. 0004 actually changes the error message we throw when the request is opposite of the existing structure. Is that intentional? But I guess some of it can be absorbed to simplify the code here. The macro definition is confusing. +#define CHECK_SIZE(size) \ +do { \ + /* Check that the sizes in the index match the request. */ \ + if (request->options->size !=3D SHMEM_ATTACH_UNKNOWN_SIZE && \ + index_entry->size !=3D request->options->size) \ + { \ + ereport(ERROR, \ + (errmsg("shared memory struct \"%s\" was created with" \ + " different %s: existing %zu, requested %zu", \ + name, CppAsString(size), index_entry->size, \ + request->options->size))); \ + } \ +} while (false) Ideally size here should be in paranthesis. Its easy to confuse request->options->size to mean request->options->size when it actually means request->options->{maximum/minimum}_size. Is that right? Possibly a static inline function where we pass corresponding members of request->options and index_entry? > ----- > > I also noticed that it's probably not correct to "just" check and > complain about the size of a resizable shmem segment when you attach: > Without coordination about which startup size the shmem segment should > have, how could you get the current size state correct? And > cross-process coordination of size information before shmem is > attached is not really possible, not when you may have to deal with a > very slow to start backend. SHMEM_ATTACH_UNKNOWN_SIZE can be used there. test_shmem module already uses it that way. --=20 Best Wishes, Ashutosh Bapat