Re: Fix condition in shm_toc and remove unused function shm_toc_freespace. - Mailing list pgsql-hackers

From Zhang Mingli
Subject Re: Fix condition in shm_toc and remove unused function shm_toc_freespace.
Date
Msg-id 0c84a55b-9b30-40d1-873a-873ee134c04e@Spark
Whole thread Raw
In response to Re: Fix condition in shm_toc and remove unused function shm_toc_freespace.  (Richard Guo <guofenglinux@gmail.com>)
List pgsql-hackers
Hi,

Regards,
Zhang Mingli
On Jan 12, 2023, 16:54 +0800, Richard Guo <guofenglinux@gmail.com>, wrote:

On Thu, Jan 12, 2023 at 2:50 PM Zhang Mingli <zmlpostgres@gmail.com> wrote:
On Jan 12, 2023, 14:34 +0800, Zhang Mingli <zmlpostgres@gmail.com>, wrote:
Some conditions in shm_toc_insert and shm_toc_allocate are bogus, like:
if (toc_bytes + nbytes > total_bytes || toc_bytes + nbytes < toc_bytes)Remove the condition `toc_bytes + nbytes < toc_bytes` and take a sizeof(shm_entry) into account in shm_toc_allocate though 
shm_toc_allocate does that too.
  shm_toc_insert does that too, and  we can report error earlier.
 
I don't think we should consider sizeof(shm_toc_entry) in the 'if'
condition in shm_toc_allocate, as this function is not in charge of
allocating a new TOC entry.  That's what shm_toc_insert does.
Thanks for review.
Make sense. 
Even reserve a sizeof(shm_toc_entry) when shm_toc_allocate, it cloud happen that there is no space  when shm_toc_insert 
in case of other processes may take space after that.
Patch updated.
Attachment

pgsql-hackers by date:

Previous
From: Xing Guo
Date:
Subject: Re: PL/Python: Fix return in the middle of PG_TRY() block.
Next
From: Ted Yu
Date:
Subject: properly sizing attnums in pg_get_publication_tables