Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5aa29e8

Browse files
committed
Arrange to align shared disk buffers on at least 32-byte boundaries,
not just MAXALIGN boundaries. This makes a noticeable difference in the speed of transfers to and from kernel space, at least on recent Pentiums, and might help other CPUs too. We should look at making this happen for local buffers and buffile.c too. Patch from Manfred Spraul.
1 parent 11b274f commit 5aa29e8

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/backend/storage/ipc/shmem.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.70 2003/08/04 02:40:03 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.71 2003/09/21 17:57:21 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -131,6 +131,7 @@ InitShmemAllocation(void *seghdr)
131131
void *
132132
ShmemAlloc(Size size)
133133
{
134+
uint32 newStart;
134135
uint32 newFree;
135136
void *newSpace;
136137

@@ -146,10 +147,16 @@ ShmemAlloc(Size size)
146147

147148
SpinLockAcquire(ShmemLock);
148149

149-
newFree = shmemseghdr->freeoffset + size;
150+
newStart = shmemseghdr->freeoffset;
151+
152+
/* extra alignment for large requests, since they are probably buffers */
153+
if (size >= BLCKSZ)
154+
newStart = BUFFERALIGN(newStart);
155+
156+
newFree = newStart + size;
150157
if (newFree <= shmemseghdr->totalsize)
151158
{
152-
newSpace = (void *) MAKE_PTR(shmemseghdr->freeoffset);
159+
newSpace = (void *) MAKE_PTR(newStart);
153160
shmemseghdr->freeoffset = newFree;
154161
}
155162
else

src/include/c.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: c.h,v 1.152 2003/08/04 02:40:10 momjian Exp $
15+
* $Id: c.h,v 1.153 2003/09/21 17:57:21 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -522,13 +522,16 @@ typedef NameData *Name;
522522
* ----------------
523523
*/
524524

525-
#define TYPEALIGN(ALIGNVAL,LEN) (((long)(LEN) + (ALIGNVAL-1)) & ~(ALIGNVAL-1))
525+
#define TYPEALIGN(ALIGNVAL,LEN) \
526+
(((long) (LEN) + (ALIGNVAL-1)) & ~((long) (ALIGNVAL-1)))
526527

527528
#define SHORTALIGN(LEN) TYPEALIGN(ALIGNOF_SHORT, (LEN))
528529
#define INTALIGN(LEN) TYPEALIGN(ALIGNOF_INT, (LEN))
529530
#define LONGALIGN(LEN) TYPEALIGN(ALIGNOF_LONG, (LEN))
530531
#define DOUBLEALIGN(LEN) TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
531532
#define MAXALIGN(LEN) TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
533+
/* MAXALIGN covers only built-in types, not buffers */
534+
#define BUFFERALIGN(LEN) TYPEALIGN(ALIGNOF_BUFFER, (LEN))
532535

533536

534537
/* ----------------------------------------------------------------

src/include/pg_config_manual.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* for developers. If you edit any of these, be sure to do a *full*
77
* rebuild (and an initdb if noted).
88
*
9-
* $Id: pg_config_manual.h,v 1.5 2003/08/04 00:43:29 momjian Exp $
9+
* $Id: pg_config_manual.h,v 1.6 2003/09/21 17:57:21 tgl Exp $
1010
*------------------------------------------------------------------------
1111
*/
1212

@@ -126,6 +126,14 @@
126126
*/
127127
#define BITS_PER_BYTE 8
128128

129+
/*
130+
* Preferred alignment for disk I/O buffers. On some CPUs, copies between
131+
* user space and kernel space are significantly faster if the user buffer
132+
* is aligned on a larger-than-MAXALIGN boundary. Ideally this should be
133+
* a platform-dependent value, but for now we just hard-wire it.
134+
*/
135+
#define ALIGNOF_BUFFER 32
136+
129137
/*
130138
* Disable UNIX sockets for those operating system.
131139
*/

0 commit comments

Comments
 (0)