Skip to content

Commit 42113e3

Browse files
ashutosh-bapatCommitfest Bot
authored andcommitted
Update sizes and addresses of shared memory mapping and shared memory structures
Update totalsize and end address in segment and mapping: Once a shared memory segment has been resized, the total size and end address of the same needs to be updated in the corresponding AnonymousMapping and Segment structure. Update allocated_size for resized shared memory structure: Reallocating the shared memory structure after resizing needs a bit more work. But at least update the allocated_size as well along with the size of shared memory structure. Author: Ashutosh Bapat
1 parent b3c3f2f commit 42113e3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/backend/port/sysv_shmem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,8 @@ AnonymousShmemResize(void)
10211021
for(int i = 0; i < ANON_MAPPINGS; i++)
10221022
{
10231023
AnonymousMapping *m = &Mappings[i];
1024+
ShmemSegment *segment = &Segments[i];
1025+
PGShmemHeader *shmem_hdr = segment->ShmemSegHdr;
10241026

10251027
#ifdef MAP_HUGETLB
10261028
if (huge_pages_on && (m->shmem_req_size % hugepagesize != 0))
@@ -1067,6 +1069,8 @@ AnonymousShmemResize(void)
10671069

10681070
reinit = true;
10691071
m->shmem_size = m->shmem_req_size;
1072+
shmem_hdr->totalsize = m->shmem_size;
1073+
segment->ShmemEnd = m->shmem + m->shmem_size;
10701074
}
10711075

10721076
if (reinit)

src/backend/storage/ipc/shmem.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,17 @@ ShmemInitStructInSegment(const char *name, Size size, bool *foundPtr,
504504
*
505505
* XXX: There is an implicit assumption this can only happen in
506506
* "resizable" segments, where only one shared structure is allowed.
507-
* This has to be implemented more cleanly.
507+
* This has to be implemented more cleanly. Probably we should implement
508+
* ShmemReallocRawInSegment functionality just to adjust the size
509+
* according to alignment, return the allocated size and update the
510+
* mapping offset.
508511
*/
509512
if (result->size != size)
510513
{
511514
Size delta = size - result->size;
512515

513516
result->size = size;
517+
result->allocated_size = size;
514518

515519
/* Reflect size change in the shared segment */
516520
SpinLockAcquire(Segments[shmem_segment].ShmemLock);

0 commit comments

Comments
 (0)