Fix unnecessary shared memory page allocation in CalculateShmemSize() - Mailing list pgsql-hackers

From Chao Li
Subject Fix unnecessary shared memory page allocation in CalculateShmemSize()
Date
Msg-id F132EBB6-47EB-4DF8-8C8D-3DE698265A2B@gmail.com
Whole thread
Responses Re: Fix unnecessary shared memory page allocation in CalculateShmemSize()
List pgsql-hackers
Hi,

I just noticed this item when I went through my TODO list today. I remember finding this issue a few months ago, but at
thattime, only bugs new to PG19 were being processed, so I put it on my TODO list. 

This is a small issue, but it has been there for many years. CalculateShmemSize() has logic to round size to a multiple
ofa typical page size: 
```
    /* might as well round it off to a multiple of a typical page size */
    size = add_size(size, 8192 - (size % 8192));
```

When size is already a multiple of 8192, this add_size() call is not needed; it only results in an extra 8192 bytes
beingallocated in shared memory. The fix is simple: 
```
    if (size % 8192 != 0)
        /* might as well round it off to a multiple of a typical page size */
        size = add_size(size, 8192 - (size % 8192));
```

I put the comment within the if clause because I remember Tom once mentioning that this would be the preferred style.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/





Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Translation of the NextOID message in pg_controldata
Next
From: Osama Abdul Qader
Date:
Subject: Re: Fix unnecessary shared memory page allocation in CalculateShmemSize()