ShmemAlloc() alignment patch - Mailing list pgsql-hackers

From Qingqing Zhou
Subject ShmemAlloc() alignment patch
Date
Msg-id e97esc$1aa6$1@news.hub.org
Whole thread Raw
Responses Re: ShmemAlloc() alignment patch  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-hackers
In ShmemAlloc() we have:
 newStart = BUFFERALIGN(newStart); newSpace = (void *) (ShmemBase + newStart); return newSpace;

Notice that though newStart is ALIGNOF_BUFFER, ShmemBase is not. Thus the
newSpace is not aligned as we disired.

Attached please find the patch.

Regards,
Qingqing

Index: src/backend/storage/ipc/shmem.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v
retrieving revision 1.92
diff -c -r1.92 shmem.c
*** src/backend/storage/ipc/shmem.c     13 Jul 2006 16:49:16 -0000      1.92
--- src/backend/storage/ipc/shmem.c     14 Jul 2006 06:47:43 -0000
***************
*** 169,178 ****       SpinLockAcquire(ShmemLock);
       newStart = shmemseghdr->freeoffset;
       /* extra alignment for large requests, since they are probably
buffers */       if (size >= BLCKSZ)
!               newStart = BUFFERALIGN(newStart);
       newFree = newStart + size;       if (newFree <= shmemseghdr->totalsize)
--- 169,179 ----       SpinLockAcquire(ShmemLock);
       newStart = shmemseghdr->freeoffset;
+       newSpace = (void *) MAKE_PTR(newStart);
       /* extra alignment for large requests, since they are probably
buffers */       if (size >= BLCKSZ)
!               newStart = MAKE_OFFSET(BUFFERALIGN(newSpace));
       newFree = newStart + size;       if (newFree <= shmemseghdr->totalsize)








pgsql-hackers by date:

Previous
From: Lukas Smith
Date:
Subject: Re: monolithic distro
Next
From: Lukas Smith
Date:
Subject: Re: monolithic distro